public void AssertThat_RayRayIntersection_FindsParallelLines() { var i = new Ray2(new Vector2(0, 10), new Vector2(0, 1)).Intersects(new Ray2(new Vector2(20, 5), new Vector2(0, 1)), out var para); Assert.AreEqual(Parallelism.Parallel, para); Assert.IsFalse(i.HasValue); }
public void GetHashCode_SameForEqual() { var a = new Ray2(new Vector2(1, 2), Vector2.UnitY); var b = new Ray2(new Vector2(1, 2), Vector2.UnitY); Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); }
public override IEnumerable <Vector3> Intersections(Ray <Vector3> ray) { var flatRay = new Ray2(ray.Origin.ToVector2(), ray.Direction.ToVector2()); foreach (var flatIntersect in Shape.Intersections(flatRay)) { var distance = (flatIntersect - flatRay.Origin).Magnitude(); var verticalComponent = ray.Direction.Y * distance; if (verticalComponent <= Height && verticalComponent >= -Height) { yield return(new Vector3(flatIntersect.X, (float)verticalComponent, flatIntersect.Y)); } } if (ray.Direction.Y != 0) { var component = (Height - ray.Origin.Y) / ray.Direction.Y; var point = flatRay.Direction.Scale(component) + flatRay.Origin; if (Shape.Contains(point)) { yield return(new Vector3(point.X, (float)Height, point.Y)); } component = (-Height - ray.Origin.Y) / ray.Direction.Y; point = flatRay.Direction.Scale(component) + flatRay.Origin; if (Shape.Contains(point)) { yield return(new Vector3(point.X, (float)Height, point.Y)); } } }
static Ray2[,] BuildJetArray(XSecPathList pathList, XSecJet jet, double meshSize, double nominalFeedrate) { int jetW = (int)(Math.Ceiling(jet.Diameter / meshSize)); double jetR = jet.Diameter / 2; Ray2[,] jetArr = new Ray2[pathList.Count, jetW]; for (int pathIndex = 0; pathIndex < pathList.Count; pathIndex++) { double endX = pathList[pathIndex].CrossLoc + jetR; for (int jetLocIndex = 0; jetLocIndex < jetW; jetLocIndex++) { double x = (pathList[pathIndex].CrossLoc - jetR) + (meshSize * jetLocIndex); var origin = new Vector2(x, 0); double angleDeg = 90; double angRad = Math.PI * (angleDeg / 180.0); var direction = new Vector2(Math.Cos(angRad), Math.Sin(angRad)); double jetX = x - pathList[pathIndex].CrossLoc; double jetMrr = jet.GetMrr(jetX); double feedEffect = FeedrateEffect(pathList[pathIndex].Feedrate, nominalFeedrate); double mrr = jetMrr * feedEffect; var jetRay = new Ray2(origin, direction, mrr); jetArr[pathIndex, jetLocIndex] = jetRay; } } return(jetArr); }
public void NotEquals_TrueForNotEqual() { var a = new Ray2(new Vector2(1, 2), Vector2.UnitX); var b = new Ray2(new Vector2(1, 2), Vector2.UnitY); Assert.IsTrue(a != b); }
public void NotEquals_FalseForEqual() { var a = new Ray2(new Vector2(1, 2), Vector2.UnitX); var b = a; Assert.IsFalse(a != b); }
public void constructor_point_vector() { var ray = new Ray2(new Point2(1, 2), new Vector2(3, 4)); Assert.Equal(new Point2(1, 2), ray.P); Assert.Equal(new Vector2(3, 4), ray.Direction); }
public void constructor_copy() { var i = new Ray2(new Point2(1, 2), new Point2(4, 5)); var j = new Ray2(i); Assert.Equal(new Point2(1, 2), j.P); Assert.Equal(new Vector2(3, 3), j.Direction); }
public void intersection_rays_at_ends() { var a = new Ray2(new Point2(0, 0), new Point2(1, 1)); var b = new Ray2(new Point2(0.5, 1.5), new Point2(1, 1)); IntersectionTest(a, b, new Point2(1, 1)); }
public void intersection_rways_at_butts() { var a = new Ray2(new Point2(0, 0), new Point2(1, 1)); var b = new Ray2(new Point2(0, 0), new Point2(1, -1)); IntersectionTest(a, b, Point2.Zero); }
public void intersections_two_rays_crossing() { var a = new Ray2(Point2.Zero, new Point2(4, 4)); var b = new Ray2(new Point2(0, 4), new Point2(4, 0)); IntersectionTest(a, b, new Point2(2, 2)); }
private void OnDrawGizmos() { Line2 line = CreateLine2(Line); Ray2 ray = CreateRay2(Ray); IntersectionTypes intersectionType; bool test = Intersection.TestLine2Ray2(ref line, ref ray, out intersectionType); Line2Ray2Intr info; bool find = Intersection.FindLine2Ray2(ref line, ref ray, out info); FiguresColor(); DrawLine(ref line); DrawRay(ref ray); if (find) { ResultsColor(); DrawPoint(info.Point); } LogInfo(intersectionType); if (test != find) { LogError("test != find"); } if (intersectionType != info.IntersectionType) { LogError("intersectionType != info.IntersectionType"); } }
public void distance_squared_test() { var ray = new Ray2(new Point2(1, 1), new Vector2(2, 1)); Assert.Equal(1 + (.5 * .5), ray.DistanceSquared(new Point2(1.5, 2.5))); Assert.Equal(4, ray.DistanceSquared(new Point2(-1, 1))); }
public void direction() { var a = new Ray2(new Point2(2, 1), new Point2(-1, 3)); var b = new Ray2(new Point2(5, -1), new Point2(10, 1)); Assert.Equal(new Vector2(-3, 2), a.Direction); Assert.Equal(new Vector2(5, 2), b.Direction); }
private void OnDrawGizmos() { Ray2 ray = CreateRay2(Ray); Polygon2 polygon = CreatePolygon2(Polygon); Ray2Polygon2Intr info; bool find = Intersection.FindRay2Polygon2(ref ray, polygon, out info); FiguresColor(); DrawRay(ref ray); DrawPolygon(polygon); if (find) { ResultsColor(); if (info.IntersectionType == IntersectionTypes.Point) { DrawPoint(info.Point0); } else if (info.IntersectionType == IntersectionTypes.Segment) { DrawSegment(info.Point0, info.Point1); DrawPoint(info.Point0); DrawPoint(info.Point1); } } LogInfo(info.IntersectionType); }
public void constructor_point_direction() { var ray = new Ray2(new Point2(0, 0), new Vector2(2, 3)); Assert.Equal(new Point2(0, 0), ray.P); Assert.Equal(new Vector2(2, 3), ray.Direction); }
public GridIntersect GetXYIntersectOf(Ray2 ray) { var origin = GetIndices(ray.Origin.X, ray.Origin.Y); double dx = _meshSize / ray.DirectionTan; double dy = _meshSize; byte cellValue = GetValueAt(origin); double x = ray.Origin.X; double y = ray.Origin.Y; var loc = new Point(origin.X, origin.Y); if (cellValue <= _critFillValue) { while (x < xWidth && y < yHeight) { x += dx; y += dy; loc = GetIndices(x, y); cellValue = GetValueAt(loc); if (cellValue > _critFillValue) { break; } } } var normal = GetNormal(loc); return(new GridIntersect { X = loc.X, Y = loc.Y, IntersectRay = ray, Normal = normal }); }
private void OnDrawGizmos() { Ray2 ray = CreateRay2(Ray); Box2 box = CreateBox2(Box); bool test = Intersection.TestRay2Box2(ref ray, ref box); Ray2Box2Intr info; bool find = Intersection.FindRay2Box2(ref ray, ref box, out info); FiguresColor(); DrawRay(ref ray); DrawBox(ref box); if (find) { ResultsColor(); if (info.IntersectionType == IntersectionTypes.Point) { DrawPoint(info.Point0); } else if (info.IntersectionType == IntersectionTypes.Segment) { DrawSegment(info.Point0, info.Point1); DrawPoint(info.Point0); DrawPoint(info.Point1); } } LogInfo(info.IntersectionType); if (test != find) { LogError("test != find"); } }
public override void Update(Vec2 mouse, bool leftClick, bool rightClick, float dt) { if (leftClick) { Polygon aabb = new Polygon(.5f, .5f); System.Random r = new System.Random(); Body b = new Body(aabb, mouse, (float)r.NextDouble(), 0.15f); b.SetStatic(); physicsWorld.AddBody(b); } if (rightClick) { Circle aabb = new Circle(0.5f); Body b = new Body(aabb, mouse, 1); b.SetStatic(); physicsWorld.AddBody(b); } ray = new Ray2(Vec2.Zero, Vec2.Rotate(Vec2.UnitY, direction)); isIntersect = physicsWorld.Raycast(ray, distance, out result); direction = (direction + dt * 0.1f) % (2 * Mathf.Pi); physicsWorld.Update(dt); }
private void OnDrawGizmos() { Ray2 ray0 = CreateRay2(Ray0); Ray2 ray1 = CreateRay2(Ray1); IntersectionTypes intersectionType; bool test = Intersection.TestRay2Ray2(ref ray0, ref ray1, out intersectionType); Ray2Ray2Intr info; bool find = Intersection.FindRay2Ray2(ref ray0, ref ray1, out info); FiguresColor(); DrawRay(ref ray0); DrawRay(ref ray1); if (find) { ResultsColor(); DrawPoint(info.Point); } LogInfo(intersectionType); if (test != find) { LogError("test != find"); } if (intersectionType != info.IntersectionType) { LogError("intersectionType != info.IntersectionType"); } }
public bool IsBehind(WoWUnit o) { var left = o.Location.FlattenZf() + Vector2.UnitY.RotateAround(Vector2.Origo, (float)(o.Facing)); var ray = new Ray2(o.Location.FlattenZf(), left); return(ray.IsOnLeftSide(Location.FlattenZf())); }
public void intersection_same_but_reversed() { var a = new Ray2(new Point2(0, 0), new Point2(1, 1)); var b = new Ray2(new Point2(1, 1), new Point2(0, 0)); IntersectionTest(a, b, new Segment2(Point2.Zero, new Point2(1, 1))); }
public void distance_point() { var ray = new Ray2(new Point2(1, 1), new Vector2(2, 1)); Assert.Equal(System.Math.Sqrt(1 + (.5 * .5)), ray.Distance(new Point2(1.5, 2.5))); Assert.Equal(2, ray.Distance(new Point2(-1, 1))); }
public void intersection_parallel_butts() { var a = new Ray2(new Point2(1, 1), new Point2(2, 2)); var b = new Ray2(new Point2(1, 1), new Point2(0, 0)); IntersectionTest(a, b, new Point2(1, 1)); }
private void OnDrawGizmos() { Ray2 ray = CreateRay2(Ray); Circle2 circle = CreateCircle2(Circle); bool test = Intersection.TestRay2Circle2(ref ray, ref circle); Ray2Circle2Intr info; bool find = Intersection.FindRay2Circle2(ref ray, ref circle, out info); FiguresColor(); DrawRay(ref ray); DrawCircle(ref circle); if (find) { Gizmos.color = Color.blue; if (info.IntersectionType == IntersectionTypes.Point) { DrawPoint(info.Point0); } else if (info.IntersectionType == IntersectionTypes.Segment) { DrawSegment(info.Point0, info.Point1); DrawPoint(info.Point0); DrawPoint(info.Point1); } } LogInfo(info.IntersectionType); if (test != find) { LogError("test != find"); } }
public void intersection_two_rays_on_edge_of_defining_point() { var a = new Ray2(Point2.Zero, new Point2(1, 1)); var b = new Ray2(new Point2(0.5, 1.5), new Point2(1.5, .5)); IntersectionTest(a, b, new Point2(1, 1)); }
public static bool Crosses(this Ray2 ray, Rectangle rectangle, out float near, out float far) { Point2 center = new Point2(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2); Size2 halfExtents = new Size2(rectangle.Width / 2, rectangle.Height / 2); BoundingRectangle boundingRectangle = new BoundingRectangle(center, halfExtents); return(ray.Crosses(boundingRectangle, out near, out far)); }
private Entity CheckEntityCollide(Vector3 position, Vector3 direction) { Ray2 ray = new Ray2 { x = position, d = direction.Normalize() }; var players = Level.GetSpawnedPlayers().OrderBy(player => position.DistanceTo(player.KnownPosition.ToVector3())); foreach (var entity in players) { if (entity == Shooter) { continue; } if (Intersect(entity.GetBoundingBox(), ray)) { if (ray.tNear > direction.Distance) { break; } Vector3 p = ray.x + ray.tNear * ray.d; KnownPosition = new PlayerLocation((float)p.X, (float)p.Y, (float)p.Z); return(entity); } } var entities = Level.Entities.Values.OrderBy(entity => position.DistanceTo(entity.KnownPosition.ToVector3())); foreach (Entity entity in entities) { if (entity == Shooter) { continue; } if (entity == this) { continue; } if (Intersect(entity.GetBoundingBox(), ray)) { if (ray.tNear > direction.Distance) { break; } Vector3 p = ray.x + ray.tNear * ray.d; KnownPosition = new PlayerLocation((float)p.X, (float)p.Y, (float)p.Z); return(entity); } } return(null); }
public void constructor_point_point() { var a = new Ray2(new Point2(0, 0), new Point2(2, 3)); var b = new Ray2(new Point2(1, 2), new Point2(3, 4)); Assert.Equal(new Point2(0, 0), a.P); Assert.Equal(new Vector2(2, 3), a.Direction); Assert.Equal(new Point2(1, 2), b.P); Assert.Equal(new Vector2(2, 2), b.Direction); }
public void Equals_FalseForNotEqual() { var a = new Ray2(new Vector2(1, 2), Vector2.UnitY); var b = new Ray2(new Vector2(1, 2), Vector2.UnitX); Assert.IsFalse(a.Equals(b)); Assert.IsFalse(a.Equals((object)b)); Assert.IsFalse(a == b); }
public void Equals_TrueForEqual() { var a = new Ray2(new Vector2(1, 2), Vector2.UnitY); var b = a; Assert.IsTrue(a.Equals(b)); Assert.IsTrue(a.Equals((object)b)); Assert.IsTrue(a == b); }
public static void ray_ray_intersection_result() { var a = new Ray2(A, B); var b = new Ray2(C, D); var forward = a.Intersection(b); var reverse = b.Intersection(a); forward.Should().NotBeNull(); forward.Should().Be(reverse); }
public void equal_op() { var a = new Ray2(new Point2(1, 3), new Point2(2, 5)); var b = new Ray2(new Point2(1, 3), new Point2(2, 5)); var c = new Ray2(new Point2(0, 2), new Point2(5, 6)); var d = new Ray2(new Point2(2, 5), new Point2(1, 3)); Assert.Equal(a, b); Assert.Equal(b, a); Assert.NotEqual(a, c); Assert.NotEqual(c, a); Assert.NotEqual(a, d); Assert.NotEqual(d, a); }
public static void line_ray_intersection_result() { var a1 = new Line2(A, B); var a2 = new Line2(B, A); var b = new Ray2(C, D); var forward1 = a1.Intersection(b); var forward2 = a2.Intersection(b); var reverse1 = b.Intersection(a1); var reverse2 = b.Intersection(a2); forward1.Should().NotBeNull(); forward1.Should().Be(forward2); forward1.Should().Be(reverse1); forward1.Should().Be(reverse2); }
public void intersects_point_test() { var ray = new Ray2(new Point2(2, 1), new Vector2(2, 1)); Assert.False(ray.Intersects(new Point2(-2, -1))); Assert.False(ray.Intersects(new Point2(0, 0))); Assert.True(ray.Intersects(new Point2(6, 3))); Assert.True(ray.Intersects(new Point2(2, 1))); Assert.True(ray.Intersects(new Point2(4, 2))); Assert.False(ray.Intersects(new Point2(1, 2))); }
public void magnitude_squared() { var ray = new Ray2(new Point2(1, 2), new Vector2(3, 4)); Assert.Equal(double.PositiveInfinity, ray.GetMagnitudeSquared()); }
public void definition_point_get() { var ray = new Ray2(new Point2(1, 2), new Vector2(3, 4)); Assert.Equal(new Point2(1, 2), ((IRay2<double>)ray).P); }
public void raw_intersection_result() { var a = new Segment2(new Point2(0, -1), new Point2(0, 1)); var b = new Ray2(new Point2(1, 1), new Vector2(1, 1)); var c = new Ray2(new Point2(1, 1), new Vector2(-1, -1)); var d = new Ray2(new Point2(0, 1), new Vector2(0, 1)); var e = new Ray2(new Point2(0, -1), new Vector2(0, -1)); var f = new Ray2(new Point2(0, 0), new Vector2(0, 3)); Assert.Equal(null, a.Intersection(b)); Assert.Equal(new Point2(0, 0), a.Intersection(c)); Assert.Equal(null, a.Intersection(new Ray2(new Point2(0, 2), new Vector2(0, 1)))); Assert.Equal(null, a.Intersection(new Ray2(new Point2(0, -2), new Vector2(0, -1)))); Assert.Equal(new Point2(0, 1), a.Intersection(d)); Assert.Equal(a, a.Intersection(d.GetReverse())); Assert.Equal(new Point2(0, -1), a.Intersection(e)); Assert.Equal(a, a.Intersection(e.GetReverse())); Assert.Equal(new Segment2(f.P, a.B), a.Intersection(f)); Assert.Equal(new Segment2(a.A, f.P), a.Intersection(f.GetReverse())); }
//public static Vector3 getRandom(AxisAlignedBB aabb) //{ // Vector min = getMinimum(aabb), max = getMaximum(aabb); // Random random = GameManager.getInstance().getRandom(); // return new Vector( // random.nextFloat() * (max.getX() - min.getX()) + min.getX(), // random.nextFloat() * (max.getY() - min.getY()) + min.getY(), // random.nextFloat() * (max.getZ() - min.getZ()) + min.getZ() // ); //} public static bool Intersect(BoundingBox aabb, Ray2 ray) { Vector3 min = GetMinimum(aabb), max = GetMaximum(aabb); double ix = ray.x.X; double iy = ray.x.Y; double iz = ray.x.Z; double t, u, v; bool hit = false; ray.tNear = Double.MaxValue; t = (min.X - ix)/ray.d.X; if (t < ray.tNear && t > -Ray2.EPSILON) { u = iz + ray.d.Z*t; v = iy + ray.d.Y*t; if (u >= min.Z && u <= max.Z && v >= min.Y && v <= max.Y) { hit = true; ray.tNear = t; ray.u = u; ray.v = v; ray.n.X = -1; ray.n.Y = 0; ray.n.Z = 0; } } t = (max.X - ix)/ray.d.X; if (t < ray.tNear && t > -Ray2.EPSILON) { u = iz + ray.d.Z*t; v = iy + ray.d.Y*t; if (u >= min.Z && u <= max.Z && v >= min.Y && v <= max.Y) { hit = true; ray.tNear = t; ray.u = 1 - u; ray.v = v; ray.n.X = 1; ray.n.Y = 0; ray.n.Z = 0; } } t = (min.Y - iy)/ray.d.Y; if (t < ray.tNear && t > -Ray2.EPSILON) { u = ix + ray.d.X*t; v = iz + ray.d.Z*t; if (u >= min.X && u <= max.X && v >= min.Z && v <= max.Z) { hit = true; ray.tNear = t; ray.u = u; ray.v = v; ray.n.X = 0; ray.n.Y = -1; ray.n.Z = 0; } } t = (max.Y - iy)/ray.d.Y; if (t < ray.tNear && t > -Ray2.EPSILON) { u = ix + ray.d.X*t; v = iz + ray.d.Z*t; if (u >= min.X && u <= max.X && v >= min.Z && v <= max.Z) { hit = true; ray.tNear = t; ray.u = u; ray.v = v; ray.n.X = 0; ray.n.Y = 1; ray.n.Z = 0; } } t = (min.Z - iz)/ray.d.Z; if (t < ray.tNear && t > -Ray2.EPSILON) { u = ix + ray.d.X*t; v = iy + ray.d.Y*t; if (u >= min.X && u <= max.X && v >= min.Y && v <= max.Y) { hit = true; ray.tNear = t; ray.u = 1 - u; ray.v = v; ray.n.X = 0; ray.n.Y = 0; ray.n.Z = -1; } } t = (max.Z - iz)/ray.d.Z; if (t < ray.tNear && t > -Ray2.EPSILON) { u = ix + ray.d.X*t; v = iy + ray.d.Y*t; if (u >= min.X && u <= max.X && v >= min.Y && v <= max.Y) { hit = true; ray.tNear = t; ray.u = u; ray.v = v; ray.n.X = 0; ray.n.Y = 0; ray.n.Z = 1; } } return hit; }
public void intersection_ray_with_grain() { var a = new Ray2(Point2.Zero, new Point2(4, 4)); var d = new Vector2(2, 2); for (var v = -3.0; v <= 0; v++) { var b = new Ray2(new Point2(v, v), d); IntersectionTest(a, b, a); } for (var v = 0; v <= 5.0; v++) { var b = new Ray2(new Point2(v, v), d); IntersectionTest(a, b, b); } }
public void intersection_ray_against_grain() { var a = new Ray2(Point2.Zero, new Point2(4, 4)); var direction = new Vector2(-2, -2); var b = new Ray2(new Point2(-1, -1), direction); var c = new Ray2(Point2.Zero, direction); IntersectionTest(a, b, null); IntersectionTest(a, c, Point2.Zero); for (var v = 1.0; v <= 4.0; v++) { var p = new Point2(v, v); IntersectionTest(a, new Ray2(p, direction), new Segment2(Point2.Zero, p)); } for (var v = 5.0; v <= 7.0; v++) { var p = new Point2(v, v); IntersectionTest(a, new Ray2(p, direction), new Segment2(Point2.Zero, p)); } }
public void intersection_identical() { var a = new Ray2(new Point2(0, 0), new Point2(1, 1)); var b = new Ray2(new Point2(0, 0), new Point2(1, 1)); Assert.Equal(a, a.Intersection(a)); Assert.Equal(b, a.Intersection(a)); Assert.Equal(a, b.Intersection(b)); Assert.Equal(b, b.Intersection(b)); Assert.Equal(a, a.Intersection(b)); Assert.Equal(b, a.Intersection(b)); Assert.Equal(a, b.Intersection(a)); Assert.Equal(b, b.Intersection(a)); }
private Entity CheckEntityCollide(Vector3 position, Vector3 direction) { Ray2 ray = new Ray2 { x = position, d = Vector3.Normalize(direction) }; var players = Level.GetSpawnedPlayers().OrderBy(player => Vector3.Distance(position, player.KnownPosition.ToVector3())); foreach (var entity in players) { if (entity == Shooter) continue; if (Intersect(entity.GetBoundingBox(), ray)) { if (ray.tNear > direction.Length()) break; Vector3 p = ray.x + new Vector3((float) ray.tNear)*ray.d; KnownPosition = new PlayerLocation((float) p.X, (float) p.Y, (float) p.Z); return entity; } } var entities = Level.Entities.Values.OrderBy(entity => Vector3.Distance(position, entity.KnownPosition.ToVector3())); foreach (Entity entity in entities) { if (entity == Shooter) continue; if (entity == this) continue; if (entity is Projectile) continue; if (Intersect(entity.GetBoundingBox(), ray)) { if (ray.tNear > direction.Length()) break; Vector3 p = ray.x + new Vector3((float) ray.tNear)*ray.d; KnownPosition = new PlayerLocation(p.X, p.Y, p.Z); return entity; } } return null; }
public void intersection_point_below_ray() { var a = new Ray2(Point2.Zero, new Point2(4, 4)); var direction = new Vector2(1, 0); for (var v = -3.0; v <= 1.0; v++) { var b = new Ray2(new Point2(v, -1), direction); IntersectionTest(a, b, null); } }
private Entity CheckEntityCollide(Vector3 position, Vector3 direction) { var players = Level.GetSpawnedPlayers().OrderBy(player => position.DistanceTo(player.KnownPosition.ToVector3())); Ray2 ray = new Ray2 { x = position, d = direction.Normalize() }; foreach (var entity in players) { if (entity == Shooter) continue; if (Intersect(entity.GetBoundingBox(), ray)) { if (ray.tNear < direction.Distance) break; Vector3 p = ray.x + ray.tNear*ray.d; KnownPosition = new PlayerLocation((float) p.X, (float) p.Y, (float) p.Z); return entity; } } var entities = Level.Entities.Values.OrderBy(entity => position.DistanceTo(entity.KnownPosition.ToVector3())); foreach (Entity entity in entities) { if (entity == Shooter) continue; if (entity == this) continue; if (Intersect(entity.GetBoundingBox(), ray)) { if (ray.tNear < direction.Distance) break; Vector3 p = ray.x + ray.tNear*ray.d; KnownPosition = new PlayerLocation((float) p.X, (float) p.Y, (float) p.Z); return entity; } } return null; }
public void mbr() { var a = new Ray2(new Point2(1, 1), new Vector2(1, 1)); var b = new Ray2(new Point2(1, 1), new Vector2(0, 1)); Assert.Equal(double.PositiveInfinity, a.GetMbr().YMax); Assert.Equal(double.PositiveInfinity, a.GetMbr().XMax); Assert.Equal(1, a.GetMbr().YMin); Assert.Equal(double.PositiveInfinity, b.GetMbr().YMax); Assert.Equal(1, b.GetMbr().XMax); Assert.Equal(1, b.GetMbr().YMin); }
public void ray_intersects_test() { var a = new Segment2(new Point2(0, -1), new Point2(0, 1)); var b = new Ray2(new Point2(1, 1), new Vector2(1, 1)); var c = new Ray2(new Point2(1, 1), new Vector2(-1, -1)); var d = new Ray2(new Point2(0, 1), new Vector2(0, 1)); var e = new Ray2(new Point2(0, -1), new Vector2(0, -1)); var f = new Ray2(new Point2(0, 0), new Vector2(0, 3)); Assert.False(a.Intersects(b)); Assert.True(a.Intersects(c)); Assert.False(a.Intersects(new Ray2(new Point2(0, 2), new Vector2(0, 1)))); Assert.False(a.Intersects(new Ray2(new Point2(0, -2), new Vector2(0, -1)))); Assert.True(a.Intersects(d)); Assert.True(a.Intersects(d.GetReverse())); Assert.True(a.Intersects(e)); Assert.True(a.Intersects(e.GetReverse())); Assert.True(a.Intersects(f)); Assert.True(a.Intersects(f.GetReverse())); }
private static void IntersectionTest(Ray2 a, Ray2 b, object expected) { AreSpatiallyEqual(expected, a.Intersection(b)); AreSpatiallyEqual(expected, b.Intersection(a)); }