I have a triangle with 3 vertices,namely: (x1,y1,z1); (x2,y2,z2) and (x3,y3,z3).
I am using Bresenhams 3D Line algorithm,currently for generating 3D Points between two vertices of the triangle,depending on the resolution size(resSize).
void Bresenham3Algo(float x0, float y0, float z0, float x1, float y1, float z1)
{
float dx = Math.Abs(x1 - x0);
float sx = x0 < x1 ? resSize : -resSize;
float dy = Math.Abs(y1 - y0);
float sy = y0 < y1 ? resSize : -resSize;
float dz = Math.Abs(z1 - z0);
float sz = z0 < z1 ? resSize : -resSize;
float dm = Math.Max(dx, Math.Max(dy, dz)), i = dm;
x1 = y1 = z1 = dm / 2;
for (; ; )
{
Console.WriteLine(x0,y0,z0); //Printing points here
if (i <= 0) break;
x1 -= dx; if (x1 < 0) { x1 += dm; x0 += sx; }
y1 -= dy; if (y1 < 0) { y1 += dm; y0 += sy; }
z1 -= dz; if (z1 < 0) { z1 += dm; z0 += sz; }
i -= resSize;
}
}
So, As of now,I am calling the above function three times to generate 3D Sampling points on the boundary of the three Triangular edges.
Bresenham3Algo(x1,y1,z1,x2,y2,z2);
Bresenham3Algo(x2,y2,z2,x3,y3,z3);
Bresenham3Algo(x3,y3,z3,x1,y1,z1);
I am finding it difficult to find the internal sampling points lying inside the triangle.
For example,If I have the vertices (0,0,0); (5,0,0) and (3,3,0), With the help of the above function, I find 3D Points on the three triangular edges i.e.
(0,0,0),(1,0,0),(2,0,0),(3,0,0),(4,0,0),(5,0,0) -> first Edge
(3,3,0),(4,1,0),(4,2,0),(5,0,0) ->Second Edge
(0,0,0),(1,1,0),(2,2,0),(3,3,0) -> Third Edge
Now,I need to find the internal 3D Sampling points,lying inside the triangle i.e. (2,1,0) , (3,1,0), (3,2,0)
I would be glad,if someone can help me with this algo.
Thanks in Advance!