Gilles avatar image
Gilles asked Gilles commented

angle between two vectors with sign

queue-orientation.pnghello team,

I have two vectors, the first vector is the direction of a conveyor (direction). the second vector is the orientation of a queue (orientation). I would like to rotate the queue so that its orientation is aligned with the direction of the conveyor.

to get the angle between the two vectors, I do: angle = orientation.angle(direction).

then to rotate the queue in order to align its orientation, I do : obj.setRotation(0,0,angle );

as you can see on the image above, it does not work in all scenarios. what I found is, if I do angle = direction.angle(orientation), I get the same result as angle = orientation.angle(direction). so it does not capture sign of the angle, in other words, it does not capture the information if I am in clock direction or counter clock direction.

I will appreciate a help with this.


FlexSim 23.1.0
queue-orientation.png (123.7 KiB)
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Joerg Vogel avatar image Joerg Vogel commented ·
@Gilles , what if you do a projection of an moved item on a conveyor to gather your data to get angle of alignment. A conveyor is defined by start position to end position. It is not a typical location, rotation and size matrix like other objects. But an item owns this data again.
0 Likes 0 ·
Gilles avatar image Gilles Joerg Vogel commented ·
hi Joerg,

what you explained is not the problem I am trying to solve. I am not worried about an item moving on a conveyor.

I am creating a 3d model, using a code. creating object and placing them in the right location and rotate them if necessary. As I explained, when I place a queue, as you can see on the image, I want to rotate that queue so that it has the same orientation with the divert. in some cases it works and in some it does not work. because I don't know how to get if the angle is in the clock direction or is counter clock direction.

Is there any command which can provide angle between two vectors with the angle direction?

0 Likes 0 ·

1 Answer

Joerg Vogel avatar image
Joerg Vogel answered Gilles commented

Here is an example to get rotation values in a range of ]-180 .. 0 .. +180[



Vec3 Vec3test = Vec3(0,0,0).projectRotation(variable,model()); //variable = object
double ang = Vec3test.z;

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Gilles avatar image Gilles commented ·
perfect! this is exactly what I was looking for.

Thank you!

0 Likes 0 ·