Skip to content

Software

tf2_2d

By Locus Robotics, United States (checked on github.com/locusrobotics (opens in a new tab)), from github.com/locusrobotics/tf2_2d (opens in a new tab)

  • Navigation and mapping
  • Library
  • BSD-3-Clause

A C++ library of 2D geometry classes (vectors, rotations, transforms) modeled on tf2's 3D classes, with conversion to and from tf2 message types.

Facts

GitHub stars
11read on 22 Nov 2026
Last update
4 Nov 2026Newest commit on devel
Maintenance
Activea commit in the last 90 days
Difficulty
Intermediate

Checked on GitHub on 22 Nov 2026.

Licenses

Code
BSD-3-Clause (opens in a new tab)

Read by Robotheca from LICENSE (opens in a new tab) (BSD-3-Clause) at commit 2b425aa (opens in a new tab), on 6 Nov 2026.

Commercial use
Yes

At a glance

What it is
  • Provides 2D Vector2, Rotation and Transform types that mirror the 3D geometry classes in tf2.
  • Supplies fromMsg() and toMsg() conversions between the 2D types and tf2 messages, including Stamped variants.
  • Implements the usual transformation math, such as adding vectors, rotating vectors and multiplying transforms.
  • Keeps every Rotation angle wrapped to the range (-Pi, Pi], so arithmetic on angles needs no manual wrapping.
  • Caches sine and cosine values in Rotation objects, so repeated rotations avoid recomputing trig functions and the cache carries over to copies and inverses.

Robotheca's summary of the project's documents, not the creator's words.

Robots on Robotheca
No robot on Robotheca uses it yet.
Licence
BSD-3-Clause. Commercial use: Yes. Where it was read
Install
In the creator's words: The project's README (opens in a new tab)
Maintenance
Active, last commit on 4 Nov 2026.

Use it

How to install it, in the creator's words: The project's README (opens in a new tab)

Robotheca doesn't review code. Read it before running it.

Files and versions

Facts read at commit 2b425aa

Robotheca read the repository at two versions: the summary at a4231c8 and the facts and the README at 2b425aa (read on 22 Nov 2026).

Robotheca never hosts the code: each link goes to the creator's own page.

The README

The creator's own README, copied as written: README.md by Locus Robotics, at commit 2b425aa, under BSD-3-Clause (opens in a new tab). The original on GitHub (opens in a new tab).

Read the README here

tf2_2d

A set of 2D geometry classes modeled after the 3D geometry classes in tf2.

Using tf2 toMsg() and fromMsg()

I've tried to include fromMsg() implementations for anything that remotely makes sense. The tf2 toMsg() signature does limit its use to a single output type, so I've had to make a guess as to the most useful variation there.

For example:

#include <tf2_2d/tf2_2d.h>     // This header includes the tf2 conversion functions
#include <tf2_2d/transform.h>  // Then include what you use

// Convert a tf2_2d object into a 3D message
auto transform_2d = tf2_2d::Transform(1.0, 1.5, 2.0);
geometry_msgs::Transform transform_3d_msg = tf2::toMsg(transform_2d);

// Convert a 3D message into a 2D tf2_2d object
geometry_msgs::Transform transform_3d_msg;
tf2_2d::Transform transform_2d;
tf2::fromMsg(transform_3d_msg, transform_2d);

// You can do Stamped<> things as well
auto transform_2d = tf2::Stamped<tf2_2d::Transform>(tf2_2d::Transform(1.0, 1.5, 2.0), ros::Time(1.2), "frame");
geometry_msgs::TransformStamped transform_3d_msg = tf2::toMsg(transform_2d);

Conversion of Points and Quaternions are also supported, as are conversions to other datatypes that are handled by tf2's conversion system.

Transformation math

The tf2_2d types also implement all of the expected transformation math.

auto v1 = tf2_2d::Vector2(1.0, 2.0);
auto v2 = tf2_2d::Vector2(1.5, 2.5);
auto v3 = v1 + v2;                             // v3 == (2.5, 4.5)

tf2_2d::Rotation r1(M_PI);
auto v4 = r1.rotate(v1);                       // v4 == (-2.0, 1.0)

auto t1 = tf2_2d::Transform(1.0, 2.0, 3.0);
auto t2 = tf2_2d::Transform(-2.0, -1.0, -1.5);
auto t3 = t1 * t2;                             // t3 == (3.12, 2.70, 1.5)

auto t4 = tf2_2d::Transform(1.0, 2.0, 3.0);
auto t5 = tf2_2d::Transform(-2.0, -1.0, -1.5);
auto t6 = t4.inverseTimes(t5);                 // t6 == (2.54, 3.39, 1.78)

The tf2_2d::Rotation class deserves a few additional notes. The angle stored in a Rotation object is always within the (-Pi, Pi] range. You can construct a Rotation object with any floating point value, but it will be wrapped to that range. You can also perform arithmetic with the angles, without worrying about wrapping issues.

tf2_2d::Rotation r1(1.0);
auto r2 = 17.0 * r1;       // r2.angle() == -1.84956

tf2_2d::Rotation r3(1.0);
tf2_2d::Rotation r4(3.0);
auto r5 = r3 + r4;         // r5.angle() == -2.28319

tf2_2d::Rotation r6(-3.0);
tf2_2d::Rotation r7(1.0);
auto r8 = r6 - r7;         // r8.angle() == 2.28319

Additionally, the tf2_td::Rotation class caches the sin/cos results needed to perform rotations. So, once a Rotation object is used to rotate something, the trig functions will never be evaluated again. And the cached sin/cos values will propagate to any derived objects that it can. This includes the Rotation object built into a Transform.

tf2_2d::Vector2 v1(1.0, 2.0);
tf2_2d::Rotation r1(1.0);            // No sin/cos calls have been made, since it is not needed yet
auto v2 = r1.rotate(v1);             // Computes sin/cos and remembers it
auto v3 = r1.unrotate(v2);           // Does not need to compute sin/cos again
tf2_2d::Rotation r2 = r1;            // Transfers sin/cos to r2
auto v4 = r2.rotate(v1);             // Does not need to compute sin/cos because it stole the cached values from r1
tf2_2d::Rotation r3 = r1.inverse();  // Inverts and transfers sin/cos to r3
auto v5 = r3.rotate(v1);             // Does not need to compute sin/cos because it stole the cached values from r1

Robotheca lists software as a reference: nothing is hosted or run here, and every fact links to where it was read.