예제 #1
0
        public clsLine3d Cross(clsLine3d l1)
        {
            double x = 0;
            double y = 0;
            double z = 0;

            x = DY() * l1.DZ() - DZ() * l1.DY();
            y = -(DX() * l1.DZ() - DZ() * l1.DX());
            z = DX() * l1.DY() - DY() * l1.DX();
            return(new clsLine3d(0, 0, 0, x, y, z));
        }
예제 #2
0
        public clsPoint3d ClosestPointToLine(clsLine3d l2)
        {
            clsPoint3d v1;
            clsPoint3d v2;
            clsPoint3d M;
            double     m2;
            clsPoint3d R;
            clsPoint3d P21;
            double     t1;
            clsPoint3d Q1;

            //Find the actual point on this line where the perpendicular distance hits.
            v1 = new clsPoint3d(DX(), DY(), DZ());
            v1.Normalise();
            v2 = new clsPoint3d(l2.DX(), l2.DY(), l2.DZ());
            v2.Normalise();

            M  = v2.Cross(v1);
            m2 = M.Dot(M);
            if (m2 < mdlGeometry.myTol)
            {
                return(l2.P1);
            }
            //Parallel

            P21 = new clsPoint3d(l2.X1 - X1, l2.Y1 - Y1, l2.Z1 - Z1);
            R   = P21.Cross(M);
            R.Scale(1 / m2);
            t1 = R.Dot(v2);
            Q1 = P1 + t1 * v1;

            return(Q1);
        }
예제 #3
0
        public clsPoint3d DistanceAlongLine(double d)
        {
            clsLine3d l1 = default(clsLine3d);

            l1 = Copy();
            l1.Normalise();
            return(new clsPoint3d(X1 + d * l1.DX(), Y1 + d * l1.DY(), Z1 + d * l1.DZ()));
        }
예제 #4
0
        public double DistanceToLine(clsLine3d l2)
        {
            //Perpendicular distance between 3d lines. Limited to the line segments.
            double     myNormalDist;
            clsPoint3d v1;
            clsPoint3d v2;
            clsPoint3d M;
            double     m2;
            clsPoint3d R;
            clsPoint3d P21;
            double     t1;
            double     t2;
            clsPoint3d Q1;
            clsPoint3d Q2;

            //Find the actual point on this line where the perpendicular distance hits. If it is off the line, then find the minimum distance between the end points
            v1 = new clsPoint3d(DX(), DY(), DZ());
            v1.Normalise();
            v2 = new clsPoint3d(l2.DX(), l2.DY(), l2.DZ());
            v2.Normalise();

            P21 = new clsPoint3d(l2.X1 - X1, l2.X1 - X1, l2.X1 - X1);
            M   = v2.Cross(v1);
            m2  = M.Dot(M);
            if (m2 < mdlGeometry.myTol)
            {
                return(DistanceToPoint(l2.P1));
            }
            //Parallel
            myNormalDist = Abs(P21.Dot(M)) / Sqrt(m2);
            //Perpendicular distance

            R = P21.Cross(M);
            R.Scale(1 / m2);
            t1 = R.Dot(v2);
            Q1 = P1 + t1 * v1;
            if (t1 < 0)
            {
                Q1 = P1;
            }
            if (t1 > Length)
            {
                Q1 = P2;
            }

            t2 = R.Dot(v1);
            Q2 = l2.P1 + t2 * v2;
            if (t2 < 0)
            {
                Q2 = l2.P1;
            }
            if (t2 > l2.Length)
            {
                Q2 = l2.P2;
            }

            return(Q1.Dist(Q2));
        }
예제 #5
0
        public void RotateAboutLine(clsLine3d l1, double theta)
        {
            clsPoint3d p1  = default(clsPoint3d);
            clsPoint3d p2  = default(clsPoint3d);
            clsPoint3d p2a = default(clsPoint3d);
            clsPoint3d p2b = default(clsPoint3d);
            clsPoint3d p3  = default(clsPoint3d);
            clsLine3d  l2  = default(clsLine3d);

            if (l1.IsOnLine(this))
            {
                return;
            }

            //Setup a coordinate system with X running along l1 and the origin at l1.p2
            l2        = new clsLine3d(l1.P2.Copy(), Copy());
            p1        = new clsPoint3d(l1.DX(), l1.DY(), l1.DZ());
            p1.Length = 1;
            p2        = new clsPoint3d(l2.DX(), l2.DY(), l2.DZ());
            p2a       = new clsPoint3d(l2.DX(), l2.DY(), l2.DZ());
            p2.Length = 1;
            p3        = p1.Cross(p2);
            p3.Length = 1;
            p2        = p1.Cross(p3);
            p2.Length = 1;
            if (p2.Dot(p2a) < 0)
            {
                p2.Scale(-1);
            }

            p2b = new clsPoint3d(p1.Dot(p2a), p2.Dot(p2a), p3.Dot(p2a));
            p2b.RotateAboutX(theta);

            myX = l1.X2 + p2b.x * p1.x + p2b.y * p2.x + p2b.z * p3.x;
            myY = l1.Y2 + p2b.x * p1.y + p2b.y * p2.y + p2b.z * p3.y;
            myZ = l1.Z2 + p2b.x * p1.z + p2b.y * p2.z + p2b.z * p3.z;
        }