Пример #1
0
 public void GetNearest_PointOnRay()
 {
     var ray = new Ray3D(new Point3D(0, 0, 0), new Vector3D(1, 2, 3));
     var p0 = new Point3D(0.1, 0.2, 0.3);
     var p = ray.GetNearest(p0);
     Assert.AreEqual(0, p0.DistanceTo(p), 1e-12);
 }
Пример #2
0
 public void PlaneIntersection_RayThroughPlaneOrigin()
 {
     var ray = new Ray3D(new Point3D(1, 2, 3), new Vector3D(-1, -2, -3));
     Point3D p;
     Assert.IsTrue(ray.PlaneIntersection(new Point3D(0, 0, 0), new Vector3D(1, 1, 1), out p));
     var pe = new Point3D(0, 0, 0);
     Assert.AreEqual(0, pe.DistanceTo(p), 1e-12);
 }
Пример #3
0
 /// <summary>
 /// Gets the distance from the camera for the specified visual.
 /// </summary>
 /// <param name="c">
 /// The visual.
 /// </param>
 /// <param name="cameraPos">
 /// The camera position.
 /// </param>
 /// <param name="transform">
 /// The total transform of the visual.
 /// </param>
 /// <returns>
 /// The camera distance.
 /// </returns>
 private double GetCameraDistance(Visual3D c, Point3D cameraPos, Transform3D transform)
 {
     var bounds = Visual3DHelper.FindBounds(c, transform);
     switch (this.Method)
     {
         case SortingMethod.BoundingBoxCenter:
             var mid = new Point3D(
                 bounds.X + bounds.SizeX * 0.5, bounds.Y + bounds.SizeY * 0.5, bounds.Z + bounds.SizeZ * 0.5);
             return (mid - cameraPos).LengthSquared;
         case SortingMethod.BoundingBoxCorners:
             double d = double.MaxValue;
             d = Math.Min(d, cameraPos.DistanceTo(new Point3D(bounds.X, bounds.Y, bounds.Z)));
             d = Math.Min(d, cameraPos.DistanceTo(new Point3D(bounds.X + bounds.SizeX, bounds.Y, bounds.Z)));
             d = Math.Min(
                 d, cameraPos.DistanceTo(new Point3D(bounds.X + bounds.SizeX, bounds.Y + bounds.SizeY, bounds.Z)));
             d = Math.Min(d, cameraPos.DistanceTo(new Point3D(bounds.X, bounds.Y + bounds.SizeY, bounds.Z)));
             d = Math.Min(d, cameraPos.DistanceTo(new Point3D(bounds.X, bounds.Y, bounds.Z + bounds.SizeZ)));
             d = Math.Min(
                 d, cameraPos.DistanceTo(new Point3D(bounds.X + bounds.SizeX, bounds.Y, bounds.Z + bounds.SizeZ)));
             d = Math.Min(
                 d,
                 cameraPos.DistanceTo(
                     new Point3D(bounds.X + bounds.SizeX, bounds.Y + bounds.SizeY, bounds.Z + bounds.SizeZ)));
             d = Math.Min(
                 d, cameraPos.DistanceTo(new Point3D(bounds.X, bounds.Y + bounds.SizeY, bounds.Z + bounds.SizeZ)));
             return d;
         default:
             var boundingSphere = BoundingSphere.CreateFromRect3D(bounds);
             return boundingSphere.DistanceFrom(cameraPos);
     }
 }
Пример #4
0
 /// <summary>
 /// Calculates the distance from a point to the nearest point on the sphere surface.
 /// </summary>
 /// <param name="point">
 /// The point.
 /// </param>
 /// <returns>
 /// The distance.
 /// </returns>
 public double DistanceFrom(Point3D point)
 {
     return point.DistanceTo(this.center) - this.radius;
 }