Пример #1
0
 /// <summary>
 /// Returns true if the ray hits the other ray before the parameter
 /// value contained in the supplied hit. Detailed information about
 /// the hit is returned in the supplied hit.
 /// </summary>
 public bool Hits(
     Ray3d ray,
     double tmin, double tmax,
     ref RayHit3d hit
     )
 {
     return(HitsRay(ray, tmin, tmax, ref hit));
 }
Пример #2
0
        public int LexicalCompare(Ray3d other)
        {
            var cmp = Origin.LexicalCompare(other.Origin);

            if (cmp != 0)
            {
                return(cmp);
            }
            return(Direction.LexicalCompare(other.Direction));
        }
Пример #3
0
        public V3d GetClosestPoint(V3d point)
        {
            var ray    = new Ray3d(Origin, Direction);
            var cp     = point.GetClosestPointOn(ray);
            var radius = GetRadius(GetHeight(point));
            var dir    = (point - cp).Normalized * radius;

            var p0 = cp + dir;
            var p1 = point.GetClosestPointOn(new Ray3d(Origin, (p0 - Origin).Normalized));

            return((V3d.Distance(point, p1) < V3d.Distance(point, p0)) ? p1 : p0);
        }
Пример #4
0
        /// <summary>
        /// Returns true if the ray hits the other ray before the parameter
        /// value contained in the supplied hit. Detailed information about
        /// the hit is returned in the supplied hit.
        /// </summary>
        public bool HitsRay(
            Ray3d ray,
            double tmin, double tmax,
            ref RayHit3d hit
            )
        {
            V3d d = Origin - ray.Origin;
            V3d u = Direction;
            V3d v = ray.Direction;
            V3d n = u.Cross(v);

            if (Fun.IsTiny(d.Length))
            {
                return(true);
            }
            else if (Fun.IsTiny(u.Cross(v).Length))
            {
                return(false);
            }
            else
            {
                //-t0*u + t1*v + t2*n == d
                //M = {-u,v,n}
                //M*{t0,t1,t2}T == d
                //{t0,t1,t2}T == M^-1 * d

                M33d M = new M33d();
                M.C0 = -u;
                M.C1 = v;
                M.C2 = n;

                if (M.Invertible)
                {
                    V3d t = M.Inverse * d;
                    if (Fun.IsTiny(t.Z))
                    {
                        ProcessHits(t.X, double.MaxValue, tmin, tmax, ref hit);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #5
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)
                                    );
            }
        }
Пример #6
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++)
            {
                double t = 0.0;
                var    r = new Ray3d(pointArray[i], direction);
                if (r.Intersects(plane, out 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);
        }
Пример #7
0
 public static bool IsNormalTo(this Plane3d plane, Ray3d ray)
 => ray.Direction.IsParallelTo(plane.Normal);
Пример #8
0
 public static bool IsOrthogonalTo(this Ray3d ray, Plane3d plane)
 => ray.Direction.IsParallelTo(plane.Normal);
Пример #9
0
 public static bool IsOrthogonalTo(this Ray3d r0, Ray3d r1) => r0.Direction.IsOrthogonalTo(r1.Direction);
Пример #10
0
 public static bool IsOrthogonalTo(this Ray3d ray, V3d vec) => ray.Direction.IsOrthogonalTo(vec);
Пример #11
0
        public double GetHeight(V3d position)
        {
            var ray = new Ray3d(Origin, Direction);

            return(ray.GetTOfProjectedPoint(position));
        }
Пример #12
0
 public static bool IsOrthogonalTo(this Ray3d ray, V3d vec)
 {
     return(ray.Direction.IsOrthogonalTo(vec));
 }
Пример #13
0
 /// <summary>
 /// Returns true if the ray hits the other ray before the parameter
 /// value contained in the supplied hit. Detailed information about
 /// the hit is returned in the supplied hit.
 /// </summary>
 public bool Hits(Ray3d ray, double tmin, double tmax, ref RayHit3d hit)
 => HitsRay(ray, tmin, tmax, ref hit);
Пример #14
0
 public static bool IsParallelTo(this Ray3d r0, Ray3d r1)
 => r0.Direction.IsParallelTo(r1.Direction);
Пример #15
0
 public static bool IsParallelTo(this Ray3d r0, Ray3d r1)
 {
     return(r0.Direction.IsParallelTo(r1.Direction));
 }
Пример #16
0
 /// <summary>
 /// Returns true if the ray hits the other ray before the parameter
 /// value contained in the supplied hit. Detailed information about
 /// the hit is returned in the supplied hit.
 /// </summary>
 public bool Hits(
     Ray3d ray, ref RayHit3d hit
     )
 {
     return(HitsRay(ray, double.MinValue, double.MaxValue, ref hit));
 }
Пример #17
0
 public static bool IsParallelTo(this Ray3d ray, V3d vec)
 {
     return(ray.Direction.IsParallelTo(vec));
 }
Пример #18
0
 public static bool IsOrthogonalTo(this Ray3d r0, Ray3d r1)
 {
     return(r0.Direction.IsOrthogonalTo(r1.Direction));
 }
Пример #19
0
 public static bool IsParallelTo(this Ray3d ray, V3d vec)
 => ray.Direction.IsParallelTo(vec);
Пример #20
0
 public FastRay3d(Ray3d ray)
 {
     Ray      = ray;
     DirFlags = ray.Direction.DirFlags();
     InvDir   = 1.0 / ray.Direction;
 }
Пример #21
0
 public static bool IsParallelTo(this Ray3d ray, V3d vec, double epsilon = 1e-6)
 => ray.Direction.IsParallelTo(vec, epsilon);
Пример #22
0
 public static bool IsParallelTo(this Plane3d plane, Ray3d ray)
 {
     return(ray.Direction.IsOrthogonalTo(plane.Normal));
 }
Пример #23
0
 public static bool IsParallelTo(this Ray3d r0, Ray3d r1, double epsilon = 1e-6)
 => r0.Direction.IsParallelTo(r1.Direction, epsilon);
Пример #24
0
 /// <summary>
 /// Returns true if the ray hits the other ray before the parameter
 /// value contained in the supplied hit. Detailed information about
 /// the hit is returned in the supplied hit.
 /// </summary>
 public bool Hits(Ray3d ray, ref RayHit3d hit)
 => HitsRay(ray, double.MinValue, double.MaxValue, ref hit);