30 namespace OpenSim.
Region.PhysicsModules.ConvexDecompositionDotNet
32 public class float3 : IEquatable<float3>
45 public float3(
float _x,
float _y,
float _z)
59 public float this[
int i]
69 throw new ArgumentOutOfRangeException();
84 return dx * dx + dy * dy + dz * dz;
89 return (
float)Math.Sqrt(x * x + y * y + z * z);
94 float A = Partial(p1);
96 A += p2.Partial(
this);
102 return (x * p.
y) - (p.x * y);
110 float3 lineDelta = line1 - line0;
115 nearestPoint = line0;
119 float delta = float3.dot(point - line0, lineDelta) /
float3.
dot(lineDelta, lineDelta);
120 nearestPoint = line0 + lineDelta * delta;
123 this.x = nearestPoint.x;
124 this.y = nearestPoint.y;
125 this.z = nearestPoint.z;
133 float3 lineDelta = line1 - line0;
136 if (lineDelta == Zero)
138 nearestPoint = line0;
142 float delta = float3.dot(point - line0, lineDelta) /
float3.
dot(lineDelta, lineDelta);
150 nearestPoint = line0 + lineDelta * delta;
153 this.x = nearestPoint.x;
154 this.y = nearestPoint.y;
155 this.z = nearestPoint.z;
164 float3 lineDelta0 = triangle1 - triangle0;
165 float3 lineDelta1 = triangle2 - triangle0;
168 if ((lineDelta0 == Zero) || (lineDelta1 == Zero))
170 nearestPoint.NearestPointInLineSegment(point, triangle1, triangle2);
172 else if (lineDelta0 == lineDelta1)
174 nearestPoint.NearestPointInLineSegment(point, triangle0, triangle1);
179 axis[0].NearestPointInLine(triangle0, triangle1, triangle2);
180 axis[1].NearestPointInLine(triangle1, triangle0, triangle2);
181 axis[2].NearestPointInLine(triangle2, triangle0, triangle1);
184 axisDot.x = dot(triangle0 - axis[0], point - axis[0]);
185 axisDot.y = dot(triangle1 - axis[1], point - axis[1]);
186 axisDot.z = dot(triangle2 - axis[2], point - axis[2]);
189 float bestMagnitude2 = 0;
190 float closeMagnitude2;
195 closePoint.NearestPointInLineSegment(point, triangle1, triangle2);
196 closeMagnitude2 = point.Distance2(closePoint);
197 if (bForce || (bestMagnitude2 > closeMagnitude2))
200 bestMagnitude2 = closeMagnitude2;
201 nearestPoint = closePoint;
206 closePoint.NearestPointInLineSegment(point, triangle0, triangle2);
207 closeMagnitude2 = point.Distance2(closePoint);
208 if (bForce || (bestMagnitude2 > closeMagnitude2))
211 bestMagnitude2 = closeMagnitude2;
212 nearestPoint = closePoint;
217 closePoint.NearestPointInLineSegment(point, triangle0, triangle1);
218 closeMagnitude2 = point.Distance2(closePoint);
219 if (bForce || (bestMagnitude2 > closeMagnitude2))
222 bestMagnitude2 = closeMagnitude2;
223 nearestPoint = closePoint;
234 normal = float3.cross(lineDelta0, lineDelta1);
236 float3 pointDelta = point - triangle0;
237 float delta = float3.dot(normal, pointDelta) /
float3.
dot(normal, normal);
239 nearestPoint = point - normal * delta;
243 this.x = nearestPoint.x;
244 this.y = nearestPoint.y;
245 this.z = nearestPoint.z;
260 return new float3(a.
x - s, a.
y - s, a.
z - s);
270 return new float3(v.
x * s, v.
y * s, v.
z * s);
275 return new float3(v.
x * s, v.
y * s, v.
z * s);
285 return new float3(dot(m.
x, v), dot(m.
y, v), dot(m.
z, v));
290 float sinv = 1.0f / s;
291 return new float3(v.
x * sinv, v.
y * sinv, v.
z * sinv);
296 return this == other;
310 return x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode();
316 if (System.Object.ReferenceEquals(a, b))
319 if (((
object)a == null) || ((object)b == null))
322 return (a.
x == b.
x && a.
y == b.
y && a.
z == b.
z);
327 return (a.
x != b.
x || a.
y != b.
y || a.
z != b.
z);
332 return a.x * b.x + a.y * b.y + a.z * b.z;
337 return new float3(v1.
x * v2.
x, v1.
y * v2.
y, v1.
z * v2.
z);
342 return new float3(a.
y * b.
z - a.
z * b.
y, a.
z * b.
x - a.
x * b.
z, a.
x * b.
y - a.
y * b.
x);
347 return v0 * (1 - alpha) + v1 * alpha;
352 return new float3((
float)Math.Round(a.
x, digits), (float)Math.Round(a.
y, digits), (float)Math.Round(a.
z, digits));
357 return new float3(Math.Max(a.
x, b.
x), Math.Max(a.y, b.y), Math.Max(a.
z, b.
z));
362 return new float3(Math.Min(a.
x, b.
x), Math.Min(a.y, b.y), Math.Min(a.
z, b.
z));
367 return new float3(Math.Abs(v.
x), Math.Abs(v.y), Math.Abs(v.
z));
372 return (
float)Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
377 float d = magnitude(v);
381 return new float3(v.
x * d, v.
y * d, v.
z * d);
386 if (magnitude(v) <= 0.0f)
387 return new float3(1, 0, 0);
394 return (v.
y == 0.0 && v.
x == 0.0) ? 0.0f : (float)Math.Atan2(-v.
x, v.
y) * (180.0f / 3.14159264f);
399 return (
float)Math.Atan2(v.z, Math.Sqrt(v.x * v.x + v.y * v.y)) * (180.0f / 3.14159264f);
404 float vx, vy, vz, wx, wy, wz, vw_x, vw_y, vw_z, mag;
414 vw_x = vy * wz - vz * wy;
415 vw_y = vz * wx - vx * wz;
416 vw_z = vx * wy - vy * wx;
418 mag = (float)Math.Sqrt((vw_x * vw_x) + (vw_y * vw_y) + (vw_z * vw_z));
433 float D = 0.0f - ((x * A.x) + (y * A.
y) + (z * A.z));
439 return String.Format(
"<{0}, {1}, {2}>", x, y, z);
void NearestPointInLine(float3 point, float3 line0, float3 line1)
override bool Equals(object obj)
static float Pitch(float3 v)
bool Equals(float3 other)
static float3 normalize(float3 v)
override int GetHashCode()
override string ToString()
void NearestPointInTriangle(float3 point, float3 triangle0, float3 triangle1, float3 triangle2)
void NearestPointInLineSegment(float3 point, float3 line0, float3 line1)
static float3 Round(float3 a, int digits)
float ComputePlane(float3 A, float3 B, float3 C)
static float3 vabs(float3 v)
float Distance2(float3 a)
static float Yaw(float3 v)
static float magnitude(float3 v)
static float3 cross(float3 a, float3 b)
static float dot(float3 a, float3 b)
float3(float _x, float _y, float _z)
static float3 VectorMin(float3 a, float3 b)
static float3 VectorMax(float3 a, float3 b)
static float3 cmul(float3 v1, float3 v2)
static readonly float3 Zero
static float3 Interpolate(float3 v0, float3 v1, float alpha)
float Area(float3 p1, float3 p2)
static float3 safenormalize(float3 v)