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

struct vertex3
{
double x, y, z;
vertex3();
vertex3(double x, double y, double z)
{
this>x = x, this>y = y, this>z = z;
}
};
double dotProduct(vertex3 a, vertex3 b)
{
return a.x*b.x + a.y*b.y + a.z*b.z;
}
vertex3 crossProduct(vertex3 a, vertex3 b)
{
vertex3 vector;
vector.x = (a.y*b.z)(b.y*a.z);
vector.y = (a.x*b.z)+(b.x*a.z);
vector.z = (a.x*b.y)(a.y*b.x);
return vector;
}
struct plane
{
vertex3 n; // a, b and c
double d;
// Define plane from three points (triangle)
plane(vertex3 a, vertex3 b, vertex3 c)
{
vertex3 u(b.x  a.x, b.y  a.y, b.z  a.z);
vertex3 v(c.x  a.x, c.y  a.y, c.z  a.z);
n = crossProduct(u, v);
d = dotProduct(n, a);
}
};
