/// <summary> /// 点と直線の距離 /// </summary> /// <param name="l">直線</param> /// <param name="p">点</param> /// <returns></returns> public static double distance_lp(Line3D l, Point3D p) { return(dist(p - project_lp(l, p))); }
/// <summary> /// 点が線分上にあるか /// </summary> /// <param name="l">線分</param> /// <param name="p">点</param> /// <returns></returns> public static bool is_in_segment(Line3D l, Point3D p) { return(Math.Abs(dist(l.a - p) + dist(l.b - p) - dist(l.a - l.b)) < Eps); }
/// <summary> /// 点の射影(点から直線に引いた垂線と線分の交点) /// </summary> /// <param name="l">直線</param> /// <param name="p">点</param> /// <returns></returns> public static Point3D project_lp(Line3D l, Point3D p) { Point3D point = l.a, vec = l.b - l.a; return(point + dot(p - point, vec) / norm(vec) * vec); }