CAD programmer, in search of help!

Started by
3 comments, last by Talyrond 19 years, 1 month ago
This is a long shot guys!! Hi, I know this is a games forum but there is a certain amount of cross over between CAD and Games programming and to be honest there is just not a lot of info on the Web for us poor old CAD programmers! Any way, if anyone can help that would be great, my problem: I have a closed curve (not self intersecting) that is made up of a combination of Line segments and arcs, in the Cartesian plane. I need to know the direction of the closed curve: CW or CCW. I have found info on polygons, this uses the cross product etc to determine the direction. But I have no idea where to start when I introduce arc!! Any idears: Cheers Talyrond
Advertisement
Direction isn't an inherent property of a loop. Only when something is moving along the path defined by the loop does direction come into play, like in a circuit loop. Now if you're referring to the direction in which the loop is stored or rendered in CAD, then that's perfectly OK. What I would do is use the fact that there are 360° in a closed loop, and then iterate each piece of the loop. Start at the first piece. If the next piece turns "left" relative to the direction of the previous piece, then subtract that angle from your total. If it goes "right", then add that angle. Iterate all the pieces like that until you finish. In the end your sum should ideally be -360 (CCW) or +360 (CW), but in practice just checking if it's negative or positive will suffice. It also doesn't matter if your piece is a line or an arc, just use the start and end points to define a straight direction.
Zipster, appreciate you taking the time out to respond to my post

You are quite right, the context I am talking about is when moving along the path!
Now I just had a quick play on my CAD system and draw a loop and measured the angles. I think the loop only adds up to 360° if each arc is tangential to each other, does this sound right to you?
If you treat an arc like a straight line between its start and end point, then what I said should still hold true. Just remember to measure the turn angle from the current direction you were going in. So after you make a "turn", you either add or subtract the turn angle but you are now going in a new direction.
Thank you, I'll give that a try!

This topic is closed to new replies.

Advertisement