Apollo  6.0
Open source self driving car software
Public Member Functions | List of all members
apollo::common::math::LineSegment2d Class Reference

Line segment in 2-D. More...

#include <line_segment2d.h>

Collaboration diagram for apollo::common::math::LineSegment2d:
Collaboration graph

Public Member Functions

 LineSegment2d ()
 Empty constructor. More...
 
 LineSegment2d (const Vec2d &start, const Vec2d &end)
 Constructor with start point and end point. More...
 
const Vec2dstart () const
 Get the start point. More...
 
const Vec2dend () const
 Get the end point. More...
 
const Vec2dunit_direction () const
 Get the unit direction from the start point to the end point. More...
 
Vec2d center () const
 Get the center of the line segment. More...
 
Vec2d rotate (const double angle)
 Get a new line-segment with the same start point, but rotated counterclock-wise by the given amount. More...
 
double heading () const
 Get the heading of the line segment. More...
 
double cos_heading () const
 Get the cosine of the heading. More...
 
double sin_heading () const
 Get the sine of the heading. More...
 
double length () const
 Get the length of the line segment. More...
 
double length_sqr () const
 Get the square of length of the line segment. More...
 
double DistanceTo (const Vec2d &point) const
 Compute the shortest distance from a point on the line segment to a point in 2-D. More...
 
double DistanceTo (const Vec2d &point, Vec2d *const nearest_pt) const
 Compute the shortest distance from a point on the line segment to a point in 2-D, and get the nearest point on the line segment. More...
 
double DistanceSquareTo (const Vec2d &point) const
 Compute the square of the shortest distance from a point on the line segment to a point in 2-D. More...
 
double DistanceSquareTo (const Vec2d &point, Vec2d *const nearest_pt) const
 Compute the square of the shortest distance from a point on the line segment to a point in 2-D, and get the nearest point on the line segment. More...
 
bool IsPointIn (const Vec2d &point) const
 Check if a point is within the line segment. More...
 
bool HasIntersect (const LineSegment2d &other_segment) const
 Check if the line segment has an intersect with another line segment in 2-D. More...
 
bool GetIntersect (const LineSegment2d &other_segment, Vec2d *const point) const
 Compute the intersect with another line segment in 2-D if any. More...
 
double ProjectOntoUnit (const Vec2d &point) const
 Compute the projection of a vector onto the line segment. More...
 
double ProductOntoUnit (const Vec2d &point) const
 Compute the cross product of a vector onto the line segment. More...
 
double GetPerpendicularFoot (const Vec2d &point, Vec2d *const foot_point) const
 Compute perpendicular foot of a point in 2-D on the straight line expanded from the line segment. More...
 
std::string DebugString () const
 Get the debug string including the essential information. More...
 

Detailed Description

Line segment in 2-D.

Constructor & Destructor Documentation

◆ LineSegment2d() [1/2]

apollo::common::math::LineSegment2d::LineSegment2d ( )

Empty constructor.

◆ LineSegment2d() [2/2]

apollo::common::math::LineSegment2d::LineSegment2d ( const Vec2d start,
const Vec2d end 
)

Constructor with start point and end point.

Parameters
startThe start point of the line segment.
endThe end point of the line segment.

Member Function Documentation

◆ center()

Vec2d apollo::common::math::LineSegment2d::center ( ) const
inline

Get the center of the line segment.

Returns
The center of the line segment.

◆ cos_heading()

double apollo::common::math::LineSegment2d::cos_heading ( ) const
inline

Get the cosine of the heading.

Returns
The cosine of the heading.

◆ DebugString()

std::string apollo::common::math::LineSegment2d::DebugString ( ) const

Get the debug string including the essential information.

Returns
Information of the line segment for debugging.

◆ DistanceSquareTo() [1/2]

double apollo::common::math::LineSegment2d::DistanceSquareTo ( const Vec2d point) const

Compute the square of the shortest distance from a point on the line segment to a point in 2-D.

Parameters
pointThe point to compute the squared of the distance to.
Returns
The square of the shortest distance from points on the line segment to the input point.

◆ DistanceSquareTo() [2/2]

double apollo::common::math::LineSegment2d::DistanceSquareTo ( const Vec2d point,
Vec2d *const  nearest_pt 
) const

Compute the square of the shortest distance from a point on the line segment to a point in 2-D, and get the nearest point on the line segment.

Parameters
pointThe point to compute the squared of the distance to.
nearest_ptThe nearest point on the line segment to the input point.
Returns
The shortest distance from points on the line segment to the input point.

◆ DistanceTo() [1/2]

double apollo::common::math::LineSegment2d::DistanceTo ( const Vec2d point) const

Compute the shortest distance from a point on the line segment to a point in 2-D.

Parameters
pointThe point to compute the distance to.
Returns
The shortest distance from points on the line segment to point.

◆ DistanceTo() [2/2]

double apollo::common::math::LineSegment2d::DistanceTo ( const Vec2d point,
Vec2d *const  nearest_pt 
) const

Compute the shortest distance from a point on the line segment to a point in 2-D, and get the nearest point on the line segment.

Parameters
pointThe point to compute the distance to.
nearest_ptThe nearest point on the line segment to the input point.
Returns
The shortest distance from points on the line segment to the input point.

◆ end()

const Vec2d& apollo::common::math::LineSegment2d::end ( ) const
inline

Get the end point.

Returns
The end point of the line segment.

◆ GetIntersect()

bool apollo::common::math::LineSegment2d::GetIntersect ( const LineSegment2d other_segment,
Vec2d *const  point 
) const

Compute the intersect with another line segment in 2-D if any.

Parameters
other_segmentThe line segment to compute the intersect.
pointthe computed intersect between the line segment and the input other_segment.
Returns
Whether the line segment has an intersect with the input other_segment.

◆ GetPerpendicularFoot()

double apollo::common::math::LineSegment2d::GetPerpendicularFoot ( const Vec2d point,
Vec2d *const  foot_point 
) const

Compute perpendicular foot of a point in 2-D on the straight line expanded from the line segment.

Parameters
pointThe point to compute the perpendicular foot from.
foot_pointThe computed perpendicular foot from the input point to the straight line expanded from the line segment.
Returns
The distance from the input point to the perpendicular foot.

◆ HasIntersect()

bool apollo::common::math::LineSegment2d::HasIntersect ( const LineSegment2d other_segment) const

Check if the line segment has an intersect with another line segment in 2-D.

Parameters
other_segmentThe line segment to check if it has an intersect.
Returns
Whether the line segment has an intersect with the input other_segment.

◆ heading()

double apollo::common::math::LineSegment2d::heading ( ) const
inline

Get the heading of the line segment.

Returns
The heading, which is the angle between unit direction and x-axis.

◆ IsPointIn()

bool apollo::common::math::LineSegment2d::IsPointIn ( const Vec2d point) const

Check if a point is within the line segment.

Parameters
pointThe point to check if it is within the line segment.
Returns
Whether the input point is within the line segment or not.

◆ length()

double apollo::common::math::LineSegment2d::length ( ) const

Get the length of the line segment.

Returns
The length of the line segment.

◆ length_sqr()

double apollo::common::math::LineSegment2d::length_sqr ( ) const

Get the square of length of the line segment.

Returns
The square of length of the line segment.

◆ ProductOntoUnit()

double apollo::common::math::LineSegment2d::ProductOntoUnit ( const Vec2d point) const

Compute the cross product of a vector onto the line segment.

Parameters
pointThe end of the vector (starting from the start point of the line segment) to compute the cross product onto the line segment.
Returns
The cross product of the unit direction and the vector, which is from the start point of the line segment to the input point.

◆ ProjectOntoUnit()

double apollo::common::math::LineSegment2d::ProjectOntoUnit ( const Vec2d point) const

Compute the projection of a vector onto the line segment.

Parameters
pointThe end of the vector (starting from the start point of the line segment) to compute the projection onto the line segment.
Returns
The projection of the vector, which is from the start point of the line segment to the input point, onto the unit direction.

◆ rotate()

Vec2d apollo::common::math::LineSegment2d::rotate ( const double  angle)

Get a new line-segment with the same start point, but rotated counterclock-wise by the given amount.

Returns
The rotated line-segment's end-point.

◆ sin_heading()

double apollo::common::math::LineSegment2d::sin_heading ( ) const
inline

Get the sine of the heading.

Returns
The sine of the heading.

◆ start()

const Vec2d& apollo::common::math::LineSegment2d::start ( ) const
inline

Get the start point.

Returns
The start point of the line segment.

◆ unit_direction()

const Vec2d& apollo::common::math::LineSegment2d::unit_direction ( ) const
inline

Get the unit direction from the start point to the end point.

Returns
The start point of the line segment.

The documentation for this class was generated from the following file: