Empeld Empeld plugin documentation.
pluginbase.Helpers.Computative.VExt Class Reference

Vector math extensions More...

## Static Public Member Functions

static Vector3 Slerp (Vector3 a, Vector3 b, float blend)
Slerp between two vectors More...

static Vector3 Nlerp (Vector3 a, Vector3 b, float blend)
Nlerp the specified a, b and blend. More...

static Vector3d Slerp (Vector3d a, Vector3d b, double blend)
Slerp the specified a, b and blend. More...

static Vector3d Nlerp (Vector3d a, Vector3d b, double blend)
Nlerp the specified a, b and blend. More...

static Vector3 SmartNlerp (Vector3 a, Vector3 b, float blend, Vector3 defaultRotateVec)
NLerp that handles near-infinite scenario More...

static Vector3 SmartNlerp (Vector3 a, Vector3 b, float blend)
NLerp that hanles the near-infinite scenario More...

static Vector3d SmartNlerp (Vector3d a, Vector3d b, double blend, Vector3d defaultRotateVec)
Smart nlerp that lerps a vector around a rotation vector More...

static Vector3d SmartNlerp (Vector3d a, Vector3d b, double blend)
NLerp that intelligently rotates one vector to another More...

static Vector3 Abs (Vector3 v)
Returns the component absolute value of a vector More...

static Vector3 InverseAbs (Vector3 v)
Returns the 1f-Abs(v) of each component of a vector More...

static bool InSquareDistance (Vector3 a, Vector3 b, float d)
Checks whether or not two vectors are within a square distance of each other More...

static bool InSquareDistance (Vector3d a, Vector3d b, double d)
Checks whether or not two vectors are within a square distance of each other More...

static bool InSquareDistance (Vector3i a, Vector3i b, int d)
Checks whether or not two vectors are greater than or equal to a square distance of each other More...

static double ComponentDistance (Vector3d a, Vector3d b)
Returns the largest distance of any components More...

static Matrix4 Rotate (Vector3 start, Vector3 end)
Create a rotation matrix to rotate a vector from a given start vector to a target vector More...

static Matrix4 RotationMatrix (Vector3 rot)
Create a rotation matrix given a vector to rotate given radians More...

static Matrix4 MatrixFromComponents (Vector3 translate, Vector3 rotate)
Create a rotation and translation vector given a translation and radians More...

static Vector2 Project (Vector3 pt, Matrix4 modelview, Matrix4 projection)
Project a 3d point to 2d given a modelview and projection More...

static Vector2d Project (Vector3d pt, Matrix4d modelview, Matrix4d projection)
Project a 3D point to 2D point given modelview and projection More...

static float PointToLineDistance (Vector3 line1, Vector3 line2, Vector3 point)
Get the distance between a point and a line More...

static Vector3 SwapXY (this Vector3 v)
Swap X and Y components of a vector More...

static float RotationZ (Vector3 lookDir)
Get the rotation value of the X and Y components of a matrix More...

static float RotationZ (Vector2 lookDir)
Get the rotation given a 2D look direction More...

static double RotationZ (Vector3d lookDir)
Get the Z rotation given a 3d look direction More...

static double RotationZ (Vector2d lookDir)
Get the Z rotation from a 2d vector More...

static Vector3d RotationVector (double rotZ, double speed=1.0)
Get a rotation vector and a power More...

## Detailed Description

Vector math extensions

## Member Function Documentation

 static Vector3 pluginbase.Helpers.Computative.VExt.Abs ( Vector3 v )
static

Returns the component absolute value of a vector

Parameters
 v V.
135  {
136  return new Vector3( Math.Abs(v.X), Math.Abs(v.Y), Math.Abs(v.Z) );
137  }
 static double pluginbase.Helpers.Computative.VExt.ComponentDistance ( Vector3d a, Vector3d b )
static

Returns the largest distance of any components

Returns
The distance.
Parameters
 a The alpha component. b The blue component.
201  {
202  double aX = Math.Abs(a.X - b.X);
203  double aY = Math.Abs(a.Y - b.Y);
204  double aZ = Math.Abs(a.Z - b.Z);
205  return aX > aY && aX > aZ ? aX : (aY > aZ ? aY : aZ); //Largest of the 3
206  }
 static bool pluginbase.Helpers.Computative.VExt.InSquareDistance ( Vector3 a, Vector3 b, float d )
static

Checks whether or not two vectors are within a square distance of each other

Returns
`true`, if manhattan distance was ined, `false` otherwise.
Parameters
 a The a component. b The b component. d D.
157  {
158  if (Math.Abs(a.X - b.X) > d) return false;
159  if (Math.Abs(a.Y - b.Y) > d) return false;
160  if (Math.Abs(a.Z - b.Z) > d) return false;
161  return true;
162  }
 static bool pluginbase.Helpers.Computative.VExt.InSquareDistance ( Vector3d a, Vector3d b, double d )
static

Checks whether or not two vectors are within a square distance of each other

Returns
`true`, if manhattan distance was ined, `false` otherwise.
Parameters
 a The alpha component. b The blue component. d D.
172  {
173  if (Math.Abs(a.X - b.X) > d) return false;
174  if (Math.Abs(a.Y - b.Y) > d) return false;
175  if (Math.Abs(a.Z - b.Z) > d) return false;
176  return true;
177  }
 static bool pluginbase.Helpers.Computative.VExt.InSquareDistance ( Vector3i a, Vector3i b, int d )
static

Checks whether or not two vectors are greater than or equal to a square distance of each other

Returns
`true`, if manhattan distance was ined, `false` otherwise.
Parameters
 a The alpha component. b The blue component. d D.
187  {
188  if (Math.Abs(a.X - b.X) > d) return false;
189  if (Math.Abs(a.Y - b.Y) > d) return false;
190  if (Math.Abs(a.Z - b.Z) > d) return false;
191  return true;
192  }
int Y
The Y coordinate
Definition: Vector3i.cs:23
int X
The X coordinate
Definition: Vector3i.cs:18
int Z
The Z coordinate
Definition: Vector3i.cs:28
 static Vector3 pluginbase.Helpers.Computative.VExt.InverseAbs ( Vector3 v )
static

Returns the 1f-Abs(v) of each component of a vector

Returns
The abs.
Parameters
 v V.
145  {
146  return new Vector3(1f - Math.Abs(v.X), 1f - Math.Abs(v.Y), 1f - Math.Abs(v.Z));
147  }
 static Matrix4 pluginbase.Helpers.Computative.VExt.MatrixFromComponents ( Vector3 translate, Vector3 rotate )
static

Create a rotation and translation vector given a translation and radians

Returns
The from components.
Parameters
 translate Translate. rotate Rotate.
246  {
247  Matrix4 mat = Matrix4.Identity;
248  mat *= Matrix4.CreateRotationX(rotate.X);
249  mat *= Matrix4.CreateRotationY(rotate.Y);
250  mat *= Matrix4.CreateRotationZ(rotate.Z);
251  mat *= Matrix4.CreateTranslation(translate);
252  return mat;
253  }
 static Vector3 pluginbase.Helpers.Computative.VExt.Nlerp ( Vector3 a, Vector3 b, float blend )
static

Nlerp the specified a, b and blend.

Parameters
 a The alpha component. b The blue component. blend Blend.
35  {
36  return Vector3.Normalize( a * (1f - blend) + b * blend);
37  }
 static Vector3d pluginbase.Helpers.Computative.VExt.Nlerp ( Vector3d a, Vector3d b, double blend )
static

Nlerp the specified a, b and blend.

Parameters
 a The alpha component. b The blue component. blend Blend.
62  {
63  return Vector3d.Normalize( a * (1.0 - blend) + b * blend);
64  }
 static float pluginbase.Helpers.Computative.VExt.PointToLineDistance ( Vector3 line1, Vector3 line2, Vector3 point )
static

Get the distance between a point and a line

Returns
The to line distance.
Parameters
 line1 Line1. line2 Line2. point Point.
293  {
294  return Vector3.Cross(point - line1, point - line2).Length / (line2 - line1).Length;
295  }
float Length
Gets the length of the vector
Definition: Vector3i.cs:165
 static Vector2 pluginbase.Helpers.Computative.VExt.Project ( Vector3 pt, Matrix4 modelview, Matrix4 projection )
static

Project a 3d point to 2d given a modelview and projection

Parameters
 pt Point. modelview Modelview. projection Projection.
262  {
263  Vector4 vec = new Vector4(pt, 1f);
264  vec = Vector4.Transform(vec, modelview);
265  vec = Vector4.Transform(vec, projection);
266  vec.Xyz /= vec.W;
267  return new Vector2((vec.X + 1f) * 0.5f, (vec.Y + 1f) * 0.5f);
268  }
 static Vector2d pluginbase.Helpers.Computative.VExt.Project ( Vector3d pt, Matrix4d modelview, Matrix4d projection )
static

Project a 3D point to 2D point given modelview and projection

Parameters
 pt Point. modelview Modelview. projection Projection.
277  {
278  Vector4d vec = new Vector4d(pt, 1f);
279  vec = Vector4d.Transform(vec, modelview);
280  vec = Vector4d.Transform(vec, projection);
281  vec.Xyz /= vec.W;
282  return new Vector2d((vec.X + 1f) * 0.5f, (vec.Y + 1f) * 0.5f);
283  }
 static Matrix4 pluginbase.Helpers.Computative.VExt.Rotate ( Vector3 start, Vector3 end )
static

Create a rotation matrix to rotate a vector from a given start vector to a target vector

Parameters
 start Start. end End.
214  {
215  float dot = Vector3.Dot(start, end);
216  if (dot <= 0.999f)
217  {
218  Vector3 axis = Vector3.Normalize(Vector3.Cross(start, end));
219  float theta = (float)Math.Acos(dot);
220  return Matrix4.CreateFromAxisAngle(axis, theta);
221  }
222  return Matrix4.Identity;
223  }
 static Matrix4 pluginbase.Helpers.Computative.VExt.RotationMatrix ( Vector3 rot )
static

Create a rotation matrix given a vector to rotate given radians

Returns
The matrix.
Parameters
 rot Rot.
231  {
232  Matrix4 mat = Matrix4.Identity;
233  mat *= Matrix4.CreateRotationX(rot.X);
234  mat *= Matrix4.CreateRotationY(rot.Y);
235  mat *= Matrix4.CreateRotationZ(rot.Z);
236  return mat;
237  }
 static Vector3d pluginbase.Helpers.Computative.VExt.RotationVector ( double rotZ, double speed = `1.0` )
static

Get a rotation vector and a power

Returns
The vector.
Parameters
 rotZ Rot z. speed Speed.
354  {
355  return new Vector3d(Math.Sin(rotZ) * speed, Math.Cos(rotZ) * speed, 0.0);
356  }
 static float pluginbase.Helpers.Computative.VExt.RotationZ ( Vector3 lookDir )
static

Get the rotation value of the X and Y components of a matrix

Returns
The z.
Parameters
 lookDir Look dir.
313  {
314  return (float)Math.Atan2(lookDir.X, lookDir.Y);
315  }
 static float pluginbase.Helpers.Computative.VExt.RotationZ ( Vector2 lookDir )
static

Get the rotation given a 2D look direction

Returns
The z.
Parameters
 lookDir Look dir.
323  {
324  return (float)Math.Atan2(lookDir.X, lookDir.Y);
325  }
 static double pluginbase.Helpers.Computative.VExt.RotationZ ( Vector3d lookDir )
static

Get the Z rotation given a 3d look direction

Returns
The z.
Parameters
 lookDir Look dir.
333  {
334  return Math.Atan2(lookDir.X, lookDir.Y);
335  }
 static double pluginbase.Helpers.Computative.VExt.RotationZ ( Vector2d lookDir )
static

Get the Z rotation from a 2d vector

Returns
The z.
Parameters
 lookDir Look dir.
343  {
344  return Math.Atan2(lookDir.X, lookDir.Y);
345  }
 static Vector3 pluginbase.Helpers.Computative.VExt.Slerp ( Vector3 a, Vector3 b, float blend )
static

Slerp between two vectors

Parameters
 a The alpha component. b The blue component. blend Blend.
19  {
20  float dot = Vector3.Dot(a, b);
21  dot = MExt.Clamp(dot, -1f, 1f);
22  float theta = (float)Math.Acos(dot) * blend;
23  Vector3 rel = b - a * dot;
24  rel.Normalize();
25  return ((a * (float)Math.Cos(theta)) + rel * (float)Math.Sin(theta));
26  }
 static Vector3d pluginbase.Helpers.Computative.VExt.Slerp ( Vector3d a, Vector3d b, double blend )
static

Slerp the specified a, b and blend.

Parameters
 a The alpha component. b The blue component. blend Blend.
46  {
47  double dot = Vector3d.Dot(a, b);
48  dot = MExt.Clamp(dot, -1.0, 1.0);
49  double theta = Math.Acos(dot) * blend;
50  Vector3d rel = b - a * dot;
51  rel.Normalize();
52  return a * Math.Cos(theta) + rel * Math.Sin(theta);
53  }
 static Vector3 pluginbase.Helpers.Computative.VExt.SmartNlerp ( Vector3 a, Vector3 b, float blend, Vector3 defaultRotateVec )
static

NLerp that handles near-infinite scenario

Returns
The nlerp.
Parameters
 a The alpha component. b The blue component. blend Blend. defaultRotateVec Default rotate vec.
75  {
76  if (Vector3.Dot(a,b) < -0.99f)
77  {
78  a += defaultRotateVec * 0.01f;
79  }
80  var blended = a * (1f - blend) + b * blend;
81  if (blended == Vector3.Zero)
82  return Vector3.Zero;
83  return Vector3.Normalize(blended);
84  }
 static Vector3 pluginbase.Helpers.Computative.VExt.SmartNlerp ( Vector3 a, Vector3 b, float blend )
static

NLerp that hanles the near-infinite scenario

Returns
The nlerp.
Parameters
 a The alpha component. b The blue component. blend Blend.
94  {
95  return SmartNlerp(a, b, blend, Vector3.UnitX);
96  }
static Vector3 SmartNlerp(Vector3 a, Vector3 b, float blend, Vector3 defaultRotateVec)
NLerp that handles near-infinite scenario
Definition: VectorExtensions.cs:74
 static Vector3d pluginbase.Helpers.Computative.VExt.SmartNlerp ( Vector3d a, Vector3d b, double blend, Vector3d defaultRotateVec )
static

Smart nlerp that lerps a vector around a rotation vector

Returns
The nlerp.
Parameters
 a The alpha component. b The blue component. blend Blend. defaultRotateVec Default rotate vec.
107  {
108  if (Vector3d.Dot(a,b) < -0.999)
109  {
110  a += defaultRotateVec * 0.001;
111  }
112  Vector3d blended = a * (1.0 - blend) + b * blend;
113  if (blended == Vector3d.Zero)
114  return Vector3d.Zero;
115  return Vector3d.Normalize(blended);
116  }
 static Vector3d pluginbase.Helpers.Computative.VExt.SmartNlerp ( Vector3d a, Vector3d b, double blend )
static

NLerp that intelligently rotates one vector to another

Returns
The nlerp.
Parameters
 a The alpha component. b The blue component. blend Blend.
126  {
127  return SmartNlerp(a, b, blend, Vector3d.UnitX);
128  }
static Vector3 SmartNlerp(Vector3 a, Vector3 b, float blend, Vector3 defaultRotateVec)
NLerp that handles near-infinite scenario
Definition: VectorExtensions.cs:74
 static Vector3 pluginbase.Helpers.Computative.VExt.SwapXY ( this Vector3 v )
static

Swap X and Y components of a vector

Returns
The X.
Parameters
 v V.
303  {
304  return new Vector3(v.X, v.Z, v.Y);
305  }

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