Exemplo n.º 1
0
 public bool IsAlmostEqualTo(Line3D other)
 {
     return(IsAlmostEqualTo(other, Extension.SMALL_NUMBER));
 }
Exemplo n.º 2
0
 public bool IsAlmostEqualTo(Line3D other, double toterance)
 {
     return((Start.IsAlmostEqualTo(other.Start, toterance) && End.IsAlmostEqualTo(other.End, toterance)) || (Start.IsAlmostEqualTo(other.End, toterance) && End.IsAlmostEqualTo(other.Start, toterance)));
 }
Exemplo n.º 3
0
 /// <summary>
 /// 创建一个反方向的线
 /// </summary>
 /// <returns></returns>
 public Line3D Reversed()
 {
     return(Line3D.Create(this.end, this.start));
 }
Exemplo n.º 4
0
        /// <summary>
        /// 直线和线段相交
        /// </summary>
        /// <param name="limitedCurve">线段</param>
        /// <returns></returns>
        public Vector3D IntersectStraightLine2(Line3D limitedCurve)
        {
            double x0 = Origin.X, y0 = Origin.Y, z0 = Origin.Z,
                   x1 = limitedCurve.Start.X, y1 = limitedCurve.Start.Y, z1 = limitedCurve.Start.Z,
                   l0 = Direction.X, m0 = Direction.Y, n0 = Direction.Z,
                   l1 = limitedCurve.Direction.X, m1 = limitedCurve.Direction.Y, n1 = limitedCurve.Direction.Z,
                   deltaLM = l0 * m1 - m0 * l1, deltaMN = m0 * n1 - n0 * m1, deltaLN = l0 * n1 - n0 * l1,
                   t0, t1;

            if (deltaLM.AreEqual(0) && deltaLN.AreEqual(0) && deltaMN.AreEqual(0))
            {
                return(null);
            }
            if (!deltaLM.AreEqual(0))
            {
                t0 = (m1 * x1 - l1 * y1 - m1 * x0 + l1 * y0) / deltaLM;
                if (!l1.AreEqual(0))
                {
                    t1 = (x0 + l0 * t0 - x1) / l1;
                }
                else
                {
                    t1 = (y0 + m0 * t0 - y1) / m1;
                }
                double   zTry1 = z0 + n0 * t0, zTry2 = z1 + n1 * t1;
                Vector3D intersection = new Vector3D(x0 + l0 * t0, y0 + m0 * t0, z0 + n0 * t0);
                if (zTry1.AreEqual(zTry2) && intersection.IsOnLine(limitedCurve))
                {
                    return(intersection);
                }
                else
                {
                    return(null);
                }
            }
            else if (!deltaLN.AreEqual(0))
            {
                t0 = (n1 * x1 - l1 * z1 - n1 * x0 + l1 * z0) / deltaLN;
                if (!l1.AreEqual(0))
                {
                    t1 = (x0 + l0 * t0 - x1) / l1;
                }
                else
                {
                    t1 = (z0 + n0 * t0 - z1) / n1;
                }
                double   yTry1 = y0 + m0 * t0, yTry2 = y1 + m1 * t1;
                Vector3D intersection = new Vector3D(x0 + l0 * t0, y0 + m0 * t0, z0 + n0 * t0);
                if (yTry1.AreEqual(yTry2) && intersection.IsOnLine(limitedCurve))
                {
                    return(intersection);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                t0 = (n1 * y1 - m1 * z1 - n1 * y0 + m1 * z0) / deltaMN;
                if (!m1.AreEqual(0))
                {
                    t1 = (y0 + m0 * t0 - y1) / m1;
                }
                else
                {
                    t1 = (z0 + n0 * t0 - z1) / n1;
                }
                double   xTry1 = x0 + l0 * t0, xTry2 = x1 + l1 * t1;
                Vector3D intersection = new Vector3D(x0 + l0 * t0, y0 + m0 * t0, z0 + n0 * t0);
                if (xTry1.AreEqual(xTry2) && intersection.IsOnLine(limitedCurve))
                {
                    return(intersection);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 线段和线段相交
        /// </summary>
        /// <param name="curve"></param>
        /// <returns></returns>
        public Vector3D Intersect(Line3D curve)
        {
            double x0 = Start.X, y0 = Start.Y, z0 = Start.Z,
                   x1 = curve.Start.X, y1 = curve.Start.Y, z1 = curve.Start.Z,
                   l0 = Direction.X, m0 = Direction.Y, n0 = Direction.Z,
                   l1 = curve.Direction.X, m1 = curve.Direction.Y, n1 = curve.Direction.Z,
                   deltaLM = l0 * m1 - m0 * l1, deltaMN = m0 * n1 - n0 * m1, deltaLN = l0 * n1 - n0 * l1,
                   t0, t1;

            if (deltaLM.AreEqual(0) && deltaLN.AreEqual(0) && deltaMN.AreEqual(0))
            {
                if (Start.IsOnTwoLine(this, curve) && !this.CoincidesWith(curve))
                {
                    return(Start);
                }
                if (End.IsOnTwoLine(this, curve) && !this.CoincidesWith(curve))
                {
                    return(End);
                }
                else
                {
                    return(null);
                }
            }
            if (!deltaLM.AreEqual(0))
            {
                t0 = (m1 * x1 - l1 * y1 - m1 * x0 + l1 * y0) / deltaLM;
                if (!l1.AreEqual(0))
                {
                    t1 = (x0 + l0 * t0 - x1) / l1;
                }
                else
                {
                    t1 = (y0 + m0 * t0 - y1) / m1;
                }
                double   zTry1 = z0 + n0 * t0, zTry2 = z1 + n1 * t1;
                Vector3D intersection = new Vector3D(x0 + l0 * t0, y0 + m0 * t0, z0 + n0 * t0);
                if (zTry1.AreEqual(zTry2) && intersection.IsOnTwoLine(this, curve))
                {
                    return(intersection);
                }
                else
                {
                    return(null);
                }
            }
            else if (!deltaLN.AreEqual(0))
            {
                t0 = (n1 * x1 - l1 * z1 - n1 * x0 + l1 * z0) / deltaLN;
                if (!l1.AreEqual(0))
                {
                    t1 = (x0 + l0 * t0 - x1) / l1;
                }
                else
                {
                    t1 = (z0 + n0 * t0 - z1) / n1;
                }
                double   yTry1 = y0 + m0 * t0, yTry2 = y1 + m1 * t1;
                Vector3D intersection = new Vector3D(x0 + l0 * t0, y0 + m0 * t0, z0 + n0 * t0);
                if (yTry1.AreEqual(yTry2) && intersection.IsOnTwoLine(this, curve))
                {
                    return(intersection);
                }
                else
                {
                    return(null);
                }
            }

            else
            {
                t0 = (n1 * y1 - m1 * z1 - n1 * y0 + m1 * z0) / deltaMN;
                if (!m1.AreEqual(0))
                {
                    t1 = (y0 + m0 * t0 - y1) / m1;
                }
                else
                {
                    t1 = (z0 + n0 * t0 - z1) / n1;
                }
                double   xTry1 = x0 + l0 * t0, xTry2 = x1 + l1 * t1;
                Vector3D intersection = new Vector3D(x0 + l0 * t0, y0 + m0 * t0, z0 + n0 * t0);
                if (xTry1.AreEqual(xTry2) && intersection.IsOnTwoLine(this, curve))
                {
                    return(intersection);
                }
                else
                {
                    return(null);
                }
            }
        }