示例#1
0
        /// <summary>
        /// Projects a point onto the plane along given direction.
        /// </summary>
        public static V3d Project(this Plane3d plane, V3d p, V3d direction)
        {
            var r = new Ray3d(p, direction);

            if (r.Intersects(plane, out double t))
            {
                return(r.GetPointOnRay(t));
            }
            else
            {
                throw new Exception(string.Format(
                                        "Failed to project point {0} onto plane {1} along direction {2}.", p, plane, direction)
                                    );
            }
        }
示例#2
0
        /// <summary>
        /// Projects points onto plane along given direction.
        /// </summary>
        public static V3d[] Project(this Plane3d plane, V3d[] pointArray, V3d direction, int startIndex = 0, int count = 0)
        {
            if (pointArray == null)
            {
                throw new ArgumentNullException();
            }
            if (startIndex < 0 || startIndex >= pointArray.Length)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (count < 0 || startIndex + count >= pointArray.Length)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (count == 0)
            {
                count = pointArray.Length - startIndex;
            }

            var result = new V3d[count];

            for (int i = startIndex, j = 0; j < count; i++, j++)
            {
                var r = new Ray3d(pointArray[i], direction);
                if (r.Intersects(plane, out double t))
                {
                    result[j] = r.GetPointOnRay(t);
                }
                else
                {
                    throw new Exception(string.Format(
                                            "Failed to project point {0} onto plane {1} along direction {2}.", pointArray[i], plane, direction)
                                        );
                }
            }
            ;
            return(result);
        }