/// <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)); }
public int LexicalCompare(Ray3d other) { var cmp = Origin.LexicalCompare(other.Origin); if (cmp != 0) { return(cmp); } return(Direction.LexicalCompare(other.Direction)); }
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); }
/// <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); } } }
/// <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) ); } }
/// <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); }
public static bool IsNormalTo(this Plane3d plane, Ray3d ray) => ray.Direction.IsParallelTo(plane.Normal);
public static bool IsOrthogonalTo(this Ray3d ray, Plane3d plane) => ray.Direction.IsParallelTo(plane.Normal);
public static bool IsOrthogonalTo(this Ray3d r0, Ray3d r1) => r0.Direction.IsOrthogonalTo(r1.Direction);
public static bool IsOrthogonalTo(this Ray3d ray, V3d vec) => ray.Direction.IsOrthogonalTo(vec);
public double GetHeight(V3d position) { var ray = new Ray3d(Origin, Direction); return(ray.GetTOfProjectedPoint(position)); }
public static bool IsOrthogonalTo(this Ray3d ray, V3d vec) { return(ray.Direction.IsOrthogonalTo(vec)); }
/// <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);
public static bool IsParallelTo(this Ray3d r0, Ray3d r1) => r0.Direction.IsParallelTo(r1.Direction);
public static bool IsParallelTo(this Ray3d r0, Ray3d r1) { return(r0.Direction.IsParallelTo(r1.Direction)); }
/// <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)); }
public static bool IsParallelTo(this Ray3d ray, V3d vec) { return(ray.Direction.IsParallelTo(vec)); }
public static bool IsOrthogonalTo(this Ray3d r0, Ray3d r1) { return(r0.Direction.IsOrthogonalTo(r1.Direction)); }
public static bool IsParallelTo(this Ray3d ray, V3d vec) => ray.Direction.IsParallelTo(vec);
public FastRay3d(Ray3d ray) { Ray = ray; DirFlags = ray.Direction.DirFlags(); InvDir = 1.0 / ray.Direction; }
public static bool IsParallelTo(this Ray3d ray, V3d vec, double epsilon = 1e-6) => ray.Direction.IsParallelTo(vec, epsilon);
public static bool IsParallelTo(this Plane3d plane, Ray3d ray) { return(ray.Direction.IsOrthogonalTo(plane.Normal)); }
public static bool IsParallelTo(this Ray3d r0, Ray3d r1, double epsilon = 1e-6) => r0.Direction.IsParallelTo(r1.Direction, epsilon);
/// <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);