MXVK Vulkan Framework 0.24.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 989 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 1003 of file mxvk_math.h.

1003 {
1004 Set(start, end, dir);
1005 }
void Set(const vec2D &start, const vec2D &end, const vec2D &dir)
Set explicit endpoints and direction.
Definition mxvk_math.h:1008

◆ 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 1000 of file mxvk_math_eigen.hpp.

1000 {
1001 Set(start, end, dir);
1002 }

Member Function Documentation

◆ ComputePoint() [1/4]

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

Compute the point p0 + v * t.

Definition at line 1022 of file mxvk_math.h.

1022 {
1023 return p0 + v * t;
1024 }
vec2D p0
Segment start point.
Definition mxvk_math.h:991
vec2D v
Direction vector, commonly p1 - p0.
Definition mxvk_math.h:997

◆ ComputePoint() [2/4]

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

Compute the point p0 + v * t.

Definition at line 1019 of file mxvk_math_eigen.hpp.

1019 {
1020 return p0 + v * t;
1021 }

◆ 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 1027 of file mxvk_math.h.

1027 {
1028 out = ComputePoint(t);
1029 return out;
1030 }
vec2D ComputePoint(float t) const
Compute the point p0 + v * t.
Definition mxvk_math.h:1022

◆ 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 1024 of file mxvk_math_eigen.hpp.

1024 {
1025 out = ComputePoint(t);
1026 return out;
1027 }

◆ 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 1015 of file mxvk_math.h.

1015 {
1016 p0 = start;
1017 p1 = end;
1018 v = end - start;
1019 }
vec2D p1
Segment end point.
Definition mxvk_math.h:994

◆ 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 1012 of file mxvk_math_eigen.hpp.

1012 {
1013 p0 = start;
1014 p1 = end;
1015 v = end - start;
1016 }

◆ 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 1039 of file mxvk_math.h.

1039 {
1040 const float det = v.x * line.v.y - v.y * line.v.x;
1041 if (std::fabs(det) <= EPSILON) {
1042 return 0;
1043 }
1044 const vec2D delta = line.p0 - p0;
1045 t_this = (delta.x * line.v.y - delta.y * line.v.x) / det;
1046 t_other = (delta.x * v.y - delta.y * v.x) / det;
1047 return (t_this >= 0.0f && t_this <= 1.0f && t_other >= 0.0f && t_other <= 1.0f) ? 1 : 2;
1048 }
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 1036 of file mxvk_math_eigen.hpp.

1036 {
1037 Eigen::Matrix2f directions;
1038 directions << v.x, line.v.x, v.y, line.v.y;
1039 const float det = directions.determinant();
1040 if (std::fabs(det) <= EPSILON) {
1041 return 0;
1042 }
1043 const Eigen::Vector2f delta(line.p0.x - p0.x, line.p0.y - p0.y);
1044 const Eigen::Vector2f parameters = directions.partialPivLu().solve(delta);
1045 t_this = parameters.x();
1046 t_other = -parameters.y();
1047 return (t_this >= 0.0f && t_this <= 1.0f && t_other >= 0.0f && t_other <= 1.0f) ? 1 : 2;
1048 }

◆ 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 1056 of file mxvk_math.h.

1056 {
1057 float t_this = 0.0f;
1058 float t_other = 0.0f;
1059 const int result = Intersect(line, t_this, t_other);
1060 if (result != 0) {
1061 out = ComputePoint(t_this);
1062 }
1063 return result;
1064 }
int Intersect(const paramLine2D &line, float &t_this, float &t_other) const
Intersect this segment with another parametric segment.
Definition mxvk_math.h:1039

◆ 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 1056 of file mxvk_math_eigen.hpp.

1056 {
1057 float t_this = 0.0f;
1058 float t_other = 0.0f;
1059 const int result = Intersect(line, t_this, t_other);
1060 if (result != 0) {
1061 out = ComputePoint(t_this);
1062 }
1063 return result;
1064 }

◆ 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 1008 of file mxvk_math.h.

1008 {
1009 p0 = start;
1010 p1 = end;
1011 v = dir;
1012 }

◆ 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 1005 of file mxvk_math_eigen.hpp.

1005 {
1006 p0 = start;
1007 p1 = end;
1008 v = dir;
1009 }

Member Data Documentation

◆ p0

vec2D mxvk::paramLine2D::p0

Segment start point.

Definition at line 991 of file mxvk_math.h.

◆ p1

vec2D mxvk::paramLine2D::p1

Segment end point.

Definition at line 994 of file mxvk_math.h.

◆ v

vec2D mxvk::paramLine2D::v

Direction vector, commonly p1 - p0.

Definition at line 997 of file mxvk_math.h.


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