Apollo 10.0
自动驾驶开放平台
apollo::common::math::Vec2d类 参考

Implements a class of 2-dimensional vectors. 更多...

#include <vec2d.h>

类 apollo::common::math::Vec2d 继承关系图:
apollo::common::math::Vec2d 的协作图:

Public 成员函数

constexpr Vec2d (const double x, const double y) noexcept
 Constructor which takes x- and y-coordinates.
 
constexpr Vec2d () noexcept
 Constructor returning the zero vector.
 
double x () const
 Getter for x component
 
double y () const
 Getter for y component
 
void set_x (const double x)
 Setter for x component
 
void set_y (const double y)
 Setter for y component
 
double Length () const
 Gets the length of the vector
 
double LengthSquare () const
 Gets the squared length of the vector
 
double Angle () const
 Gets the angle between the vector and the positive x semi-axis
 
void Normalize ()
 Returns the unit vector that is co-linear with this vector
 
double DistanceTo (const Vec2d &other) const
 Returns the distance to the given vector
 
double DistanceSquareTo (const Vec2d &other) const
 Returns the squared distance to the given vector
 
double CrossProd (const Vec2d &other) const
 Returns the "cross" product between these two Vec2d (non-standard).
 
double InnerProd (const Vec2d &other) const
 Returns the inner product between these two Vec2d.
 
Vec2d rotate (const double angle) const
 rotate the vector by angle.
 
void SelfRotate (const double angle)
 rotate the vector itself by angle.
 
Vec2d operator+ (const Vec2d &other) const
 Sums two Vec2d
 
Vec2d operator- (const Vec2d &other) const
 Subtracts two Vec2d
 
Vec2d operator* (const double ratio) const
 Multiplies Vec2d by a scalar
 
Vec2d operator/ (const double ratio) const
 Divides Vec2d by a scalar
 
Vec2doperator+= (const Vec2d &other)
 Sums another Vec2d to the current one
 
Vec2doperator-= (const Vec2d &other)
 Subtracts another Vec2d to the current one
 
Vec2doperator*= (const double ratio)
 Multiplies this Vec2d by a scalar
 
Vec2doperator/= (const double ratio)
 Divides this Vec2d by a scalar
 
bool operator== (const Vec2d &other) const
 Compares two Vec2d
 
std::string DebugString () const
 Returns a human-readable string representing this object
 

静态 Public 成员函数

static Vec2d CreateUnitVec2d (const double angle)
 Creates a unit-vector with a given angle to the positive x semi-axis
 

Protected 属性

double x_ = 0.0
 
double y_ = 0.0
 

详细描述

Implements a class of 2-dimensional vectors.

在文件 vec2d.h42 行定义.

构造及析构函数说明

◆ Vec2d() [1/2]

constexpr apollo::common::math::Vec2d::Vec2d ( const double  x,
const double  y 
)
inlineconstexprnoexcept

Constructor which takes x- and y-coordinates.

在文件 vec2d.h45 行定义.

45: x_(x), y_(y) {}
double y() const
Getter for y component
Definition vec2d.h:57
double x() const
Getter for x component
Definition vec2d.h:54

◆ Vec2d() [2/2]

constexpr apollo::common::math::Vec2d::Vec2d ( )
inlineconstexprnoexcept

Constructor returning the zero vector.

在文件 vec2d.h48 行定义.

48: Vec2d(0, 0) {}
constexpr Vec2d() noexcept
Constructor returning the zero vector.
Definition vec2d.h:48

成员函数说明

◆ Angle()

double apollo::common::math::Vec2d::Angle ( ) const

Gets the angle between the vector and the positive x semi-axis

在文件 vec2d.cc37 行定义.

37{ return std::atan2(y_, x_); }

◆ CreateUnitVec2d()

Vec2d apollo::common::math::Vec2d::CreateUnitVec2d ( const double  angle)
static

Creates a unit-vector with a given angle to the positive x semi-axis

在文件 vec2d.cc29 行定义.

29 {
30 return Vec2d(std::cos(angle), std::sin(angle));
31}

◆ CrossProd()

double apollo::common::math::Vec2d::CrossProd ( const Vec2d other) const

Returns the "cross" product between these two Vec2d (non-standard).

在文件 vec2d.cc57 行定义.

57 {
58 return x_ * other.y() - y_ * other.x();
59}

◆ DebugString()

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

Returns a human-readable string representing this object

在文件 vec2d.cc125 行定义.

125 {
126 return absl::StrCat("vec2d ( x = ", x_, " y = ", y_, " )");
127}

◆ DistanceSquareTo()

double apollo::common::math::Vec2d::DistanceSquareTo ( const Vec2d other) const

Returns the squared distance to the given vector

在文件 vec2d.cc51 行定义.

51 {
52 const double dx = x_ - other.x_;
53 const double dy = y_ - other.y_;
54 return dx * dx + dy * dy;
55}

◆ DistanceTo()

double apollo::common::math::Vec2d::DistanceTo ( const Vec2d other) const

Returns the distance to the given vector

在文件 vec2d.cc47 行定义.

47 {
48 return std::hypot(x_ - other.x_, y_ - other.y_);
49}

◆ InnerProd()

double apollo::common::math::Vec2d::InnerProd ( const Vec2d other) const

Returns the inner product between these two Vec2d.

在文件 vec2d.cc61 行定义.

61 {
62 return x_ * other.x() + y_ * other.y();
63}

◆ Length()

double apollo::common::math::Vec2d::Length ( ) const

Gets the length of the vector

在文件 vec2d.cc33 行定义.

33{ return std::hypot(x_, y_); }

◆ LengthSquare()

double apollo::common::math::Vec2d::LengthSquare ( ) const

Gets the squared length of the vector

在文件 vec2d.cc35 行定义.

35{ return x_ * x_ + y_ * y_; }

◆ Normalize()

void apollo::common::math::Vec2d::Normalize ( )

Returns the unit vector that is co-linear with this vector

在文件 vec2d.cc39 行定义.

39 {
40 const double l = Length();
41 if (l > kMathEpsilon) {
42 x_ /= l;
43 y_ /= l;
44 }
45}
double Length() const
Gets the length of the vector
Definition vec2d.cc:33
constexpr double kMathEpsilon
Definition vec2d.h:35

◆ operator*()

Vec2d apollo::common::math::Vec2d::operator* ( const double  ratio) const

Multiplies Vec2d by a scalar

在文件 vec2d.cc84 行定义.

84 {
85 return Vec2d(x_ * ratio, y_ * ratio);
86}

◆ operator*=()

Vec2d & apollo::common::math::Vec2d::operator*= ( const double  ratio)

Multiplies this Vec2d by a scalar

在文件 vec2d.cc105 行定义.

105 {
106 x_ *= ratio;
107 y_ *= ratio;
108 return *this;
109}

◆ operator+()

Vec2d apollo::common::math::Vec2d::operator+ ( const Vec2d other) const

Sums two Vec2d

在文件 vec2d.cc76 行定义.

76 {
77 return Vec2d(x_ + other.x(), y_ + other.y());
78}

◆ operator+=()

Vec2d & apollo::common::math::Vec2d::operator+= ( const Vec2d other)

Sums another Vec2d to the current one

在文件 vec2d.cc93 行定义.

93 {
94 x_ += other.x();
95 y_ += other.y();
96 return *this;
97}

◆ operator-()

Vec2d apollo::common::math::Vec2d::operator- ( const Vec2d other) const

Subtracts two Vec2d

在文件 vec2d.cc80 行定义.

80 {
81 return Vec2d(x_ - other.x(), y_ - other.y());
82}

◆ operator-=()

Vec2d & apollo::common::math::Vec2d::operator-= ( const Vec2d other)

Subtracts another Vec2d to the current one

在文件 vec2d.cc99 行定义.

99 {
100 x_ -= other.x();
101 y_ -= other.y();
102 return *this;
103}

◆ operator/()

Vec2d apollo::common::math::Vec2d::operator/ ( const double  ratio) const

Divides Vec2d by a scalar

在文件 vec2d.cc88 行定义.

88 {
89 CHECK_GT(std::abs(ratio), kMathEpsilon);
90 return Vec2d(x_ / ratio, y_ / ratio);
91}

◆ operator/=()

Vec2d & apollo::common::math::Vec2d::operator/= ( const double  ratio)

Divides this Vec2d by a scalar

在文件 vec2d.cc111 行定义.

111 {
112 CHECK_GT(std::abs(ratio), kMathEpsilon);
113 x_ /= ratio;
114 y_ /= ratio;
115 return *this;
116}

◆ operator==()

bool apollo::common::math::Vec2d::operator== ( const Vec2d other) const

Compares two Vec2d

在文件 vec2d.cc118 行定义.

118 {
119 return (std::abs(x_ - other.x()) < kMathEpsilon &&
120 std::abs(y_ - other.y()) < kMathEpsilon);
121}

◆ rotate()

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

rotate the vector by angle.

在文件 vec2d.cc65 行定义.

65 {
66 return Vec2d(x_ * cos(angle) - y_ * sin(angle),
67 x_ * sin(angle) + y_ * cos(angle));
68}
float cos(Angle16 a)
Definition angle.cc:42
float sin(Angle16 a)
Definition angle.cc:25

◆ SelfRotate()

void apollo::common::math::Vec2d::SelfRotate ( const double  angle)

rotate the vector itself by angle.

在文件 vec2d.cc70 行定义.

70 {
71 double tmp_x = x_;
72 x_ = x_ * cos(angle) - y_ * sin(angle);
73 y_ = tmp_x * sin(angle) + y_ * cos(angle);
74}

◆ set_x()

void apollo::common::math::Vec2d::set_x ( const double  x)
inline

Setter for x component

在文件 vec2d.h60 行定义.

60{ x_ = x; }

◆ set_y()

void apollo::common::math::Vec2d::set_y ( const double  y)
inline

Setter for y component

在文件 vec2d.h63 行定义.

63{ y_ = y; }

◆ x()

double apollo::common::math::Vec2d::x ( ) const
inline

Getter for x component

在文件 vec2d.h54 行定义.

54{ return x_; }

◆ y()

double apollo::common::math::Vec2d::y ( ) const
inline

Getter for y component

在文件 vec2d.h57 行定义.

57{ return y_; }

类成员变量说明

◆ x_

double apollo::common::math::Vec2d::x_ = 0.0
protected

在文件 vec2d.h126 行定义.

◆ y_

double apollo::common::math::Vec2d::y_ = 0.0
protected

在文件 vec2d.h127 行定义.


该类的文档由以下文件生成: