0

The answer to Direct way of computing clockwise angle between 2 vectors was helpful in getting the clockwise angle between two vectors, but what I need to know is how to get the angle from two vectors going in the clockwise direction from a specific vector.

Here's a visual explanation of what I am trying to say. When going in the clockwise direction from the red vector, the clockwise angle is this: (Excuse the bad drawing)

enter image description here enter image description here

But when going in the clockwise direction from the black vector, the clockwise angle is this:

enter image description here enter image description here

EDIT: I'll rephrase my question. This is what I am trying to achieve. I have been following this old but useful link on generating triangle meshes: http://www.geom.uiuc.edu/~samuelp/del_project.html#algorithms

With the above images, I always want the angle going in a clockwise direction from a specific vector. I have been using the code from the linked SO answer to get the angle, but its incorrect in my situation

    float dotProd = vx*ux + vy*uy;
    float det = vx*uy - vy*ux;
    float angle = MathUtils.atan2(det, dotProd);//in radians
    if(angle < 0) angle += MathUtils.PI;

The angle calculation incorrectly allows unnecessary edges to be connected.

enter image description here

How can I fix this?

Community
  • 1
  • 1
Streak324
  • 153
  • 1
  • 3
  • 12
  • The code is correct. It finds angle in positive direction needed to rotate the first (V) vector to make it collinear with the second one (U). It is not clear how this approach is related to your triangulation problem. – MBo Apr 17 '16 at 17:34

2 Answers2

0

I'm sure there is a shorter way to do it, but if you know where you 0,0 is first do a check in which quarter your vector is and then perform the calculation accordingly.

it will solve your solution but mathematically I think you can get there faster.

Dani
  • 14,639
  • 11
  • 62
  • 110
0

I did these experiments:

int[] v1={5, 2}, v2={3, 4}, v3={5, 0};
double d1=v1[0]*v2[0]+v1[1]*v2[1], d2=v1[0]*v2[1]-v1[1]*v2[0];
System.out.println(Math.toDegrees(Math.atan2(d2, d1)));
d2=v2[0]*v1[1]-v2[1]*v1[0];
System.out.println(Math.toDegrees(Math.atan2(d2, d1)));
d1=v3[0]*v1[0]+v3[1]*v1[1]; d2=v3[0]*v1[1]-v3[1]*v1[0];
System.out.println(Math.toDegrees(Math.atan2(d2, d1)));
d1=v1[0]*v3[0]+v1[1]*v3[1]; d2=v1[0]*v3[1]-v1[1]*v3[0];
System.out.println(Math.toDegrees(Math.atan2(d2, d1)));
d1=v2[0]*v3[0]+v2[1]*v3[1]; d2=v3[0]*v2[1]-v3[1]*v2[0];
System.out.println(Math.toDegrees(Math.atan2(d2, d1)));

It seems the angle computed is the immediate angle: if it's positive the direction is counter clockwise (from v3 to v2 for example), if it is negative then it is clockwise.

I used standard java atan2 I dont know what you are using.

Therefore to get the clock wise always you have to check the result: if it is positive then subtract 360 degrees.

You have to do your own experiments to confirm this negative/positive.

gpasch
  • 2,672
  • 3
  • 10
  • 12