If you are just asking how to compute the extruded points of a triangle then the principle is as follows:
- all your triangles (ABC) must be oriented.
- compute a normal vector for the triangle. If the triangles are properly oriented, all normals will point towards the exterior. If they all point to interior, then just change ABC order into ACB for all your triangles.
- normalize this vector (not necessary but always a good idea)
- point
A' (extruded of
A) will be
A + normal, and same for
B' and
C'
The normal of a triangle can be obtained using cross product. Something like this:
struct Vector3
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
public Vector3() {}
public Vector3(Vector3 A, Vector3 B)
{
X = B.X - A.X;
Y = B.Y - A.Y;
Z = B.Z - A.Z;
}
public void Normalize()
{
float d = Math.Sqrt(X * X + Y * Y + Z * Z);
if (d == 0)
return;
X /= d;
Y /= d;
Z /= d;
}
static public Vector3 CrossProduct(Vector3 u, Vector3 v)
{
Vector3 w = new Vector3();
w.X = u.Y * v.Z - u.Z * v.Y;
w.Y = u.Z * v.X - u.X * v.Z;
w.Z = u.X * v.Y - u.Y * v.X;
return w;
}
}
struct Face
{
public Vector3 A { get; set; }
public Vector3 B { get; set; }
public Vector3 C { get; set; }
public Vector3 GetNormal()
{
Vector3 AB = new Vector3(A, B);
Vector3 AC = new Vector3(A, C);
Vector3 n = Vector3.CrossProduct(AB, AC);
n.Normalize();
return n;
}
}