Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
pluginbase.Helpers.Geometry.Sphere Struct Reference
Inheritance diagram for pluginbase.Helpers.Geometry.Sphere:
pluginbase.Helpers.Geometry.IIntersectable

Public Member Functions

 Sphere (Sphere sphere)
 
 Sphere (Vector3d point, double radius)
 
bool Intersects (Ray ray, out double dist)
 

Public Attributes

Vector3d Point
 
double Radius
 

Properties

double Volume [get]
 

Constructor & Destructor Documentation

pluginbase.Helpers.Geometry.Sphere.Sphere ( Sphere  sphere)
13  {
14  this.Point = sphere.Point;
15  this.Radius = sphere.Radius;
16  }
Vector3d Point
Definition: Sphere.cs:8
double Radius
Definition: Sphere.cs:10
pluginbase.Helpers.Geometry.Sphere.Sphere ( Vector3d  point,
double  radius 
)
19  {
20  this.Point = point;
21  this.Radius = radius;
22  }
Vector3d Point
Definition: Sphere.cs:8
double Radius
Definition: Sphere.cs:10

Member Function Documentation

bool pluginbase.Helpers.Geometry.Sphere.Intersects ( Ray  ray,
out double  dist 
)

Implements pluginbase.Helpers.Geometry.IIntersectable.

35  {
36  var vpc = this.Point - ray.Point;
37 
38  if (Vector3d.Dot(vpc, ray.Direction) < 0.0)
39  {
40  //Sphere is behind origin point, but need to test
41  if (vpc.Length > this.Radius)
42  {
43  dist = 0.0;
44  return false;
45  }
46 
47  Vector3d pc = ray.ProjectPoint(this.Point);
48  double pcLen = (pc - this.Point).Length;
49  double pcDist = Math.Sqrt(this.Radius*this.Radius - pcLen*pcLen);
50  dist = pcDist - (pc - ray.Point).Length;
51  return true;
52  }
53 
54  Vector3d projC = ray.ProjectPoint(this.Point);
55  if ((this.Point - projC).Length > this.Radius)
56  {
57  dist = 0.0;
58  return false;
59  }
60 
61  double pcToC = (projC - this.Point).Length;
62  double projDist = Math.Sqrt(this.Radius * this.Radius - pcToC * pcToC);
63 
64  if (vpc.Length > this.Radius) //origin outside the sphere
65  {
66  dist = (projC - ray.Point).Length - projDist;
67  }
68  else
69  {
70  dist = (projC - ray.Point).Length + projDist;
71  }
72  return true;
73  }
float Length
Gets the length of the vector
Definition: Vector3i.cs:165
Vector3d Point
Definition: Sphere.cs:8
double Radius
Definition: Sphere.cs:10

Member Data Documentation

Vector3d pluginbase.Helpers.Geometry.Sphere.Point
double pluginbase.Helpers.Geometry.Sphere.Radius

Property Documentation

double pluginbase.Helpers.Geometry.Sphere.Volume
get

The documentation for this struct was generated from the following file: