private static Vector3D CalculateMove(Body body, Vector3D normal, Axis3D startMoveRay, Axis3D endMoveRay) { var planeOffset = body.Frame.Offset; var planeNormal = body.Frame * normal; var movePlane = new Plane3D(planeOffset, planeNormal); var(startIsIntersecting, startIntersection) = movePlane.Intersect(startMoveRay); var(endIsIntersecting, endIntersection) = movePlane.Intersect(endMoveRay); var moveVector = startIsIntersecting && endIsIntersecting ? endIntersection - startIntersection : new Vector3D(); return(moveVector); }
private static Position3D GetPosition(Axis3D moveRay, Plane3D axisPlane) { var(success, position) = axisPlane.Intersect(moveRay); var result = success ? position : moveRay.Offset; return(result); }
public void IntersectTest_WhenParallelStraightLineNotIntersectsPlane_ThenResultIsEmpty() { var plane = new Plane3D(new Position3D(100, 100, 0), new Vector3D(0, 0, 1)); var axis = new Axis3D(new Position3D(100, 100, 100), new Vector3D(1, 1, 0)); var(success, intersection) = plane.Intersect(axis); var(success2, intersection2) = axis.Intersect(plane); Assert.False(success); Assert.False(success2); }
public void IntersectTest_WhenStraightLineYIntersectsPlaneXZ_ThenResultIsIntersection() { var plane = new Plane3D(new Position3D(0, 100, 0), new Vector3D(0, 1, 0)); var axis = new Axis3D(new Position3D(100, 0, 100), new Vector3D(0, 1, 0)); var(success, intersection) = plane.Intersect(axis); var(success2, intersection2) = axis.Intersect(plane); Assert.True(success); Assert.Equal(new Position3D(100, 100, 100), intersection); Assert.True(success2); Assert.Equal(new Position3D(100, 100, 100), intersection2); }
public IEnumerable <HitInfo <float3> > Raycast(RayDescription ray) { float t; if (!plane.Intersect(new Ray3D(ray.Origin, ray.Direction), out t)) { yield break; } if (t >= ray.MinT && t < ray.MaxT) { yield return new HitInfo <float3> { T = t, Attribute = ray.Origin + t * ray.Direction } } ; } }
public double TestAngle(Point pt, HitResult prevHit, Axis axis) { Ray3D ray = Ext3D.Unproject(pt, _viewpoint, _model.Transform, _inverseViewMatrix, _inverseProjectionMatrix); //Plane yz = new Plane(-1, 0, 0, prevHit.HitPoint.X); //Point3 pyz; double? d = yz.Intersects(ray); Debug.WriteLine(string.Format("second ray: {0}: distance: {1}", ray, (double)d)); //Debug.WriteLine(string.Format("second ray: {0}", ray)); double angle = 0; switch (axis) { case Axis.X: Plane3D yz = new Plane3D(new Vector3D(-1, 0, 0), prevHit.HitPoint.X); Point3D oyz = new Point3D(prevHit.HitPoint.X, 0, 0); Point3D pyz; yz.Intersect(ray, out pyz); Vector3D from = prevHit.HitPoint - oyz; Vector3D to = pyz - oyz; angle = Ext3D.AngleBetween(from, to); if (Vector3D.DotProduct(Ext3D.UnitX, Vector3D.CrossProduct(from, to)) < 0) { angle = -angle; } break; case Axis.Z: Plane3D xy = new Plane3D(new Vector3D(0, 0, -1), prevHit.HitPoint.Z); Point3D oxy = new Point3D(0, 0, prevHit.HitPoint.Z); Point3D pxy; xy.Intersect(ray, out pxy); from = prevHit.HitPoint - oxy; to = pxy - oxy; angle = Ext3D.AngleBetween(from, to); if (Vector3D.DotProduct(Ext3D.UnitZ, Vector3D.CrossProduct(from, to)) < 0) { angle = -angle; } break; case Axis.Y: Plane3D zx = new Plane3D(new Vector3D(0, -1, 0), prevHit.HitPoint.Y); Point3D ozx = new Point3D(0, prevHit.HitPoint.Y, 0); Point3D pzx; zx.Intersect(ray, out pzx); from = prevHit.HitPoint - ozx; to = pzx - ozx; angle = Ext3D.AngleBetween(from, to); if (Vector3D.DotProduct(Ext3D.UnitY, Vector3D.CrossProduct(from, to)) < 0) { angle = -angle; } break; } /* * if (angle < 2) * angle = null; * else * { * Debug.WriteLine(string.Format("axis: {0}, angle:{1}", axis, angle)); * } */ return(angle); }