Reputation: 1613
I have this one triangle with arbitrary vertices positioned in a 3D space.
I have that finding the centroid of such triangle is easy by doing:
float centroid[3] = { 0, 0, 0 };
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
centroid[i] += points[j][i];
}
centroid[i] /= 3.0;
}
It's also easy to find the normal for it with something called plane equation:
crossProduct(points[1] - points[0], points[2] - points[0]);
There is a very simple method for moving the vertices away from the centroid, but that is too linear. I can only move the pointers back and forth.
What is the formula that I need to be able to freely move the vertices in a pseudo X/Y axis that is formed from the perspective of the triangle normal?
For reference, I'm using C++ and QT for the vectors and matrices. I'm rendering with basic OpenGL.
Upvotes: 0
Views: 68
Reputation: 80187
To build coordinate axes in triangle plane, you can use axis pseudoX
from centroid to any vertex and perpendicular axis pseudoY = pseudoX.cross.Normal
.
The choice of vertex as base vector seems rather natural. If you want to add some randomness, rotate this pseudoX
by arbitrary angle and generate new pseudoY
as cross product again.
Another method to generate vector in that plane - from normal only. Choose normal component with the largest magnitude, negate it and exchange with component with the second magnitude, make the smallest component zero. For example, if
|ny|>=|nz|>=|nx|
Vec = (0, nz, -ny)
note that Vec.dot.Normal = 0
, so Vec
lies in triangle plane
Upvotes: 1