Check vector direction

Hi,
I have two vectors, how I can check that vectors same direction as the hands of an analogue clock

Thanks

image

hey

you can substract them and check if the result is zero. if is, they are parallel.

V(1,0,0) - V(1,0,0) = 0,0,0 parallel (same direction)
V(1,0,0) - V(0,1,0) = 1,-1,0 not parallel (not same direction)

or with this method:
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Vector3d_IsParallelTo.htm

hope that helps

B

Hi @benedict ,

How I can check the angle of that vectors is follow clockwise

Thanks

I’m not sure to understand your question. you mean an angle between the two vectors that should be smaller than 180°?

Hi @benedict
Please see picture below

image

you could cross product 2 vectors, then check the reslt direction

Another way is to measure the angles of the vectors against whatever 12:00/24:00 is:


211026_ClockAngles_00.gh (13.0 KB)

2 Likes

to have a clockwise or counterclockwise direction you need a plane, else its several transformations, which cannot be simplified to a simple rotation direction. also you need to know in which quadrant you are, as conditions repeat themselves, when just comparing the vectors.

however, in a simple xy plane the conditions to check the direction would be the following:

clockwise
V0 V1 crossproduct quadrant
1,0,0 0,1,0 V0.x>V1.x V0.y<V1.y 1,1,0 1
0,1,0 -1,0,0 V0.x>V1.x V0.y<V1.y -1,1,0 4
-1,0,0 0,-1,0 V0.x<V1.x V0.y>V1.y -1,-1,0 3
0,-1,0 1,0,0 V0.x<V1.x V0.y<V1.y 1,-1,0 2
counterclockwise
V0 V1
1,0,0 0,-1,0 V0.x>V1.x V0.y<V1.y 1,-1,0 2
0,-1,0 -1,0,0 V0.x>V1.x V0.y<V1.y -1,-1,0 3
-1,0,0 0,1,0 V0.x<V1.x V0.y<V1.y -1,1,0 4
0,1,0 1,0,0 V0.x<V1.x V0.y>V1.y 1,1,0 1

:

here you go with the example: please note that its working on xy plane only and ignores 180°, as it can be considered none of both conditions.

Vectoranalysis.gh (10.2 KB)

oh, bugger, I got the quadrants wrong numbered…

@AndersDeleuran 's solution looks way easier though:) nice one!

2 Likes

Based on your drawing:
The blue and the red vectors always have the same direction.
And how do you want to know the orientation (clockwise or counterclockwise) of a vector? you need a reference

image

The angle have no relation with the orientation.

image

I think you need to post the real example or the real idea and what you want exactly

1 Like

I think you confuse something here, the red and blue vector do not have the same direction in your drawing and are compared to each other. having the first one as a reference, you can easily determine whether its rotating clockwise or counter clockwise. With @AndersDeleuran 's method you’d repeat the process with both vectors and check if the references vectors angle is bigger than the references angle or smaller.

How do you know if the blue axis orientation is clockwise or counterclockwise?
We have two possibilities here

image

I guess counterclockwise in this case, as alpha is smaller than beta. at least that’s what I understood from his question. given that just getting the angle of the two vectors with the default ‘vector angle’ node gives you the smaller angle, otherwise it would be the reflex angle
"

but I can see your point from math’s point of view
:

We can’t know even Grasshopper without reference can’t know , that why we have Angle and Reflex in this component

image

It’s like : is this circle orientation clockwise or counterclockwise?!

image

https://www.mathsisfun.com/reflex.html

reflex is always the larger angle. I think he’s looking for the shortest angle TRANSFORMATION.

looking at my example above, you can see the 90° angle between the vectors in both cases, but it’s not clear when referencing to the first vector (the one you want to transform) which of the two angles (angle or reflex) is needed to get the new vector.
in counterclockwise case, you’d use the acute angle to transform, while in clockwise you’d use the reflex angle to transform.

angles for transformations do have a direction and are counter clockwise.

1 Like