C ++ opengl: how to find normalized vectors for a quadrant?

Can someone help me find the right quadrant formula?

using C ++ with opengl.

Thank you!

+4
source share
2 answers

Assuming you need a normal vector for an ATV, this pseudo code works

Vector3d vertex[4] = { ... } Vector3d normal(0,0,0) ; for (int i=0; i<4; i++) { normal += cross (vertex[i], vertex[(i+1)%4]) ; // cross product } normalize (normal) ; // normal is the unit normal to the quad 

This gives the formula n=A/|A| , where A = v0xv1 + v1xv2 + v2xv3 + v3xv0 and vi=vertex[i] ). |A|/2 also the region of the polygon. This can be generalized to arbitrary polygons and even give reasonable results for non-planar polygons if they are not too flat.

One link http://softsurfer.com/Archive/algorithm_0101/algorithm_0101.htm

If you know that the square / polygon is flat, you only need to calculate the normal of the triangle formed by the first three vertices. This is A1/|A1| , where A1 = (v1-v0)x(v2-v0) = v0xv1 + v1xv2 + v2xv0 .

If using quad-normalization you mean something else, just ignore this answer.

EDIT: I found this related question: Get the surface area of ​​a polyhedron (3D object)

+6
source

The Newell method is usually your best bet for calculating the normals of polygons that are almost flat. It tends to be sufficiently resistant to minor disturbances, not too expensive. See the Graphics Gems article. It is similar to the one described above:

 Vector3d normal(0,0,0) ; for (int i=0; i<4; i++) { int j = (i+1)%4; normal.x += (vertex[i].y - vertex[j].y) *(vertex[i].z + vertex[j].z); normal.y += (vertex[i].z - vertex[j].z) *(vertex[i].x + vertex[j].x); normal.z += (vertex[i].x - vertex[j].x) *(vertex[i].y + vertex[j].y); } normalize (normal) ; 

This is probably not very important for ATVs if they behave reasonably well, but of course I would use it if you are dealing with more complex polygons.

+8
source

Source: https://habr.com/ru/post/1306079/


All Articles