namespace geom

Overview

Set of structures for geometry and linear algebra. More…

namespace geom {

// namespaces

namespace geom::quadrics;

// typedefs

typedef Line<2> Line2;
typedef Line<3> Line3;
typedef Ray<2> Ray2;
typedef Ray<3> Ray3;
typedef TSphere<2, float> Circle;
typedef TSphere<3, float> Sphere;
typedef TRect<float> Rect;
typedef TRect<int> IRect;
typedef TRect<unsigned> URect;
typedef TAabb<2, float> Aabb2;
typedef TAabb<3, float> Aabb3;

// enums

enum Axis;

// structs

struct Capsule;
struct CollisionResult;
struct ConicalCapsule;
struct Graph;
struct HalfPlane;

template <size_t N>
struct Line;

template <size_t N>
struct LineSegment;

struct LineSegment2;
struct LineSegment3;
struct Plane;

template <size_t N>
struct Ray;

template <int dimensions, typename Type>
struct TAabb;

template <typename T>
struct TRect;

template <int N, typename T>
struct TSphere;

template <size_t D>
struct TTriangle;

struct Triangle2;
struct Triangle3;

// classes

class KDop;
class KDop13;
class KDop3;
class KDop4;
class KDop7;
class KalmanFilterObject;
class UvSphereGenerator;

// global variables

static const glm::vec3 Vec3X = AxisToVec3(Axis::x);
static const glm::vec3 Vec3Y = AxisToVec3(Axis::y);
static const glm::vec3 Vec3Z = AxisToVec3(Axis::z);
static const glm::vec4 Vec4X = AxisToVec4(Axis::x);
static const glm::vec4 Vec4Y = AxisToVec4(Axis::y);
static const glm::vec4 Vec4Z = AxisToVec4(Axis::z);
static const std::vector<glm::vec3> KDOP_3_DIRECTIONS {     glm::vec3(1.0, 0.0, 0.0),     glm::vec3(0.0, 1.0, 0.0),     glm::vec3(0.0, 0.0, 1.0),   };
static const std::vector<glm::vec3> KDOP_4_DIRECTIONS {     glm::vec3(1.0, 1.0, 1.0),     glm::vec3(1.0, 1.0, -1.0),     glm::vec3(1.0, -1.0, 1.0),     glm::vec3(1.0, -1.0, -1.0)   };
static const std::vector<glm::vec3> KDOP_7_DIRECTIONS {     glm::vec3(1.0, 0.0, 0.0),     glm::vec3(0.0, 1.0, 0.0),     glm::vec3(0.0, 0.0, 1.0),      glm::vec3(1.0, 1.0, 1.0),     glm::vec3(1.0, 1.0, -1.0),     glm::vec3(1.0, -1.0, 1.0),     glm::vec3(1.0, -1.0, -1.0)   };
static const std::vector<glm::vec3> KDOP_13_DIRECTIONS {     glm::vec3(1.0, 0.0, 0.0),     glm::vec3(0.0, 1.0, 0.0),     glm::vec3(0.0, 0.0, 1.0),      glm::vec3(1.0, 1.0, 1.0),     glm::vec3(1.0, 1.0, -1.0),     glm::vec3(1.0, -1.0, 1.0),     glm::vec3(1.0, -1.0, -1.0),      glm::vec3(0.0, 1.0, 1.0),     glm::vec3(0.0, 1.0, -1.0),     glm::vec3(1.0, 0.0, 1.0),     glm::vec3(1.0, 0.0, -1.0),     glm::vec3(1.0, 1.0, 0.0),     glm::vec3(1.0, -1.0, 0.0),   };

// global functions

static glm::vec3 AxisToVec3(const geom::Axis axis);
static glm::vec4 AxisToVec4(const geom::Axis axis);
GEOM_API Aabb3 GetAabb(const std::vector<glm::vec3>& points);
GEOM_API Aabb3 GetAabb(const ConicalCapsule& conical_capsule);
GEOM_API Line3 ToLine(const LineSegment3& segment);
GEOM_API Plane ToPlane(const HalfPlane& halfplane);
GEOM_API Plane ToPlane(const Triangle3& triangle);
GEOM_API void CalculatePCA(const std::vector<glm::vec3>& vertices, std::vector<glm::vec3>& principalComponents, glm::vec3& pointCloudCenter);
GEOM_API void GetTangentPlanePCA(const std::vector<glm::vec3>& points, glm::vec3& nn, glm::vec3& ev_1, glm::vec3& ev_2, glm::vec3& ev_3);
GEOM_API void PlaneProjectionUsingPCA(const std::vector<glm::vec3>& points, std::vector<float>& pointsInPlane, std::vector<float>& vec1, std::vector<float>& vec2);
GEOM_API glm::vec3 ProjectPointIntoPlane(const glm::vec3& q, const glm::vec3& o, const glm::vec3& n);
GEOM_API glm::vec2 Space2Plane(const glm::vec3& q, const glm::vec3& o, const glm::vec3& e1, const glm::vec3& e2);
GEOM_API glm::vec3 Plane2Space(const glm::vec2& q, const glm::vec3& o, const glm::vec3& e1, const glm::vec3& e2);
GEOM_API float DeterminantInPlane(const glm::vec3& vVector1, const glm::vec3& vVector2, const glm::vec3& vVector3);

template <typename T>
void InflateRectangle(geom::TRect<T>& rect, const T margin);

template <typename T>
void DeflateRectangle(geom::TRect<T>& rect, const T margin);

GEOM_API Plane FitPlane(const std::vector<glm::vec3>& points);
GEOM_API glm::vec3 GetCentroid(const std::vector<glm::vec3>& points);
GEOM_API float GetProjectionParameter(const glm::vec3& point, const geom::LineSegment3& line_segment);
GEOM_API float GetProjectionParameterClamped(const glm::vec3& point, const geom::LineSegment3& line_segment);
GEOM_API float GetOrientedDistance(const glm::vec3& point, const Plane& plane);
GEOM_API float GetDistance(const glm::vec3& point, const geom::LineSegment3& line);
GEOM_API float GetDistance(const glm::vec3& point, const Plane& plane);
GEOM_API float GetDistance(const glm::vec3& point, const geom::Line3& line);
GEOM_API float GetDistance(const glm::vec3& point, const ConicalCapsule& conical_capsuile);
GEOM_API glm::vec3 GetProjection(const glm::vec3& point, const Plane& plane);
GEOM_API glm::vec3 GetProjection(const glm::vec3& point, const LineSegment3& line_segment);
GEOM_API glm::vec3 GetProjection(const glm::vec3& point, const Line3& line);
GEOM_API glm::vec3 GetProjection(const glm::vec3& point, const ConicalCapsule& capsule);
GEOM_API std::optional<glm::vec2> GetIntersection(const geom::Line2& line1, const geom::Line2& line2);
GEOM_API bool GetIntersection(const geom::Line2& line1, const geom::Line2& line2, glm::vec2* out_intersection_point);
GEOM_API bool GetIntersection(const geom::Line3& line, const geom::Plane& plane, glm::vec3* out_intersection_point);
GEOM_API bool GetIntersection(const geom::LineSegment3& linesegment, const geom::Plane& plane, glm::vec3* out_intersection_point);
GEOM_API bool GetIntersection(const geom::Line3& line, const geom::HalfPlane& half_plane, glm::vec3* out_intersection_point);
GEOM_API bool GetIntersection(const geom::LineSegment3& linesegment, const geom::HalfPlane& half_plane, glm::vec3* out_intersection_point);
GEOM_API bool GetIntersection(const geom::Triangle3& triangle, const geom::HalfPlane& halfplane, geom::LineSegment3* out_intersection = nullptr);
GEOM_API bool GetIntersection(const geom::Line3& line, const geom::Aabb3& aabb);
GEOM_API glm::vec3 Barycentric(const glm::vec3& p, const Triangle3& triangle);
GEOM_API CollisionResult GetCollision(const geom::Capsule& capsule_1, const geom::Capsule& capsule_2);
GEOM_API bool IsTriangleFacingToPoint(const glm::vec3& point, const geom::Triangle3& triangle);
GEOM_API void DijkstraAlgorithm(const Graph& graph, const unsigned int start_vertex, std::vector<float>& distances, std::vector<unsigned int>& previous);
GEOM_API void DijkstraAlgorithm(const Graph& graph, const unsigned start_vertex, const std::vector<float>& vertex_weights, std::vector<float>& out_distances, std::vector<unsigned int>& out_previous);
GEOM_API float GetTriangleVolume(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c);
GEOM_API float GetTriangleVolume(const glm::vec3& a, const glm::vec3& b, const glm::vec3& c);
GEOM_API glm::vec3 GetTriangleNormalCW(glm::vec3 p0, glm::vec3 p1, glm::vec3 p2);
GEOM_API glm::vec3 GetTriangleNormalCCW(glm::vec3 p0, glm::vec3 p1, glm::vec3 p2);
GEOM_API bool LineTriangleIntersection(const geom::Triangle3 triangle, const geom::Line3& line, glm::vec3& out_intersection);
GEOM_API glm::vec3 GetCentroid(std::vector<float>& vertices);
GEOM_API glm::vec3 GetVertexLowestY(std::vector<float>& vertices);

} // namespace geom

Detailed Documentation

Set of structures for geometry and linear algebra.

Typedefs

typedef Line<2> Line2

Definition of a line in a 2 dimensional space.

typedef Line<3> Line3

Definition of a line in a 3 dimensional space.

typedef Ray<2> Ray2

Definition of a ray in a 2 dimensional space.

typedef Ray<3> Ray3

Definition of a ray in a 3 dimensional space.

typedef TSphere<2, float> Circle

Definition of a float type circle.

typedef TSphere<3, float> Sphere

Definition of a float type sphere.

typedef TRect<float> Rect

Definition of a float type rectangle.

typedef TRect<int> IRect

Definition of an integer type rectangle.

typedef TRect<unsigned> URect

Definition of an unsigned integer type rectangle.

typedef TAabb<2, float> Aabb2

Two dimensional axis aligned bounding box.

typedef TAabb<3, float> Aabb3

Three dimensional axis aligned bounding box.

Global Variables

static const glm::vec3 Vec3X = AxisToVec3(Axis::x)

Definition of a unit 3D vector in X axis.

static const glm::vec3 Vec3Y = AxisToVec3(Axis::y)

Definition of a unit 3D vector in Y axis.

static const glm::vec3 Vec3Z = AxisToVec3(Axis::z)

Definition of a unit 3D vector in Z axis.

static const glm::vec4 Vec4X = AxisToVec4(Axis::x)

Definition of a unit 4D vector in X axis.

static const glm::vec4 Vec4Y = AxisToVec4(Axis::y)

Definition of a unit 4D vector in Y axis.

static const glm::vec4 Vec4Z = AxisToVec4(Axis::z)

Definition of a unit 4D vector in Z axis.

static const std::vector<glm::vec3> KDOP_3_DIRECTIONS {     glm::vec3(1.0, 0.0, 0.0),     glm::vec3(0.0, 1.0, 0.0),     glm::vec3(0.0, 0.0, 1.0),   }

Directions that define default KDOP_3.

static const std::vector<glm::vec3> KDOP_4_DIRECTIONS {     glm::vec3(1.0, 1.0, 1.0),     glm::vec3(1.0, 1.0, -1.0),     glm::vec3(1.0, -1.0, 1.0),     glm::vec3(1.0, -1.0, -1.0)   }

Directions that define default KDOP_4.

static const std::vector<glm::vec3> KDOP_7_DIRECTIONS {     glm::vec3(1.0, 0.0, 0.0),     glm::vec3(0.0, 1.0, 0.0),     glm::vec3(0.0, 0.0, 1.0),      glm::vec3(1.0, 1.0, 1.0),     glm::vec3(1.0, 1.0, -1.0),     glm::vec3(1.0, -1.0, 1.0),     glm::vec3(1.0, -1.0, -1.0)   }

Directions that define default KDOP_7.

static const std::vector<glm::vec3> KDOP_13_DIRECTIONS {     glm::vec3(1.0, 0.0, 0.0),     glm::vec3(0.0, 1.0, 0.0),     glm::vec3(0.0, 0.0, 1.0),      glm::vec3(1.0, 1.0, 1.0),     glm::vec3(1.0, 1.0, -1.0),     glm::vec3(1.0, -1.0, 1.0),     glm::vec3(1.0, -1.0, -1.0),      glm::vec3(0.0, 1.0, 1.0),     glm::vec3(0.0, 1.0, -1.0),     glm::vec3(1.0, 0.0, 1.0),     glm::vec3(1.0, 0.0, -1.0),     glm::vec3(1.0, 1.0, 0.0),     glm::vec3(1.0, -1.0, 0.0),   }

Directions that define default KDOP_13.

Global Functions

static glm::vec3 AxisToVec3(const geom::Axis axis)

Converts an Axis to the glm::vec3.

static glm::vec4 AxisToVec4(const geom::Axis axis)

Converts an Axis to the glm::vec4. Homogenic (w) coordinate is zero.

GEOM_API Aabb3 GetAabb(const std::vector<glm::vec3>& points)

Get Aabb3 that covers every point in the point set.

GEOM_API Aabb3 GetAabb(const ConicalCapsule& conical_capsule)

Get Aabb3 that covers the entire ConicalCapsule.

GEOM_API Line3 ToLine(const LineSegment3& segment)

Convert 3D LineSegment object to 3D Line.

GEOM_API Plane ToPlane(const HalfPlane& halfplane)

Convert HalfPlane object to Plane.

GEOM_API Plane ToPlane(const Triangle3& triangle)

Convert 3D Triangle primitive to Plane.

template <typename T>
void InflateRectangle(geom::TRect<T>& rect, const T margin)

Inflate each side of the rectangle by specified margin.

template <typename T>
void DeflateRectangle(geom::TRect<T>& rect, const T margin)

Deflate each side of the rectangle by specified margin.

GEOM_API Plane FitPlane(const std::vector<glm::vec3>& points)

Fit a 3D plane to the point set.

GEOM_API glm::vec3 GetCentroid(const std::vector<glm::vec3>& points)

Calculate mean point of the point set.

GEOM_API float GetProjectionParameter(const glm::vec3& point, const geom::LineSegment3& line_segment)

Calculate interpolation parameter of point projection onto the line segment.

Resulting parameter of value 0 tells the projection lays on segment line point1, and value 1 tells the projection lays on segment line point2. Anything between 0 and 1 tells the point projection lays directly on line segment

Returns:

Parameter value between -inf and inf.

GEOM_API float GetProjectionParameterClamped(const glm::vec3& point, const geom::LineSegment3& line_segment)

Calculate interpolation parameter of point projection onto the line segment.

Resulting parameter of value 0 tells the projection lays on segment line point1, and value 1 tells the projection lays on segment line point2. Anything between 0 and 1 tells the point projection lays directly on line segment

Returns:

Parameter value between 0 and 1.

GEOM_API float GetOrientedDistance(const glm::vec3& point, const Plane& plane)

Calculates the oriented distance of point to a plane. The value is positive if the point lies in the half-space pointed to by the plane normal.

GEOM_API float GetDistance(const glm::vec3& point, const geom::LineSegment3& line)

Calculates a distance of the point to the 3D line segment.

GEOM_API float GetDistance(const glm::vec3& point, const Plane& plane)

Calculate the distance of the point from the plane.

GEOM_API float GetDistance(const glm::vec3& point, const geom::Line3& line)

Calculate the distance of the point from the 3D line.

GEOM_API float GetDistance(const glm::vec3& point, const ConicalCapsule& conical_capsuile)

Calculate distance of point to the capsule surface.

Returns:

Negative distance when point is inside capsule, zero when it is on surface and positive value otherwise.

GEOM_API glm::vec3 GetProjection(const glm::vec3& point, const Plane& plane)

Calculate projection of point onto a plane.

GEOM_API glm::vec3 GetProjection(const glm::vec3& point, const LineSegment3& line_segment)

Calculate projection of point onto a line segment in 3D.

GEOM_API glm::vec3 GetProjection(const glm::vec3& point, const Line3& line)

Calculate projection of point onto a line in 3D.

GEOM_API glm::vec3 GetProjection(const glm::vec3& point, const ConicalCapsule& capsule)

Calculate projection of point onto a ConicalCapsule.

GEOM_API std::optional<glm::vec2> GetIntersection(const geom::Line2& line1, const geom::Line2& line2)

Get intersection point between two 2D planes.