Exemplo n.º 1
0
        /// <summary>
        /// Returns the ordered tuple. Point in Item1 is closer to the plane
        /// </summary>
        /// <param name="src">Plane</param>
        /// <param name="pt1">Tested point1</param>
        /// <param name="pt2">Tested point2</param>
        /// <returns>The ordered tuple</returns>
        public static Tuple <IPoint3D, IPoint3D> OrderPointsByDistance(this Plane3D src, IPoint3D pt1, IPoint3D pt2)
        {
            double distPt1 = Math.Abs(src.GetPointDistance(pt1));
            double distPt2 = Math.Abs(src.GetPointDistance(pt2));

            if (distPt1 > distPt2)
            {
                return(new Tuple <IPoint3D, IPoint3D>(pt2, pt1));
            }

            return(new Tuple <IPoint3D, IPoint3D>(pt1, pt2));
        }
Exemplo n.º 2
0
        /// <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));
        }