[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 948
  • Last Modified:

Order of triangles's vertices

I plot some 3D functions and extract triangles, but some draw clockwise and other counter-clockwise so they are falsely colored (but all normal vector are directed to same direction)

For example, I use v=sign(x0*y1-x1*y0 + x1*y2-x2*y1 + x2*y0-x0*y2) to determine how triangle is shown:

(-0.422 -0.100 0.900)
(-0.400 -0.167 0.900)
(-0.400 -0.100 0.911)
0.001481 - clockwise

(-0.422 0.100 0.900)
(-0.400 0.167 0.900)
(-0.400 0.100 0.911)
-0.001481 - counterclockwise

I am looking for the method that will allow sorting of triangle vertices that they are all shown in right direction (counterclockwise for instance).

Thank you.
0
Neoliten
Asked:
Neoliten
  • 3
  • 3
1 Solution
 
ozoCommented:
Is that clockwise when looking in the z direction?
0
 
NeolitenAuthor Commented:
Actually it not directly visible. I see on the display that some triangles colored on front, but other colored on the back, however normals are pointer to the same direction, so all triangles should be colored on front.
I made calculations and I see that v=sign(... gives negative and positive results, which means that triangles drawn in clockwise/counterclockwise order. I am trying to sort vertices so they are all drawn in clockwise direction.
In this way coloring will depend on direction of normal vector.
0
 
ozoCommented:
Can you just swap a pair of vertices when v is negative?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
NeolitenAuthor Commented:
I am trying...
However, which pair? Or swap until v become positive?
0
 
ozoCommented:
It doesn't matter, swaping any pair will change the sign
0
 
NeolitenAuthor Commented:
Yes, works. Thank you.

However seems that I need to organize vertices according normal direction. For example, if I plot sphere, then one half colored on front and other half also on front (which is wrong, second half should be colored on back - inside the sphere).

I need sort of check, if normal points back, then color front (v < 0); if normal points front, then color back (v > 0). (just different checks for v, greater then 0 or less than 0)
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now