1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
namespace GtkGL {
using System;
public class Vector {
public double x, y, z;
public Vector(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public Vector(double[] v) {
if(v == null || v.Length < 3)
this.x = this.y = this.z = 0.0;
else{
this.x = v[0];
this.y = v[1];
this.z = v[2];
}
}
public static Vector Cross(Vector v1, Vector v2)
{
return new Vector( (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 static Vector operator +(Vector v1, Vector v2)
{
return new Vector(v1.x + v2.x,
v1.y + v2.y,
v1.z + v2.z
);
}
public static Vector operator *(Vector v1, double factor)
{
Vector result = new Vector( v1.x * factor,
v1.y * factor,
v1.z * factor
);
return result;
}
public static double Dot(Vector v1, Vector v2)
{
return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
}
}
}
|