Empeld
Empeld plugin documentation.
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)
 
 Sphere (double x, double y, double z, double radius)
 
bool Contains (Vector3d pt)
 
double Distance (Vector3d pt)
 
bool Intersects (Ray ray, out double dist)
 
override string ToString ()
 

Public Attributes

Vector3d Point
 
double Radius
 

Properties

double Volume [get]
 

Constructor & Destructor Documentation

◆ Sphere() [1/3]

pluginbase.Helpers.Geometry.Sphere.Sphere ( Sphere  sphere)
12  {
13  this.Point = sphere.Point;
14  this.Radius = sphere.Radius;
15  }
Vector3d Point
Definition: Sphere.cs:8
double Radius
Definition: Sphere.cs:9

◆ Sphere() [2/3]

pluginbase.Helpers.Geometry.Sphere.Sphere ( Vector3d  point,
double  radius 
)
18  {
19  this.Point = point;
20  this.Radius = radius;
21  }
Vector3d Point
Definition: Sphere.cs:8
double Radius
Definition: Sphere.cs:9

◆ Sphere() [3/3]

pluginbase.Helpers.Geometry.Sphere.Sphere ( double  x,
double  y,
double  z,
double  radius 
)
24  {
25  this.Point = new Vector3d(x, y, z);
26  this.Radius = radius;
27  }
Vector3d Point
Definition: Sphere.cs:8
double Radius
Definition: Sphere.cs:9

Member Function Documentation

◆ Contains()

bool pluginbase.Helpers.Geometry.Sphere.Contains ( Vector3d  pt)
38  {
39  return (this.Point - pt).Length < this.Radius;
40  }
Vector3d Point
Definition: Sphere.cs:8
double Radius
Definition: Sphere.cs:9

◆ Distance()

double pluginbase.Helpers.Geometry.Sphere.Distance ( Vector3d  pt)
43  {
44  return (this.Point - pt).Length;
45  }
Vector3d Point
Definition: Sphere.cs:8

◆ Intersects()

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

Implements pluginbase.Helpers.Geometry.IIntersectable.

50  {
51  var vpc = this.Point - ray.Point;
52 
53  if (Vector3d.Dot(vpc, ray.Direction) < 0.0)
54  {
55  //Sphere is behind origin point, but need to test
56  if (vpc.Length > this.Radius)
57  {
58  dist = 0.0;
59  return false;
60  }
61 
62  Vector3d pc = ray.ProjectPoint(this.Point);
63  double pcLen = (pc - this.Point).Length;
64  double pcDist = Math.Sqrt(this.Radius*this.Radius - pcLen*pcLen);
65  dist = pcDist - (pc - ray.Point).Length;
66  return true;
67  }
68 
69  Vector3d projC = ray.ProjectPoint(this.Point);
70  if ((this.Point - projC).Length > this.Radius)
71  {
72  dist = 0.0;
73  return false;
74  }
75 
76  double pcToC = (projC - this.Point).Length;
77  double projDist = Math.Sqrt(this.Radius * this.Radius - pcToC * pcToC);
78 
79  if (vpc.Length > this.Radius) //origin outside the sphere
80  {
81  dist = (projC - ray.Point).Length - projDist;
82  }
83  else
84  {
85  dist = (projC - ray.Point).Length + projDist;
86  }
87  return true;
88  }
float Length
Definition: Vector2i.cs:129
Vector3d Point
Definition: Sphere.cs:8
double Radius
Definition: Sphere.cs:9

◆ ToString()

override string pluginbase.Helpers.Geometry.Sphere.ToString ( )
93  {
94  return string.Format("[Sphere: Point={0}, Radius={1}]", Point, Radius);
95  }
Vector3d Point
Definition: Sphere.cs:8
double Radius
Definition: Sphere.cs:9

Member Data Documentation

◆ Point

Vector3d pluginbase.Helpers.Geometry.Sphere.Point

◆ Radius

double pluginbase.Helpers.Geometry.Sphere.Radius

Property Documentation

◆ Volume

double pluginbase.Helpers.Geometry.Sphere.Volume
get

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