using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bbiwarg.Utility
{
///
/// Class with represents a vector or a point in 3 dimensional space.
///
public class Vector3D
{
///
/// X (first) component
///
public float X { get; private set; }
///
/// Y (second) component
///
public float Y { get; private set; }
///
/// Z (third) component
///
public float Z { get; private set; }
///
/// X component as integer
///
public int IntX { get { return (int)X; } }
///
/// Y component as Integer
///
public int IntY { get { return (int)Y; } }
///
/// Z component as Integer
///
public int IntZ { get { return (int)Z; } }
///
/// length of the vector, computed with euclidean distance (2.Norm)
///
public float Length { get { return (float)Math.Sqrt(X * X + Y * Y + Z * Z); } }
///
/// Standard constructor which sets the 3 components
///
/// first component
/// second component
/// third component
public Vector3D(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
}
///
/// Computes the distance from the point this vector describes to another 3D point (vector).
/// the distance is the euclidean distance (2. Norm)
///
/// the other point
/// euclidean distance between this and point
public float getDistanceTo(Vector3D point)
{
return (this - point).Length;
}
///
/// multiplies this vector with a scalar value
///
/// the value
/// this vector
/// the multiplied vector
public static Vector3D operator *(float scalar, Vector3D v)
{
return new Vector3D(scalar * v.X, scalar * v.Y, scalar * v.Z);
}
///
/// multiplies this vector with a scalar value
///
/// this vector
/// the value
/// the multiplied vector
public static Vector3D operator *(Vector3D v, float scalar)
{
return new Vector3D(scalar * v.X, scalar * v.Y, scalar * v.Z);
}
///
/// divides this vector with a scalar value
///
/// this vector
/// the value
/// the divided vector
public static Vector3D operator /(Vector3D v, float scalar)
{
return new Vector3D(v.X / scalar, v.Y / scalar, v.Z / scalar);
}
///
/// divides on vector with another vector component-by-component
///
/// the dividend
/// the divisor
/// the component divided vector
public static Vector3D operator /(Vector3D v1, Vector3D v2)
{
return new Vector3D(v1.X / v2.X, v1.Y / v2.Y, v1.Z / v2.Z);
}
///
/// adds two vectors (component-by-component)
///
/// first addend
/// second addend
/// sum of the vectors
public static Vector3D operator +(Vector3D v1, Vector3D v2)
{
return new Vector3D(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z);
}
///
/// subtracts two vectors (component-by-component)
///
/// the minuend
/// the subtrahend
/// the difference of the two vectors
public static Vector3D operator -(Vector3D v1, Vector3D v2)
{
return new Vector3D(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);
}
}
}