Esempio n. 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));
 }
Esempio n. 2
0
        public int LexicalCompare(Ray3d other)
        {
            var cmp = Origin.LexicalCompare(other.Origin);

            if (cmp != 0)
            {
                return(cmp);
            }
            return(Direction.LexicalCompare(other.Direction));
        }
Esempio n. 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);
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 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)
                                    );
            }
        }
Esempio n. 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);
        }
Esempio n. 7
0
 public static bool IsNormalTo(this Plane3d plane, Ray3d ray)
 => ray.Direction.IsParallelTo(plane.Normal);
Esempio n. 8
0
 public static bool IsOrthogonalTo(this Ray3d ray, Plane3d plane)
 => ray.Direction.IsParallelTo(plane.Normal);
Esempio n. 9
0
 public static bool IsOrthogonalTo(this Ray3d r0, Ray3d r1) => r0.Direction.IsOrthogonalTo(r1.Direction);
Esempio n. 10
0
 public static bool IsOrthogonalTo(this Ray3d ray, V3d vec) => ray.Direction.IsOrthogonalTo(vec);
Esempio n. 11
0
        public double GetHeight(V3d position)
        {
            var ray = new Ray3d(Origin, Direction);

            return(ray.GetTOfProjectedPoint(position));
        }
Esempio n. 12
0
 public static bool IsOrthogonalTo(this Ray3d ray, V3d vec)
 {
     return(ray.Direction.IsOrthogonalTo(vec));
 }
Esempio n. 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);
Esempio n. 14
0
 public static bool IsParallelTo(this Ray3d r0, Ray3d r1)
 => r0.Direction.IsParallelTo(r1.Direction);
Esempio n. 15
0
 public static bool IsParallelTo(this Ray3d r0, Ray3d r1)
 {
     return(r0.Direction.IsParallelTo(r1.Direction));
 }
Esempio n. 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));
 }
Esempio n. 17
0
 public static bool IsParallelTo(this Ray3d ray, V3d vec)
 {
     return(ray.Direction.IsParallelTo(vec));
 }
Esempio n. 18
0
 public static bool IsOrthogonalTo(this Ray3d r0, Ray3d r1)
 {
     return(r0.Direction.IsOrthogonalTo(r1.Direction));
 }
Esempio n. 19
0
 public static bool IsParallelTo(this Ray3d ray, V3d vec)
 => ray.Direction.IsParallelTo(vec);
Esempio n. 20
0
 public FastRay3d(Ray3d ray)
 {
     Ray      = ray;
     DirFlags = ray.Direction.DirFlags();
     InvDir   = 1.0 / ray.Direction;
 }
Esempio n. 21
0
 public static bool IsParallelTo(this Ray3d ray, V3d vec, double epsilon = 1e-6)
 => ray.Direction.IsParallelTo(vec, epsilon);
Esempio n. 22
0
 public static bool IsParallelTo(this Plane3d plane, Ray3d ray)
 {
     return(ray.Direction.IsOrthogonalTo(plane.Normal));
 }
Esempio n. 23
0
 public static bool IsParallelTo(this Ray3d r0, Ray3d r1, double epsilon = 1e-6)
 => r0.Direction.IsParallelTo(r1.Direction, epsilon);
Esempio n. 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);