Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the Point and Vector3 geometry message if they're exactly the same?

Tags:

ros

I'm pretty new to ROS but I was manipulating a custom message that was made up of geometry_msgs/Point and geometry_msgs/Vector3 messages. When I printed out the message I noticed that both the Point and the Vector3 had the same 3 attributes (x, y, and z) and this made me curious because it seemed redundant... right?

Upon further digging in the source code, it turns out the Point and the Vector3 are exactly the same. They're both composed of a float x, float y, and a float z.

But after reading the docs, it seems like there IS a difference between these two messages. The docs mention that a Point should be used if the user wants to apply a translation whereas a Vector3 should be used to only represent a direction (and magnitude I guess?).

Since the two messages are defined exactly the same, I reckon if I could apply a translation to a Point I could also apply a translation to the Vector3. Is there a difference I'm not seeing between the Point and Vector3 that isn't their name?

like image 910
Dzhao Avatar asked Sep 10 '25 19:09

Dzhao


1 Answers

Even though Point and Vector3 have the same content, the tf2 library checks the type of message and acts on it differently, depending on whether it is a Point or a Vector3.

Ultimately, this was a decision made by the developer to highlight the conceptual distinction between a Point (a point in space which cannot be rotated), and a Vector3 (a direction which has no definite location in space but which can be rotated).

The developer did not have to make this distinction, and in fact many physics libraries use a single Vector3 datatype to handle directions, points, velocities, etc.

As with Colors (red, green, blue) and Dates (year, month, day) and many other things which can be represented as a Vector3, ultimately it comes down to the need to draw artificial distinctions to make the code easier to understand for users and other programmers.

like image 65
eiko Avatar answered Sep 13 '25 19:09

eiko