mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-24 03:38:26 +00:00
+ Added some additional Vector operations
This commit is contained in:
parent
07c845bcbd
commit
8e5aa0a2f3
@ -72,6 +72,26 @@ namespace OSCADSharp
|
|||||||
return new Vector3(sum.X / positions.Length, sum.Y / positions.Length, sum.Z / positions.Length);
|
return new Vector3(sum.X / positions.Length, sum.Y / positions.Length, sum.Z / positions.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the unit vector for this vector
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Vector3 Normalize()
|
||||||
|
{
|
||||||
|
if(this.X == 0 && this.Y == 0 && this.Z == 0)
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
double sum = Math.Abs(this.X) + Math.Abs(this.Y) + Math.Abs(this.Z);
|
||||||
|
return new Vector3(this.X / sum, this.Y / sum, this.Z / sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Dot(Vector3 other)
|
||||||
|
{
|
||||||
|
return this.X * other.X + this.Y * other.Y + this.Z * other.Z;
|
||||||
|
}
|
||||||
|
|
||||||
#region Operators/Overrides
|
#region Operators/Overrides
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
@ -96,7 +116,7 @@ namespace OSCADSharp
|
|||||||
left.Y == right.Y &&
|
left.Y == right.Y &&
|
||||||
left.Z == right.Z);
|
left.Z == right.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 operator +(Vector3 left, Vector3 right)
|
public static Vector3 operator +(Vector3 left, Vector3 right)
|
||||||
{
|
{
|
||||||
return new Vector3(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
|
return new Vector3(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
|
||||||
@ -106,8 +126,23 @@ namespace OSCADSharp
|
|||||||
{
|
{
|
||||||
return new Vector3(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
|
return new Vector3(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator *(Vector3 left, Vector3 right)
|
||||||
|
{
|
||||||
|
return new Vector3(left.X * right.X, left.Y * right.Y, left.Z * right.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator *(Vector3 left, double right)
|
||||||
|
{
|
||||||
|
return new Vector3(left.X * right, left.Y * right, left.Z * right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator *(double left, Vector3 right)
|
||||||
|
{
|
||||||
|
return new Vector3(left * right.X, left * right.Y, left * right.Z);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
internal Matrix ToMatrix()
|
internal Matrix ToMatrix()
|
||||||
{
|
{
|
||||||
double[] coords = { this.X, this.Y, this.Z, 0 };
|
double[] coords = { this.X, this.Y, this.Z, 0 };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user