[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

determining if 3 points are stored in cw or ccw

Posted on 2005-05-06
6
Medium Priority
?
517 Views
Last Modified: 2008-01-09
Hi Experts.

I have a little problem. I have 3 points (p1, p2, and p3). i need to know if p1-p2-p3 is stored in clockwise or counterclockwise order.
these points are just 2d, so this should be pretty easy

Thanks in advance
0
Comment
Question by:Tai-San
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:nonubik
ID: 13943650
You need to compute the cross product of the p2p1 and p2pr vectors. If it is oriented like Z axiz (pozitive value) it's cw. If it is opposed to Z axis (negative value) it's ccw.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13943656
'p2pr' should be read as'p2p3'
0
 
LVL 2

Author Comment

by:Tai-San
ID: 13943670
float somefloat = Vector_Cross(Vector_Sub(p2, p1), Vector_Sub(p2, p3));
^ is this what you mean, valid
and i check it by:

if (somefloat >= 0)
{
    //cw
}
else
{
    //ccw
}

did i understand this correctly?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 16

Expert Comment

by:nonubik
ID: 13943685
Techincaly a cross product between to vecros produce also a vector. The 'somfloat' should be it's norm.
0
 
LVL 2

Author Comment

by:Tai-San
ID: 13943692
VECTOR3D_T tResult = Vector_Cross(Vector_Sub(p2, p1), Vector_Sub(p2, p3)); //p1, p2, and p3 must be 3d i suppose. just zero-out Y

//how do i check it then?
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 200 total points
ID: 13944875
Having three points p0, p1 and p2 calculate:

(p1 - p0) × (p2 - p0) = (x1 - x0)(y2 - y0) - (x2 - x0)(y1 - y0).

If this cross product is positive, then vector p0p1 is clockwise from vector p0p2; if negative, it is counterclockwise.

Positive:

         p2
p0    
         p1

Negative:

          p1
p0
          p2
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

834 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