Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace DistanceTask
- {
- public static class DistanceTask
- {
- // Расстояние от точки (x, y) до отрезка AB с координатами A(ax, ay), B(bx, by)
- public static double GetDistanceToSegment(double ax, double ay, double bx, double by, double x, double y)
- {
- C = (x, y);
- double АВ = Math.Sqrt(Math.Pow((bx - ax), 2) + Math.Pow((by - ay), 2));
- double ВС = Math.Sqrt(Math.Pow((bx - x), 2) + Math.Pow((by - y), 2));
- double АС = Math.Sqrt(Math.Pow((ax - x), 2) + Math.Pow((ay - y), 2));
- double Math.Cos A = (Math.Pow(AC, 2) + Math.Pow(AB, 2) - Math.Pow(BC, 2)) / (2 * AC * DC);
- double Math.Cos B = (Math.Pow(AB, 2) + Math.Pow(BC, 2) - Math.Pow(AC, 2)) / (2 * AB * BC);
- if (Math.Cos <= 0) return BC;
- if (Math.Cos > 0)
- {
- double Area = 1 / 2(AB * BC * Math.Sin.B);
- double AH = ((2 * Area) / AB);
- return AH;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement