[wpimath] Add 3D geometry classes (#4175)

Also clean up 2D geometry documentation.
This commit is contained in:
Tyler Veness
2022-05-06 08:41:23 -07:00
committed by GitHub
parent 708a4bc3bc
commit f20a20f3f1
48 changed files with 4299 additions and 255 deletions

View File

@@ -16,12 +16,12 @@ class json;
namespace frc {
/**
* Represents a translation in 2d space.
* Represents a translation in 2D space.
* This object can be used to represent a point or a vector.
*
* This assumes that you are using conventional mathematical axes.
* When the robot is placed on the origin, facing toward the X direction,
* moving forward increases the X, whereas moving to the left increases the Y.
* When the robot is at the origin facing in the positive X direction, forward
* is positive X and left is positive Y.
*/
class WPILIB_DLLEXPORT Translation2d {
public:
@@ -49,10 +49,9 @@ class WPILIB_DLLEXPORT Translation2d {
Translation2d(units::meter_t distance, const Rotation2d& angle);
/**
* Calculates the distance between two translations in 2d space.
* Calculates the distance between two translations in 2D space.
*
* This function uses the pythagorean theorem to calculate the distance.
* distance = std::sqrt((x2 - x1)^2 + (y2 - y1)^2)
* The distance between translations is defined as √((x₂x₁)²+(y₂y₁)²).
*
* @param other The translation to compute the distance to.
*
@@ -63,14 +62,14 @@ class WPILIB_DLLEXPORT Translation2d {
/**
* Returns the X component of the translation.
*
* @return The x component of the translation.
* @return The X component of the translation.
*/
units::meter_t X() const { return m_x; }
/**
* Returns the Y component of the translation.
*
* @return The y component of the translation.
* @return The Y component of the translation.
*/
units::meter_t Y() const { return m_y; }
@@ -82,16 +81,18 @@ class WPILIB_DLLEXPORT Translation2d {
units::meter_t Norm() const;
/**
* Applies a rotation to the translation in 2d space.
* Applies a rotation to the translation in 2D space.
*
* This multiplies the translation vector by a counterclockwise rotation
* matrix of the given angle.
*
* <pre>
* [x_new] [other.cos, -other.sin][x]
* [y_new] = [other.sin, other.cos][y]
* </pre>
*
* For example, rotating a Translation2d of {2, 0} by 90 degrees will return a
* Translation2d of {0, 2}.
* For example, rotating a Translation2d of &lt;2, 0&gt; by 90 degrees will
* return a Translation2d of &lt;0, 2&gt;.
*
* @param other The rotation to rotate the translation by.
*
@@ -100,11 +101,10 @@ class WPILIB_DLLEXPORT Translation2d {
Translation2d RotateBy(const Rotation2d& other) const;
/**
* Adds two translations in 2d space and returns the sum. This is similar to
* vector addition.
* Returns the sum of two translations in 2D space.
*
* For example, Translation2d{1.0, 2.5} + Translation2d{2.0, 5.5} =
* Translation2d{3.0, 8.0}
* For example, Translation3d{1.0, 2.5} + Translation3d{2.0, 5.5} =
* Translation3d{3.0, 8.0}.
*
* @param other The translation to add.
*
@@ -113,11 +113,10 @@ class WPILIB_DLLEXPORT Translation2d {
Translation2d operator+(const Translation2d& other) const;
/**
* Subtracts the other translation from the other translation and returns the
* difference.
* Returns the difference between two translations.
*
* For example, Translation2d{5.0, 4.0} - Translation2d{1.0, 2.0} =
* Translation2d{4.0, 2.0}
* Translation2d{4.0, 2.0}.
*
* @param other The translation to subtract.
*
@@ -127,17 +126,17 @@ class WPILIB_DLLEXPORT Translation2d {
/**
* Returns the inverse of the current translation. This is equivalent to
* rotating by 180 degrees, flipping the point over both axes, or simply
* negating both components of the translation.
* rotating by 180 degrees, flipping the point over both axes, or negating all
* components of the translation.
*
* @return The inverse of the current translation.
*/
Translation2d operator-() const;
/**
* Multiplies the translation by a scalar and returns the new translation.
* Returns the translation multiplied by a scalar.
*
* For example, Translation2d{2.0, 2.5} * 2 = Translation2d{4.0, 5.0}
* For example, Translation2d{2.0, 2.5} * 2 = Translation2d{4.0, 5.0}.
*
* @param scalar The scalar to multiply by.
*
@@ -146,9 +145,9 @@ class WPILIB_DLLEXPORT Translation2d {
Translation2d operator*(double scalar) const;
/**
* Divides the translation by a scalar and returns the new translation.
* Returns the translation divided by a scalar.
*
* For example, Translation2d{2.0, 2.5} / 2 = Translation2d{1.0, 1.25}
* For example, Translation2d{2.0, 2.5} / 2 = Translation2d{1.0, 1.25}.
*
* @param scalar The scalar to divide by.
*