/// <summary> /// Gets distance of the <paramref name="point"/> from <paramref name="line"/> /// </summary> /// <param name="line">Line</param> /// <param name="point">Point</param> /// <returns>Distance</returns> public static double Distance(ref StraightLine line, ref WM.Point3D point) { Plane3D tempPln = new Plane3D(point, line.Direction); var temPlnIntersection = tempPln.GetIntersection(ref line); return((temPlnIntersection - point).Length); }
/// <summary> /// Calculates intersection of the plane and line which is defined by direction vector <paramref name="l"/> and point <paramref name="l0"/> /// </summary> /// <param name="src">Plane</param> /// <param name="ray">Straight line</param> /// <returns>Found intersection. If intersection doesn't NaN is set</returns> public static WM.Point3D GetIntersection(this Plane3D src, ref StraightLine ray) { double d = WM.Vector3D.DotProduct(src.NormalVector, ray.Direction); if (d.IsZero()) { return(new WM.Point3D(double.NaN, double.NaN, double.NaN)); } double dd = WM.Vector3D.DotProduct((src.PointOnPlane - ray.Point), src.NormalVector) / d; return(ray.Point + dd * ray.Direction); }
public static WM.Point3D GetIntersection(ref StraightLine planeNormal, ref StraightLine ray) { double d = WM.Vector3D.DotProduct(planeNormal.Direction, ray.Direction); if (d.IsZero()) { return(new WM.Point3D(double.NaN, double.NaN, double.NaN)); } double dd = WM.Vector3D.DotProduct((planeNormal.Point - ray.Point), planeNormal.Direction) / d; return(ray.Point + dd * ray.Direction); }
/// <summary> /// Returns the distance of <paramref name="line1"/> and <paramref name="line2"/> /// </summary> /// <param name="line1">The first line</param> /// <param name="line2">The second line</param> /// <returns>Distance</returns> public static double Distance(ref StraightLine line1, ref StraightLine line2) { var dot = Math.Abs(WM.Vector3D.DotProduct(line1.Direction, line2.Direction)); if (dot.IsEqual(1, 1e-8)) { // lines are parallel var pln = new Plane3D(line1.Point, line1.Direction); var line2Intersection = pln.GetIntersection(ref line2); return((line1.Point - line2Intersection).Length); } var cross = WM.Vector3D.CrossProduct(line1.Direction, line2.Direction); var pln2 = new Plane3D(line1.Point, cross); var dist = pln2.GetPointDistance(ref line2.Point); return(Math.Abs(dist)); }