Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. using System;
  2. namespace DistanceTask
  3. {
  4. public static class DistanceTask
  5. {
  6. // Расстояние от точки (x, y) до отрезка AB с координатами A(ax, ay), B(bx, by)
  7. public static double GetDistanceToSegment(double ax, double ay, double bx, double by, double x, double y)
  8. {
  9. C = (x, y);
  10. double АВ = Math.Sqrt(Math.Pow((bx - ax), 2) + Math.Pow((by - ay), 2));
  11. double ВС = Math.Sqrt(Math.Pow((bx - x), 2) + Math.Pow((by - y), 2));
  12. double АС = Math.Sqrt(Math.Pow((ax - x), 2) + Math.Pow((ay - y), 2));
  13. double Math.Cos A = (Math.Pow(AC, 2) + Math.Pow(AB, 2) - Math.Pow(BC, 2)) / (2 * AC * DC);
  14. double Math.Cos B = (Math.Pow(AB, 2) + Math.Pow(BC, 2) - Math.Pow(AC, 2)) / (2 * AB * BC);
  15. if (Math.Cos <= 0) return BC;
  16. if (Math.Cos > 0)
  17. {
  18. double Area = 1 / 2(AB * BC * Math.Sin.B);
  19. double AH = ((2 * Area) / AB);
  20. return AH;
  21. }
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement