Ask Your Question

Arrow Marker Orientation

asked 2018-08-16 05:27:55 -0500

th6262 gravatar image

updated 2018-08-16 05:29:57 -0500

Hey everyone,

I'm trying to publish an Arrow marker in the cluster center of extracted clusters. My goal is to set the orientation to the moving direction of the tracked cluster.

For this I'm able to utilize the X-Velocity and Y-Velocity (I also have access to the X and Y Position of the Point Origin)

Suppose for example the X-Velocity is 1 and the Y-Velocity is 0.5.

How do I set the POSE.ORIENTATION of the Arrow to point in a Direction that's parallel to the hypotenuse of this triangle (I do not want to change the length of the Arrow, just the direction)

Additionally I want it to point in the exact opposite direction if the velocity is negative (If the object is moving backwards, the arrow should point there too)

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-08-16 06:31:33 -0500

It would be much easier for you to use the start/end point method of specifying an arrow marker than the position orientation method.

You can normalize the velocity vector (divide each element by it's length) and add it to the current position to produce the end point. This way the arrow will always have a length of 1. You'll have to be careful and catch the case where it's velocity is zero since the end point will be a NAN. This arrow will always point in the velocity direction weather it's positive or negative.

Hope this helps.

edit flag offensive delete link more



Wow ! That was my first approach but I didn't think about normalizing the vectors! Duh. Of course!

Thanks again. Much appreciated

th6262 gravatar image th6262  ( 2018-08-16 06:35:04 -0500 )edit

Essentially works, however, by dividing the x-vel by itself I get a adjacent side length by 1. Then, by dividing the y-vel by the x-vel I get the correct ratio and the arrow points in the right direction. however the hypotenuse won't have length 1 then! Do you have any elegant solution for this ?

th6262 gravatar image th6262  ( 2018-08-17 04:39:03 -0500 )edit

I could calculate the euclidean distance between starting- and endpoint. this would be the length of the hypotenuse. However I can't simply divide this length by itself, because I'm not specifying the length, but the starting and endpoint, so this solution will get less and less elegant

th6262 gravatar image th6262  ( 2018-08-17 04:41:51 -0500 )edit

Calculate and store the magnitude of the velocity vector using sqrt(x'^2 + y'^2 + z'^2) Then divide each element of the vector sequentially by this stored magnitude. your velocity vector now has length 1. Use this velocity vector to find the arrows end point.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-08-17 06:53:57 -0500 )edit

perfect, thats the elegant solution I was missing :) ! thanks a ton

th6262 gravatar image th6262  ( 2018-08-17 09:02:20 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-08-16 05:27:55 -0500

Seen: 1,355 times

Last updated: Aug 16 '18