Solved

Order of triangles's vertices

Posted on 2006-11-06
6
899 Views
Last Modified: 2013-12-06
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
Comment
Question by:Neoliten
  • 3
  • 3
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17887449
Is that clockwise when looking in the z direction?
0
 

Author Comment

by:Neoliten
ID: 17887473
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
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
ID: 17887489
Can you just swap a pair of vertices when v is negative?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Neoliten
ID: 17887500
I am trying...
However, which pair? Or swap until v become positive?
0
 
LVL 84

Expert Comment

by:ozo
ID: 17887549
It doesn't matter, swaping any pair will change the sign
0
 

Author Comment

by:Neoliten
ID: 17887570
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now