Skip to content

Instantly share code, notes, and snippets.

@Vftdan
Last active April 12, 2017 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vftdan/97776e4a56585b3b23437ceb00b41f46 to your computer and use it in GitHub Desktop.
Save Vftdan/97776e4a56585b3b23437ceb00b41f46 to your computer and use it in GitHub Desktop.
struct Vec3
{
public double x, y, z;
public Vec3(double x_, double y_, double z_)
{
x = x_;
y = y_;
z = z_;
}
public static Vec3 operator +(Vec3 v1, Vec3 v2){
return new Vec3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
}
public static Vec3 operator -(Vec3 v1, Vec3 v2)
{
return new Vec3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
}
public static Vec3 operator *(Vec3 v, double f)
{
return new Vec3(v.x * f, v.y * f, v.z * f);
}
public static Vec3 operator /(Vec3 v, double f)
{
return v * (1 / f);
}
public static double operator %(Vec3 v1, Vec3 v2)
{
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}
public static Vec3 operator ^(Vec3 v1, Vec3 v2)
{
return new Vec3(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x);
}
public double len()
{
return Math.Sqrt(this % this);
}
public static Vec3 operator !(Vec3 v)
{
return v / v.len();
}
public override string ToString()
{
return String.Format("{0}{1}, {2}, {3}{4}", "{", x, y, z, "}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment