Ejemplo n.º 1
0
        /// <summary>
        /// 构造直线,为两平面的交线
        /// </summary>
        public Line(Face face1, Face face2)
        {
            Vector3Double normalFace1 = face1.PlaneNormal;
            Vector3Double normalFace2 = face2.PlaneNormal;

            Direction = Vector3Double.Cross(normalFace1, normalFace2);

            if (!(Direction.magnitude < EqualityTolerance))  // 两平面不平行
            {
                //getting a line point, zero is set to a coordinate whose direction
                // 获取线上一点,方向坐标设为零点
                //component isn't zero (line intersecting its origin plan)
                // 成员不为零(线与第一个平面相交)
                var d1 = -Vector3Double.Dot(normalFace1, face1.v1.Position);
                var d2 = -Vector3Double.Dot(normalFace2, face2.v1.Position);
                if (Math.Abs(Direction.x) > EqualityTolerance)
                {
                    startPoint = new Vector3Double
                    {
                        x = 0,
                        y = (d2 * normalFace1.z - d1 * normalFace2.z) / Direction.x,
                        z = (d1 * normalFace2.y - d2 * normalFace1.y) / Direction.x
                    };
                }
                else if (Math.Abs(Direction.y) > EqualityTolerance)
                {
                    startPoint = new Vector3Double
                    {
                        x = (d1 * normalFace2.z - d2 * normalFace1.z) / Direction.y,
                        y = 0,
                        z = (d2 * normalFace1.x - d1 * normalFace2.x) / Direction.y
                    };
                }
                else
                {
                    startPoint = new Vector3Double
                    {
                        x = (d2 * normalFace1.y - d1 * normalFace2.y) / Direction.z,
                        y = (d1 * normalFace2.x - d2 * normalFace1.x) / Direction.z,
                        z = 0
                    };
                }
            }
            else
            {
                startPoint = default;
            }
            Direction.Normalize();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 用方向和起点构造射线
 /// </summary>
 /// <param name="direction">射线方向</param>
 /// <param name="point">射线起点坐标</param>
 public Line(Vector3Double direction, Vector3Double point)
 {
     Direction  = direction;
     startPoint = point;
     direction.Normalize();
 }