MXVK Vulkan Framework 0.35.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
mxvk::paramLine2D Struct Reference

Parametric 2D line segment represented by a start point, end point, and direction. More...

#include <mxvk/include/mxvk/mxvk_math.h>

Public Member Functions

vec2D ComputePoint (float t) const
 Compute the point p0 + v * t.
vec2D ComputePoint (float t) const
 Compute the point p0 + v * t.
vec2D ComputePoint (float t, vec2D &out) const
 Compute the point p0 + v * t and write it to out.
vec2D ComputePoint (float t, vec2D &out) const
 Compute the point p0 + v * t and write it to out.
void Init (const vec2D &start, const vec2D &end)
 Initialize from endpoints and derive the direction vector.
void Init (const vec2D &start, const vec2D &end)
 Initialize from endpoints and derive the direction vector.
int Intersect (const paramLine2D &line, float &t_this, float &t_other) const
 Intersect this segment with another parametric segment.
int Intersect (const paramLine2D &line, float &t_this, float &t_other) const
 Intersect this segment with another parametric segment.
int Intersect (const paramLine2D &line, vec2D &out) const
 Intersect this segment with another segment and compute the point.
int Intersect (const paramLine2D &line, vec2D &out) const
 Intersect this segment with another segment and compute the point.
 paramLine2D ()=default
 Construct an uninitialized line segment.
 paramLine2D ()=default
 Construct an uninitialized line segment.
 paramLine2D (const vec2D &start, const vec2D &end, const vec2D &dir)
 Construct from explicit endpoints and direction.
 paramLine2D (const vec2D &start, const vec2D &end, const vec2D &dir)
 Construct from explicit endpoints and direction.
void Set (const vec2D &start, const vec2D &end, const vec2D &dir)
 Set explicit endpoints and direction.
void Set (const vec2D &start, const vec2D &end, const vec2D &dir)
 Set explicit endpoints and direction.

Public Attributes

vec2D p0
 Segment start point.
vec2D p1
 Segment end point.
vec2D v
 Direction vector, commonly p1 - p0.

Detailed Description

Parametric 2D line segment represented by a start point, end point, and direction.

Definition at line 875 of file mxvk_math.h.

Constructor & Destructor Documentation

◆ paramLine2D() [1/4]

mxvk::paramLine2D::paramLine2D ( )
default

Construct an uninitialized line segment.

◆ paramLine2D() [2/4]

mxvk::paramLine2D::paramLine2D ( const vec2D & start,
const vec2D & end,
const vec2D & dir )
inline

Construct from explicit endpoints and direction.

Definition at line 889 of file mxvk_math.h.

889{ Set(start, end, dir); }
void Set(const vec2D &start, const vec2D &end, const vec2D &dir)
Set explicit endpoints and direction.
Definition mxvk_math.h:892

◆ paramLine2D() [3/4]

mxvk::paramLine2D::paramLine2D ( )
default

Construct an uninitialized line segment.

◆ paramLine2D() [4/4]

mxvk::paramLine2D::paramLine2D ( const vec2D & start,
const vec2D & end,
const vec2D & dir )
inline

Construct from explicit endpoints and direction.

Definition at line 852 of file mxvk_math_eigen.hpp.

852{ Set(start, end, dir); }

Member Function Documentation

◆ ComputePoint() [1/4]

vec2D mxvk::paramLine2D::ComputePoint ( float t) const
inlinenodiscard

Compute the point p0 + v * t.

Definition at line 906 of file mxvk_math.h.

906{ return p0 + v * t; }
vec2D p0
Segment start point.
Definition mxvk_math.h:877
vec2D v
Direction vector, commonly p1 - p0.
Definition mxvk_math.h:883

◆ ComputePoint() [2/4]

vec2D mxvk::paramLine2D::ComputePoint ( float t) const
inlinenodiscard

Compute the point p0 + v * t.

Definition at line 869 of file mxvk_math_eigen.hpp.

869{ return p0 + v * t; }

◆ ComputePoint() [3/4]

vec2D mxvk::paramLine2D::ComputePoint ( float t,
vec2D & out ) const
inline

Compute the point p0 + v * t and write it to out.

Definition at line 909 of file mxvk_math.h.

909 {
910 out = ComputePoint(t);
911 return out;
912 }
vec2D ComputePoint(float t) const
Compute the point p0 + v * t.
Definition mxvk_math.h:906

◆ ComputePoint() [4/4]

vec2D mxvk::paramLine2D::ComputePoint ( float t,
vec2D & out ) const
inline

Compute the point p0 + v * t and write it to out.

Definition at line 872 of file mxvk_math_eigen.hpp.

872 {
873 out = ComputePoint(t);
874 return out;
875 }

◆ Init() [1/2]

void mxvk::paramLine2D::Init ( const vec2D & start,
const vec2D & end )
inline

Initialize from endpoints and derive the direction vector.

Definition at line 899 of file mxvk_math.h.

899 {
900 p0 = start;
901 p1 = end;
902 v = end - start;
903 }
vec2D p1
Segment end point.
Definition mxvk_math.h:880

◆ Init() [2/2]

void mxvk::paramLine2D::Init ( const vec2D & start,
const vec2D & end )
inline

Initialize from endpoints and derive the direction vector.

Definition at line 862 of file mxvk_math_eigen.hpp.

862 {
863 p0 = start;
864 p1 = end;
865 v = end - start;
866 }

◆ Intersect() [1/4]

int mxvk::paramLine2D::Intersect ( const paramLine2D & line,
float & t_this,
float & t_other ) const
inline

Intersect this segment with another parametric segment.

Parameters
lineSegment to intersect with.
t_thisReceives this segment's intersection parameter.
t_otherReceives the other segment's intersection parameter.
Returns
0 for parallel lines, 1 for segment intersection, 2 for line intersection outside one or both segments.

Definition at line 921 of file mxvk_math.h.

921 {
922 const float det = v.x * line.v.y - v.y * line.v.x;
923 if (std::fabs(det) <= EPSILON) {
924 return 0;
925 }
926 const vec2D delta = line.p0 - p0;
927 t_this = (delta.x * line.v.y - delta.y * line.v.x) / det;
928 t_other = (delta.x * v.y - delta.y * v.x) / det;
929 return (t_this >= 0.0f && t_this <= 1.0f && t_other >= 0.0f && t_other <= 1.0f) ? 1 : 2;
930 }
float x
X coordinate.
Definition mxvk_math.h:161
float y
Y coordinate.
Definition mxvk_math.h:164
constexpr float EPSILON
Default tolerance used for floating-point singularity and zero-length checks.
Definition mxvk_math.h:37

◆ Intersect() [2/4]

int mxvk::paramLine2D::Intersect ( const paramLine2D & line,
float & t_this,
float & t_other ) const
inline

Intersect this segment with another parametric segment.

Parameters
lineSegment to intersect with.
t_thisReceives this segment's intersection parameter.
t_otherReceives the other segment's intersection parameter.
Returns
0 for parallel lines, 1 for segment intersection, 2 for line intersection outside one or both segments.

Definition at line 884 of file mxvk_math_eigen.hpp.

884 {
885 Eigen::Matrix2f directions;
886 directions << v.x, line.v.x, v.y, line.v.y;
887 const float det = directions.determinant();
888 if (std::fabs(det) <= EPSILON) {
889 return 0;
890 }
891 const Eigen::Vector2f delta(line.p0.x - p0.x, line.p0.y - p0.y);
892 const Eigen::Vector2f parameters = directions.partialPivLu().solve(delta);
893 t_this = parameters.x();
894 t_other = -parameters.y();
895 return (t_this >= 0.0f && t_this <= 1.0f && t_other >= 0.0f && t_other <= 1.0f) ? 1 : 2;
896 }

◆ Intersect() [3/4]

int mxvk::paramLine2D::Intersect ( const paramLine2D & line,
vec2D & out ) const
inline

Intersect this segment with another segment and compute the point.

Parameters
lineSegment to intersect with.
outReceives the intersection point when the lines are not parallel.
Returns
0 for parallel lines, 1 for segment intersection, 2 for line intersection outside one or both segments.

Definition at line 938 of file mxvk_math.h.

938 {
939 float t_this = 0.0f;
940 float t_other = 0.0f;
941 const int result = Intersect(line, t_this, t_other);
942 if (result != 0) {
943 out = ComputePoint(t_this);
944 }
945 return result;
946 }
int Intersect(const paramLine2D &line, float &t_this, float &t_other) const
Intersect this segment with another parametric segment.
Definition mxvk_math.h:921

◆ Intersect() [4/4]

int mxvk::paramLine2D::Intersect ( const paramLine2D & line,
vec2D & out ) const
inline

Intersect this segment with another segment and compute the point.

Parameters
lineSegment to intersect with.
outReceives the intersection point when the lines are not parallel.
Returns
0 for parallel lines, 1 for segment intersection, 2 for line intersection outside one or both segments.

Definition at line 904 of file mxvk_math_eigen.hpp.

904 {
905 float t_this = 0.0f;
906 float t_other = 0.0f;
907 const int result = Intersect(line, t_this, t_other);
908 if (result != 0) {
909 out = ComputePoint(t_this);
910 }
911 return result;
912 }

◆ Set() [1/2]

void mxvk::paramLine2D::Set ( const vec2D & start,
const vec2D & end,
const vec2D & dir )
inline

Set explicit endpoints and direction.

Definition at line 892 of file mxvk_math.h.

892 {
893 p0 = start;
894 p1 = end;
895 v = dir;
896 }

◆ Set() [2/2]

void mxvk::paramLine2D::Set ( const vec2D & start,
const vec2D & end,
const vec2D & dir )
inline

Set explicit endpoints and direction.

Definition at line 855 of file mxvk_math_eigen.hpp.

855 {
856 p0 = start;
857 p1 = end;
858 v = dir;
859 }

Member Data Documentation

◆ p0

vec2D mxvk::paramLine2D::p0

Segment start point.

Definition at line 877 of file mxvk_math.h.

◆ p1

vec2D mxvk::paramLine2D::p1

Segment end point.

Definition at line 880 of file mxvk_math.h.

◆ v

vec2D mxvk::paramLine2D::v

Direction vector, commonly p1 - p0.

Definition at line 883 of file mxvk_math.h.


The documentation for this struct was generated from the following files: