Hi,
I have two vectors, how I can check that vectors same direction as the hands of an analogue clock
Thanks
Hi,
I have two vectors, how I can check that vectors same direction as the hands of an analogue clock
Thanks
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
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
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:
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!
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
The angle have no relation with the orientation.
I think you need to post the real example or the real idea and what you want exactly
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
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
Itâs like : is this circle orientation clockwise or counterclockwise?!
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.
@AndersDeleuran @anon39580149 @nguyentheta2002
finally, because I know youâre interested in that kind of stuff and I learned this today which made me think of this thread:
the direction of the second vector in relation from the first vector of two vectors is quite important to know for algorithms like hull ( I think grahamâs, but not sure at all). itâs very simple to calculate by using the crossproduct of two vectors:
public Vector3d xProduct(Vector3d u, Vector3d v)
{
double cx = (u.Y * v.Z) - (u.Z * v.Y);
double cy = (u.Z * v.X) - (u.X * v.Z);
double cz = (u.X * v.Y) - (u.Y * v.X);
Vector3d xVector = new Vector3d(cx, cy, cz);
return xVector;
}
the same thing can be done by using
Vector3d.Crossproduct(u,v);
if the result (of the crossvectors Z value) is positive, it is clockwise. if itâs negative its counterclockwise and if itâs zerolength, itâs straight.
by consequence, a polyline defined by three points can be analysed if relative from the first line it makes a right or left turn to the third point. the vectors are created and translated to center to repeat get the crossproduct:
public string direction(Point3d A, Point3d B, Point3d C)
{
string sOut = ânullcheckâ;
Vector3d u = new Vector3d(B - A);
Vector3d v = new Vector3d(C - B);
Vector3d uxv = xProduct(u, v);
if(Math.Round(uxv.Z, 4) < 0) sOut = ârightâ;
if(Math.Round(uxv.Z, 4) == 0) sOut = âstraightâ;
if(Math.Round(uxv.Z, 4) > 0) sOut = âleftâ;
return sOut;
}
given the points are in xy plane.
the references and proof as well as more acurate information on the topic can be found here:
cheers and happy new year
Ben