Convert Figma logo to code with AI

strasdat logoSophus

C++ implementation of Lie Groups using Eigen.

2,007
588
2,007
6

Top Related Projects

4,517

Simple MPL-2.0-licensed C++ geometry processing library.

3,039

g2o: A General Framework for Graph Optimization

A large scale non-linear optimization library

2,544

GTSAM is a library of C++ classes that implement smoothing and mapping (SAM) in robotics and vision, using factor graphs and Bayes networks as the underlying computing paradigm rather than sparse matrices.

30,390

A library for efficient similarity search and clustering of dense vectors.

Quick Overview

The Sophus library is a C++ implementation of Lie groups, which are mathematical structures that describe the symmetries of geometric objects. It provides a set of classes and functions for working with various Lie groups, such as SE(2), SE(3), and SO(3), which are commonly used in robotics, computer vision, and other fields.

Pros

  • Efficient and Optimized: The Sophus library is designed to be efficient and optimized for performance, making it suitable for real-time applications.
  • Comprehensive Functionality: The library provides a wide range of functionality for working with Lie groups, including operations such as composition, inversion, and interpolation.
  • Flexible and Extensible: The library is designed to be flexible and extensible, allowing users to easily add support for new Lie groups or customize existing ones.
  • Well-Documented: The Sophus library is well-documented, with detailed documentation and examples available on the project's GitHub repository.

Cons

  • Limited Language Support: The Sophus library is primarily written in C++, which may limit its accessibility for developers who prefer other programming languages.
  • Steep Learning Curve: Working with Lie groups can be a complex and challenging topic, and the Sophus library may have a steep learning curve for developers who are new to this field.
  • Dependency on Eigen: The Sophus library is heavily dependent on the Eigen library, which may be a limitation for developers who prefer to use other linear algebra libraries.
  • Limited Community Support: The Sophus library is not as widely used as some other libraries in the robotics and computer vision communities, which may limit the availability of community support and resources.

Code Examples

Here are a few examples of how to use the Sophus library:

  1. Creating a SE(3) transformation:
#include <Sophus/SE3.hpp>

Sophus::SE3d T_aw(Eigen::Vector3d(1.0, 2.0, 3.0), Eigen::Quaterniond(0.5, 0.5, 0.5, 0.5));

This code creates a SE(3) transformation T_aw with a translation of (1.0, 2.0, 3.0) and a rotation represented by a quaternion (0.5, 0.5, 0.5, 0.5).

  1. Composing two SE(3) transformations:
#include <Sophus/SE3.hpp>

Sophus::SE3d T_aw(Eigen::Vector3d(1.0, 2.0, 3.0), Eigen::Quaterniond(0.5, 0.5, 0.5, 0.5));
Sophus::SE3d T_wb(Eigen::Vector3d(4.0, 5.0, 6.0), Eigen::Quaterniond(0.6, 0.6, 0.4, 0.4));
Sophus::SE3d T_ab = T_aw * T_wb;

This code composes two SE(3) transformations T_aw and T_wb to obtain a new transformation T_ab.

  1. Interpolating between two SO(3) rotations:
#include <Sophus/SO3.hpp>

Sophus::SO3d R_a(Eigen::Quaterniond(0.5, 0.5, 0.5, 0.5));
Sophus::SO3d R_b(Eigen::Quaterniond(0.6, 0.6, 0.4, 0.4));
double t = 0.5;
Sophus::SO3d R_interp = Sophus::SO3d::slerp(t, R_a, R_b);

This code interpolates between two SO(3) rotations R_a and R_b using spherical linear interpolation (slerp) to obtain a new rotation R_interp at the midpoint (t = 0.5) between the two.

Getting Started

To get started with the

Competitor Comparisons

4,517

Simple MPL-2.0-licensed C++ geometry processing library.

Pros of libigl

  • Broader scope: Focuses on geometry processing and offers a wide range of algorithms and tools
  • Extensive documentation and tutorials, making it easier for newcomers to get started
  • Large and active community, resulting in frequent updates and contributions

Cons of libigl

  • Larger codebase and dependencies, potentially leading to longer compilation times
  • Steeper learning curve due to its extensive feature set
  • May include unnecessary functionality for projects focused solely on Lie groups and transformations

Code Comparison

Sophus (matrix logarithm):

Eigen::Matrix3d R = SO3d::exp(phi).matrix();
Vector3d phi = SO3d::log(SO3d(R));

libigl (mesh smoothing):

#include <igl/cotmatrix.h>
#include <igl/massmatrix.h>
Eigen::SparseMatrix<double> L, M;
igl::cotmatrix(V, F, L);
igl::massmatrix(V, F, igl::MASSMATRIX_TYPE_BARYCENTRIC, M);

Both libraries utilize Eigen for matrix operations, but Sophus focuses on Lie group transformations, while libigl provides a broader set of geometry processing tools.

3,039

g2o: A General Framework for Graph Optimization

Pros of g2o

  • More comprehensive graph optimization framework, suitable for a wide range of SLAM and optimization problems
  • Supports various sensor types and constraints, making it versatile for different robotics applications
  • Larger community and more frequent updates, potentially leading to better support and bug fixes

Cons of g2o

  • Steeper learning curve due to its complexity and broader scope
  • Heavier and more resource-intensive, which may not be ideal for lightweight or embedded systems
  • Requires more setup and configuration for specific use cases

Code Comparison

g2o example (vertex addition):

g2o::VertexSE3* v = new g2o::VertexSE3();
v->setEstimate(Eigen::Isometry3d::Identity());
v->setId(0);
optimizer.addVertex(v);

Sophus example (SE3 transformation):

Sophus::SE3d pose = Sophus::SE3d::exp(se3);
Eigen::Matrix4d T = pose.matrix();

g2o is more focused on graph construction and optimization, while Sophus provides a cleaner interface for Lie group operations. g2o is better suited for large-scale SLAM problems, whereas Sophus excels in efficient and precise geometric computations.

A large scale non-linear optimization library

Pros of Ceres Solver

  • More comprehensive and feature-rich optimization library
  • Supports a wider range of problem types and solvers
  • Better documentation and extensive examples

Cons of Ceres Solver

  • Larger and more complex codebase
  • Steeper learning curve for beginners
  • May be overkill for simpler optimization problems

Code Comparison

Sophus (Lie group operations):

Sophus::SE3d pose = Sophus::SE3d::exp(se3);
Sophus::SE3d new_pose = pose * Sophus::SE3d::exp(delta);

Ceres Solver (optimization problem setup):

ceres::Problem problem;
ceres::CostFunction* cost_function = new AutoDiffCostFunction<CostFunctor, 1, 1>(new CostFunctor);
problem.AddResidualBlock(cost_function, nullptr, &x);
ceres::Solver::Options options;
ceres::Solver::Summary summary;
Solve(options, &problem, &summary);

Sophus focuses on Lie group operations and transformations, while Ceres Solver is a more general-purpose optimization library. Sophus is lightweight and specialized, making it easier to use for specific geometric computations. Ceres Solver offers more flexibility and power for complex optimization problems but requires more setup and understanding of optimization concepts.

2,544

GTSAM is a library of C++ classes that implement smoothing and mapping (SAM) in robotics and vision, using factor graphs and Bayes networks as the underlying computing paradigm rather than sparse matrices.

Pros of GTSAM

  • More comprehensive library with a wider range of functionality for robotics and computer vision applications
  • Supports factor graphs and nonlinear optimization, enabling complex SLAM and sensor fusion tasks
  • Extensive documentation and examples, making it easier for new users to get started

Cons of GTSAM

  • Steeper learning curve due to its broader scope and more complex architecture
  • Potentially higher computational overhead for simpler tasks that don't require its full feature set

Code Comparison

GTSAM example (pose composition):

#include <gtsam/geometry/Pose3.h>

gtsam::Pose3 pose1 = gtsam::Pose3(gtsam::Rot3::RzRyRx(0.1, 0.2, 0.3), gtsam::Point3(1, 2, 3));
gtsam::Pose3 pose2 = gtsam::Pose3(gtsam::Rot3::RzRyRx(0.4, 0.5, 0.6), gtsam::Point3(4, 5, 6));
gtsam::Pose3 composed = pose1.compose(pose2);

Sophus example (pose composition):

#include <sophus/se3.hpp>

Sophus::SE3d pose1 = Sophus::SE3d::rotX(0.1) * Sophus::SE3d::rotY(0.2) * Sophus::SE3d::rotZ(0.3) * Sophus::SE3d::trans(1, 2, 3);
Sophus::SE3d pose2 = Sophus::SE3d::rotX(0.4) * Sophus::SE3d::rotY(0.5) * Sophus::SE3d::rotZ(0.6) * Sophus::SE3d::trans(4, 5, 6);
Sophus::SE3d composed = pose1 * pose2;
30,390

A library for efficient similarity search and clustering of dense vectors.

Pros of Faiss

  • Highly optimized for large-scale similarity search and clustering
  • Supports GPU acceleration for faster processing
  • Extensive documentation and examples for various use cases

Cons of Faiss

  • Steeper learning curve due to its complexity and wide range of features
  • Primarily focused on vector similarity search, less versatile for general-purpose applications

Code Comparison

Sophus (Lie group operations):

Sophus::SE3d pose = Sophus::SE3d::exp(se3);
Sophus::SE3d new_pose = pose * Sophus::SE3d::exp(delta);

Faiss (Vector similarity search):

faiss::IndexFlatL2 index(d);
index.add(n, xb);
index.search(nq, xq, k, distances, labels);

Summary

Sophus is a C++ library for Lie groups, focusing on geometric computations in robotics and computer vision. Faiss, developed by Facebook Research, specializes in efficient similarity search and clustering of dense vectors.

While Sophus excels in handling 3D transformations and rotations, Faiss is optimized for high-dimensional vector operations and nearest neighbor search. Sophus offers a more intuitive API for geometric operations, whereas Faiss provides powerful tools for large-scale similarity search with GPU support.

Choose Sophus for projects involving 3D geometry and pose estimation, and Faiss for applications requiring fast similarity search on large datasets, such as recommendation systems or image retrieval.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Sophus

2d and 3d Lie Groups for Computer Vision and Robotics

This is a c++ implementation of Lie groups commonly used for 2d and 3d geometric problems (i.e. for Computer Vision or Robotics applications). Among others, this package includes the special orthogonal groups SO(2) and SO(3) to present rotations in 2d and 3d as well as the special Euclidean group SE(2) and SE(3) to represent isometries also known as rigid body transformations (i.e. rotations and translations) in 2d and 3d.

Status

Sophus (aka Sophus 1) is in maintenance mode. As of June 2024, there is no plane to add new larger features and future PRs will likely be limited to bug fixes, small improvements and toolchain updates.

However, next incarnations of Sophus are under development:

  • sophus2 is the next c++ iteration of Sophus and is a complete rewrite. In addition to the Lie groups, it includes a more geometric concepts such unit vector, splines, image classes, camera models and more.

    It is currently hosted as part of the farm-ng-core repository and has likely only a few community users. While the code itself is in a good shape, there are no good build instructions yet. Hopefully, this will change in the near future.

  • sophus-rs is a Rust version of Sophus. Similar to sophus2, it includes a more geometric concepts such unit vector, splines, image classes, camera models and more. Also it includes an early and experimental version of non-linear least squares optimization library (similar to Ceres, g2o, etc.).

    sophus-rs has likely only a few community users so far, but should be easy to build and experiment with - of course being written in Rust.

    https://github.com/sophus-vision/sophus-rs

    https://crates.io/crates/sophus

How to build Sophus from source

Sophus requires a C++17 compiler (though older versions build with C++14).

Sophus is tested on Linux and macOS. It also worked on Windows in the past, however there is currently no CI for Windows, so it might require some smaller patches to build on Windows.

There are no comprehensive build instructions but inspecting the install scripts as well as the main.yml file should give you a good idea how to build the required dependencies.

Installing Sophus through vcpkg

You can build and install Sophus using vcpkg dependency manager::

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install sophus

The Sophus port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.