Skip to main content
GameDev.net gamedev.net
🔒 Locked

Quad question

Started by tendifo Aug 8, 2007 at 12:21 PM 3 replies 750+ views
Original Post
tendifo
tendifo
There are four vertices that are oriented in a CW rotation: A, B, C, and D. And there are two quads made from these vertices: A-B-C-D, and A-B-D-C (shown graphicaly below).
Quad 1:

A---B
|   |
D---C

Quad 2:

A---B
 \ /
  /
 / \   
D---C
How can I determine whether a given Quad follows the Quad 1 format or the Quad 2 format. In other words, how can I figure out if one side crosses over another in a Quad? Thanks.
Zakwayda
Zakwayda
A quick and easy way is to take the cross product of each successive pair of edges - (B-A)x(C-B) and so forth. If all the cross products point in the same direction (that is, if the dot product of the first cross product and each successive cross product is positive), you have 'quad 1', else you have 'quad 2'.

There was some discussion here recently on how to solve this (or perhaps a similar) problem most efficiently, but if efficiency isn't a concern I'd just go with the cross-product method.
mrcheesewheel
mrcheesewheel
Is this in 2D or in 3D? If you mean 3D, then what you want to know is are the vertices coplanar (as if they are not coplanar, an appropriate viewing angle would yield a quad looking like quad 2). If you mean 2D, you simply need to check if one vertex (eg vertex D) lies on the correct side of the other two edges (AB and BC). This can be done with simple vector maths and dot products. In 3D, you can effectively calculate the normal distance of D from the plane ABC (again, this is fairly simple mathematics). If you simply need to know if they are planar or not, you'll be able to work back through your maths to a point where you can determine the sign (+,- or 0) of the distance. In either case the mathematical formulation is quite simple and the resulting code will be quite quick. Remember to consider the implications of degenerate edges, and colinear points.
Hope you get it working,

Dan
Zakwayda
Zakwayda
Quote:
Original post by mrcheesewheel
Is this in 2D or in 3D? If you mean 3D, then what you want to know is are the vertices coplanar...
I could be wrong, but I don't think this is what the OP is asking about. I'm guessing (assuming this is a 3-d problem, which, as you note, the OP didn't specify) that the four vertices are assumed to be coplanar. The question is then simply one of proper winding (which can be determined using the cross-product method I described earlier).
tendifo
tendifo
I meant 3D. I like the cross product method.. seems rather elegant, actually. I'll give that a try. Thanks.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.