The Shapes Library
Game Physics with Bespoke Code
Loading...
Searching...
No Matches
Shapes::CLine Class Reference

Line shape. More...

#include <Line.h>

Inheritance diagram for Shapes::CLine:

Public Member Functions

 CLine (const Vector2 &, float)
 Constructor.
 

Protected Member Functions

const Vector2 Intersect (const CLine &) const
 Get intersection point with line.
 
const Vector2 ClosestPt (const Vector2 &) const
 Get closest point on line.
 

Protected Attributes

float m_fGradient = 0.0f
 Gradient.
 
float m_fInverseGradient = 0.0f
 Inverse gradient.
 
float m_fYIntercept = 0.0f
 Intercept with Y axis.
 
float m_fXIntercept = 0.0f
 Intercept with X axis.
 

Detailed Description

A line is infinite in both directions. It consists of its gradient \(m\) and \(y\)-incercept \(c\), that is, it has the equation \(y = mx + c\). The gradient can be infinite, in which case it has the equation \(x = b\), where \(b\) is its \(x\)-intercept. Note that there is no line descriptor class. That is to discourage the use of lines outside this project. If you are thinking of using one, I recommend that you use a line segment instead.

Constructor & Destructor Documentation

◆ CLine()

CLine::CLine ( const Vector2 & p,
float m )

Given a point and a gradient, construct the unique line through that point with that gradient.

Parameters
pPoint.
mGradient.
Here is the caller graph for this function:

Member Function Documentation

◆ ClosestPt()

const Vector2 CLine::ClosestPt ( const Vector2 & p) const
protected

Given a point, find the point on this line that is closest to it. This is done by intersecting this line with a perpendicular line through the point.

Parameters
pA point.
Returns
The point on this line that is closest to it.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Intersect()

const Vector2 CLine::Intersect ( const CLine & Line) const
protected

Given another line, find the unique point that is on both lines if they are not parallel, otherwise fail. We have to careful whem one or both of the lines are vertical because vertical lines have infinite gradient.

Parameters
LineA line to intersect with.
Returns
Point of intersection of this line with that one, if there is one.
Here is the caller graph for this function: