Example #1
0
        /// <summary>
        /// Projects the point onto the line.
        /// </summary>
        public Point ProjectOntoLine(ILinear projectOnto)
        {
            var vector           = this - projectOnto.BasePoint;
            var scalarProjection = vector.ScalarProjection(projectOnto.Direction);

            return(projectOnto.GetPointAlongLine(scalarProjection));
        }
Example #2
0
        /// <summary>
        /// Returns true if the passed line is in the same plane as this one, AKA if it intersects or is parallel to the other line
        /// </summary>
        /// <param name="passedLine"></param>
        /// <returns></returns>
        public static bool IsCoplanarWith(this ILinear thisLine, ILinear otherLine)
        {
            if (thisLine.BasePoint.Z == otherLine.BasePoint.Z &&
                thisLine.Direction.Z < 0.01 &&
                otherLine.Direction.Z < 0.01)
            {
                return(true);
            }

            var point1Line1 = new[] { thisLine.BasePoint.X.InInches(), thisLine.BasePoint.Y.InInches(), thisLine.BasePoint.Z.InInches() };

            var anotherPointOnLine1 = thisLine.GetPointAlongLine(1 * Unit.Inches);
            var point2Line1         = new [] { anotherPointOnLine1.X.InInches(), anotherPointOnLine1.Y.InInches(), anotherPointOnLine1.Z.InInches() };

            var point1Line2 = new [] { otherLine.BasePoint.X.InInches(), otherLine.BasePoint.Y.InInches(), otherLine.BasePoint.Z.InInches() };

            var anotherPointOnLine2 = otherLine.GetPointAlongLine(2 * Unit.Inches);
            var point2Line2         = new [] { anotherPointOnLine2.X.InInches(), anotherPointOnLine2.Y.InInches(), anotherPointOnLine2.Z.InInches() };

            var pointsMatrix = new double[4, 4];

            pointsMatrix.SetRow(0, point1Line1);
            pointsMatrix.SetRow(1, point2Line1);
            pointsMatrix.SetRow(2, point1Line2);
            pointsMatrix.SetRow(3, point2Line2);

            pointsMatrix.SetColumn(3, new double[] { 1, 1, 1, 1 });

            var determinant = Math.Abs(pointsMatrix.Determinant());

            // Tolerance is suspect given that the determinant has dimensions of (in.^4)
            return(determinant * Unit.Inches == Unit.ZeroDistance);
        }