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

Rectangular (undirected) bounding box in 2-D. 更多...

#include <box2d.h>

apollo::common::math::Box2d 的协作图:

Public 成员函数

 Box2d ()=default
 
 Box2d (const Vec2d &center, const double heading, const double length, const double width)
 Constructor which takes the center, heading, length and width.
 
 Box2d (const Vec2d &point, double heading, double front_length, double back_length, double width)
 Constructor which takes the point on the axis, front length, back length, heading, and width.
 
 Box2d (const LineSegment2d &axis, const double width)
 Constructor which takes the heading-axis and the width of the box
 
 Box2d (const AABox2d &aabox)
 Constructor which takes an AABox2d (axes-aligned box).
 
const Vec2dcenter () const
 Getter of the center of the box
 
double center_x () const
 Getter of the x-coordinate of the center of the box
 
double center_y () const
 Getter of the y-coordinate of the center of the box
 
double length () const
 Getter of the length
 
double width () const
 Getter of the width
 
double half_length () const
 Getter of half the length
 
double half_width () const
 Getter of half the width
 
double heading () const
 Getter of the heading
 
double cos_heading () const
 Getter of the cosine of the heading
 
double sin_heading () const
 Getter of the sine of the heading
 
double area () const
 Getter of the area of the box
 
double diagonal () const
 Getter of the size of the diagonal of the box
 
void GetAllCorners (std::vector< Vec2d > *const corners) const
 Getter of the corners of the box
 
const std::vector< Vec2d > & GetAllCorners () const
 Getter of the corners of the box
 
bool IsPointIn (const Vec2d &point) const
 Tests points for membership in the box
 
bool IsPointOnBoundary (const Vec2d &point) const
 Tests points for membership in the boundary of the box
 
double DistanceTo (const Vec2d &point) const
 Determines the distance between the box and a given point
 
double DistanceTo (const LineSegment2d &line_segment) const
 Determines the distance between the box and a given line segment
 
double DistanceTo (const Box2d &box) const
 Determines the distance between two boxes
 
bool HasOverlap (const LineSegment2d &line_segment) const
 Determines whether this box overlaps a given line segment
 
bool HasOverlap (const Box2d &box) const
 Determines whether these two boxes overlap
 
AABox2d GetAABox () const
 Gets the smallest axes-aligned box containing the current one
 
void RotateFromCenter (const double rotate_angle)
 Rotate from center.
 
void Shift (const Vec2d &shift_vec)
 Shifts this box by a given vector
 
void LongitudinalExtend (const double extension_length)
 Extend the box longitudinally
 
void LateralExtend (const double extension_length)
 
std::string DebugString () const
 Gets a human-readable description of the box
 
void InitCorners ()
 
double max_x () const
 
double min_x () const
 
double max_y () const
 
double min_y () const
 

静态 Public 成员函数

static Box2d CreateAABox (const Vec2d &one_corner, const Vec2d &opposite_corner)
 Creates an axes-aligned Box2d from two opposite corners
 

详细描述

Rectangular (undirected) bounding box in 2-D.

This class is referential-agnostic, although our convention on the use of the word "heading" in this project (permanently set to be 0 at East) forces us to assume that the X/Y frame here is East/North. For disambiguation, we call the axis of the rectangle parallel to the heading direction the "heading-axis". The size of the heading-axis is called "length", and the size of the axis perpendicular to it "width".

在文件 box2d.h52 行定义.

构造及析构函数说明

◆ Box2d() [1/5]

apollo::common::math::Box2d::Box2d ( )
default

◆ Box2d() [2/5]

apollo::common::math::Box2d::Box2d ( const Vec2d center,
const double  heading,
const double  length,
const double  width 
)

Constructor which takes the center, heading, length and width.

参数
centerThe center of the rectangular bounding box.
headingThe angle between the x-axis and the heading-axis, measured counter-clockwise.
lengthThe size of the heading-axis.
widthThe size of the axis perpendicular to the heading-axis.

在文件 box2d.cc53 行定义.

55 : center_(center),
56 length_(length),
57 width_(width),
58 half_length_(length / 2.0),
59 half_width_(width / 2.0),
60 heading_(heading),
61 cos_heading_(cos(heading)),
62 sin_heading_(sin(heading)) {
63 CHECK_GT(length_, -kMathEpsilon);
64 CHECK_GT(width_, -kMathEpsilon);
66}
double width() const
Getter of the width
Definition box2d.h:130
const Vec2d & center() const
Getter of the center of the box
Definition box2d.h:106
double length() const
Getter of the length
Definition box2d.h:124
double heading() const
Getter of the heading
Definition box2d.h:148
float cos(Angle16 a)
Definition angle.cc:42
constexpr double kMathEpsilon
Definition vec2d.h:35
float sin(Angle16 a)
Definition angle.cc:25

◆ Box2d() [3/5]

apollo::common::math::Box2d::Box2d ( const Vec2d point,
double  heading,
double  front_length,
double  back_length,
double  width 
)

Constructor which takes the point on the axis, front length, back length, heading, and width.

参数
centerThe center of the rectangular bounding box.
headingThe angle between the x-axis and the heading-axis, measured counter-clockwise.
front_lengthThe length from the start point to the given point.
back_lengthThe length from the end point to the given point.
widthThe size of the axis perpendicular to the heading-axis.

在文件 box2d.cc68 行定义.

70 : length_(front_length + back_length),
71 width_(width),
72 half_length_(length_ / 2.0),
73 half_width_(width / 2.0),
74 heading_(heading),
75 cos_heading_(cos(heading)),
76 sin_heading_(sin(heading)) {
77 CHECK_GT(length_, -kMathEpsilon);
78 CHECK_GT(width_, -kMathEpsilon);
79 double delta_length = (front_length - back_length) / 2.0;
80 center_ = Vec2d(point.x() + cos_heading_ * delta_length,
81 point.y() + sin_heading_ * delta_length);
83}

◆ Box2d() [4/5]

apollo::common::math::Box2d::Box2d ( const LineSegment2d axis,
const double  width 
)

Constructor which takes the heading-axis and the width of the box

参数
axisThe heading-axis
widthThe width of the box, which is taken perpendicularly to the heading direction.

在文件 box2d.cc85 行定义.

86 : center_(axis.center()),
87 length_(axis.length()),
88 width_(width),
89 half_length_(axis.length() / 2.0),
90 half_width_(width / 2.0),
91 heading_(axis.heading()),
92 cos_heading_(axis.cos_heading()),
93 sin_heading_(axis.sin_heading()) {
94 CHECK_GT(length_, -kMathEpsilon);
95 CHECK_GT(width_, -kMathEpsilon);
97}

◆ Box2d() [5/5]

apollo::common::math::Box2d::Box2d ( const AABox2d aabox)
explicit

Constructor which takes an AABox2d (axes-aligned box).

参数
aaboxThe input AABox2d.

在文件 box2d.cc118 行定义.

119 : center_(aabox.center()),
120 length_(aabox.length()),
121 width_(aabox.width()),
122 half_length_(aabox.half_length()),
123 half_width_(aabox.half_width()),
124 heading_(0.0),
125 cos_heading_(1.0),
126 sin_heading_(0.0) {
127 CHECK_GT(length_, -kMathEpsilon);
128 CHECK_GT(width_, -kMathEpsilon);
129}

成员函数说明

◆ area()

double apollo::common::math::Box2d::area ( ) const
inline

Getter of the area of the box

返回
The product of its length and width

在文件 box2d.h166 行定义.

166{ return length_ * width_; }

◆ center()

const Vec2d & apollo::common::math::Box2d::center ( ) const
inline

Getter of the center of the box

返回
The center of the box

在文件 box2d.h106 行定义.

106{ return center_; }

◆ center_x()

double apollo::common::math::Box2d::center_x ( ) const
inline

Getter of the x-coordinate of the center of the box

返回
The x-coordinate of the center of the box

在文件 box2d.h112 行定义.

112{ return center_.x(); }
double x() const
Getter for x component
Definition vec2d.h:54

◆ center_y()

double apollo::common::math::Box2d::center_y ( ) const
inline

Getter of the y-coordinate of the center of the box

返回
The y-coordinate of the center of the box

在文件 box2d.h118 行定义.

118{ return center_.y(); }
double y() const
Getter for y component
Definition vec2d.h:57

◆ cos_heading()

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

Getter of the cosine of the heading

返回
The cosine of the heading

在文件 box2d.h154 行定义.

154{ return cos_heading_; }

◆ CreateAABox()

Box2d apollo::common::math::Box2d::CreateAABox ( const Vec2d one_corner,
const Vec2d opposite_corner 
)
static

Creates an axes-aligned Box2d from two opposite corners

参数
one_cornerOne of the corners
opposite_cornerThe opposite corner to the first one
返回
An axes-aligned Box2d

在文件 box2d.cc131 行定义.

132 {
133 const double x1 = std::min(one_corner.x(), opposite_corner.x());
134 const double x2 = std::max(one_corner.x(), opposite_corner.x());
135 const double y1 = std::min(one_corner.y(), opposite_corner.y());
136 const double y2 = std::max(one_corner.y(), opposite_corner.y());
137 return Box2d({(x1 + x2) / 2.0, (y1 + y2) / 2.0}, 0.0, x2 - x1, y2 - y1);
138}

◆ DebugString()

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

Gets a human-readable description of the box

返回
A debug-string

在文件 box2d.cc418 行定义.

418 {
419 return absl::StrCat("box2d ( center = ", center_.DebugString(),
420 " heading = ", heading_, " length = ", length_,
421 " width = ", width_, " )");
422}
std::string DebugString() const
Returns a human-readable string representing this object
Definition vec2d.cc:125

◆ diagonal()

double apollo::common::math::Box2d::diagonal ( ) const
inline

Getter of the size of the diagonal of the box

返回
The diagonal size of the box

在文件 box2d.h172 行定义.

172{ return std::hypot(length_, width_); }

◆ DistanceTo() [1/3]

double apollo::common::math::Box2d::DistanceTo ( const Box2d box) const

Determines the distance between two boxes

参数
boxThe box whose distance to this box we want to compute
返回
A distance

在文件 box2d.cc338 行定义.

338 {
339 return Polygon2d(box).DistanceTo(*this);
340}

◆ DistanceTo() [2/3]

double apollo::common::math::Box2d::DistanceTo ( const LineSegment2d line_segment) const

Determines the distance between the box and a given line segment

参数
line_segmentThe line segment whose distance to the box we compute
返回
A distance

在文件 box2d.cc244 行定义.

244 {
245 if (line_segment.length() <= kMathEpsilon) {
246 return DistanceTo(line_segment.start());
247 }
248 const double ref_x1 = line_segment.start().x() - center_.x();
249 const double ref_y1 = line_segment.start().y() - center_.y();
250 double x1 = ref_x1 * cos_heading_ + ref_y1 * sin_heading_;
251 double y1 = ref_x1 * sin_heading_ - ref_y1 * cos_heading_;
252 double box_x = half_length_;
253 double box_y = half_width_;
254 int gx1 = (x1 >= box_x ? 1 : (x1 <= -box_x ? -1 : 0));
255 int gy1 = (y1 >= box_y ? 1 : (y1 <= -box_y ? -1 : 0));
256 if (gx1 == 0 && gy1 == 0) {
257 return 0.0;
258 }
259 const double ref_x2 = line_segment.end().x() - center_.x();
260 const double ref_y2 = line_segment.end().y() - center_.y();
261 double x2 = ref_x2 * cos_heading_ + ref_y2 * sin_heading_;
262 double y2 = ref_x2 * sin_heading_ - ref_y2 * cos_heading_;
263 int gx2 = (x2 >= box_x ? 1 : (x2 <= -box_x ? -1 : 0));
264 int gy2 = (y2 >= box_y ? 1 : (y2 <= -box_y ? -1 : 0));
265 if (gx2 == 0 && gy2 == 0) {
266 return 0.0;
267 }
268 if (gx1 < 0 || (gx1 == 0 && gx2 < 0)) {
269 x1 = -x1;
270 gx1 = -gx1;
271 x2 = -x2;
272 gx2 = -gx2;
273 }
274 if (gy1 < 0 || (gy1 == 0 && gy2 < 0)) {
275 y1 = -y1;
276 gy1 = -gy1;
277 y2 = -y2;
278 gy2 = -gy2;
279 }
280 if (gx1 < gy1 || (gx1 == gy1 && gx2 < gy2)) {
281 std::swap(x1, y1);
282 std::swap(gx1, gy1);
283 std::swap(x2, y2);
284 std::swap(gx2, gy2);
285 std::swap(box_x, box_y);
286 }
287 if (gx1 == 1 && gy1 == 1) {
288 switch (gx2 * 3 + gy2) {
289 case 4:
290 return PtSegDistance(box_x, box_y, x1, y1, x2, y2,
291 line_segment.length());
292 case 3:
293 return (x1 > x2) ? (x2 - box_x)
294 : PtSegDistance(box_x, box_y, x1, y1, x2, y2,
295 line_segment.length());
296 case 2:
297 return (x1 > x2) ? PtSegDistance(box_x, -box_y, x1, y1, x2, y2,
298 line_segment.length())
299 : PtSegDistance(box_x, box_y, x1, y1, x2, y2,
300 line_segment.length());
301 case -1:
302 return CrossProd({x1, y1}, {x2, y2}, {box_x, -box_y}) >= 0.0
303 ? 0.0
304 : PtSegDistance(box_x, -box_y, x1, y1, x2, y2,
305 line_segment.length());
306 case -4:
307 return CrossProd({x1, y1}, {x2, y2}, {box_x, -box_y}) <= 0.0
308 ? PtSegDistance(box_x, -box_y, x1, y1, x2, y2,
309 line_segment.length())
310 : (CrossProd({x1, y1}, {x2, y2}, {-box_x, box_y}) <= 0.0
311 ? 0.0
312 : PtSegDistance(-box_x, box_y, x1, y1, x2, y2,
313 line_segment.length()));
314 }
315 } else {
316 switch (gx2 * 3 + gy2) {
317 case 4:
318 return (x1 < x2) ? (x1 - box_x)
319 : PtSegDistance(box_x, box_y, x1, y1, x2, y2,
320 line_segment.length());
321 case 3:
322 return std::min(x1, x2) - box_x;
323 case 1:
324 case -2:
325 return CrossProd({x1, y1}, {x2, y2}, {box_x, box_y}) <= 0.0
326 ? 0.0
327 : PtSegDistance(box_x, box_y, x1, y1, x2, y2,
328 line_segment.length());
329 case -3:
330 return 0.0;
331 }
332 }
333 ACHECK(0) << "unimplemented state: " << gx1 << " " << gy1 << " " << gx2 << " "
334 << gy2;
335 return 0.0;
336}
double DistanceTo(const Vec2d &point) const
Determines the distance between the box and a given point
Definition box2d.cc:168
#define ACHECK(cond)
Definition log.h:80
double CrossProd(const Vec2d &start_point, const Vec2d &end_point_1, const Vec2d &end_point_2)
Cross product between two 2-D vectors from the common start point, and end at two other points.
Definition math_utils.cc:28

◆ DistanceTo() [3/3]

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

Determines the distance between the box and a given point

参数
pointThe point whose distance to the box we wish to compute
返回
A distance

在文件 box2d.cc168 行定义.

168 {
169 const double x0 = point.x() - center_.x();
170 const double y0 = point.y() - center_.y();
171 const double dx =
172 std::abs(x0 * cos_heading_ + y0 * sin_heading_) - half_length_;
173 const double dy =
174 std::abs(x0 * sin_heading_ - y0 * cos_heading_) - half_width_;
175 if (dx <= 0.0) {
176 return std::max(0.0, dy);
177 }
178 if (dy <= 0.0) {
179 return dx;
180 }
181 return hypot(dx, dy);
182}

◆ GetAABox()

AABox2d apollo::common::math::Box2d::GetAABox ( ) const

Gets the smallest axes-aligned box containing the current one

返回
An axes-aligned box

在文件 box2d.cc378 行定义.

378 {
379 const double dx1 = std::abs(cos_heading_ * half_length_);
380 const double dy1 = std::abs(sin_heading_ * half_length_);
381 const double dx2 = std::abs(sin_heading_ * half_width_);
382 const double dy2 = std::abs(cos_heading_ * half_width_);
383 return AABox2d(center_, (dx1 + dx2) * 2.0, (dy1 + dy2) * 2.0);
384}

◆ GetAllCorners() [1/2]

const std::vector< Vec2d > & apollo::common::math::Box2d::GetAllCorners ( ) const

Getter of the corners of the box

参数
cornersThe vector where the corners are listed

在文件 box2d.cc147 行定义.

147{ return corners_; }

◆ GetAllCorners() [2/2]

void apollo::common::math::Box2d::GetAllCorners ( std::vector< Vec2d > *const  corners) const

Getter of the corners of the box

参数
cornersThe vector where the corners are listed

在文件 box2d.cc140 行定义.

140 {
141 if (corners == nullptr) {
142 return;
143 }
144 *corners = corners_;
145}

◆ half_length()

double apollo::common::math::Box2d::half_length ( ) const
inline

Getter of half the length

返回
Half the length of the heading-axis

在文件 box2d.h136 行定义.

136{ return half_length_; }

◆ half_width()

double apollo::common::math::Box2d::half_width ( ) const
inline

Getter of half the width

返回
Half the width of the box taken perpendicularly to the heading

在文件 box2d.h142 行定义.

142{ return half_width_; }

◆ HasOverlap() [1/2]

bool apollo::common::math::Box2d::HasOverlap ( const Box2d box) const

Determines whether these two boxes overlap

参数
line_segmentThe other box
返回
True if they overlap

在文件 box2d.cc342 行定义.

342 {
343 if (box.max_x() < min_x() || box.min_x() > max_x() || box.max_y() < min_y() ||
344 box.min_y() > max_y()) {
345 return false;
346 }
347
348 const double shift_x = box.center_x() - center_.x();
349 const double shift_y = box.center_y() - center_.y();
350
351 const double dx1 = cos_heading_ * half_length_;
352 const double dy1 = sin_heading_ * half_length_;
353 const double dx2 = sin_heading_ * half_width_;
354 const double dy2 = -cos_heading_ * half_width_;
355 const double dx3 = box.cos_heading() * box.half_length();
356 const double dy3 = box.sin_heading() * box.half_length();
357 const double dx4 = box.sin_heading() * box.half_width();
358 const double dy4 = -box.cos_heading() * box.half_width();
359
360 return std::abs(shift_x * cos_heading_ + shift_y * sin_heading_) <=
361 std::abs(dx3 * cos_heading_ + dy3 * sin_heading_) +
362 std::abs(dx4 * cos_heading_ + dy4 * sin_heading_) +
363 half_length_ &&
364 std::abs(shift_x * sin_heading_ - shift_y * cos_heading_) <=
365 std::abs(dx3 * sin_heading_ - dy3 * cos_heading_) +
366 std::abs(dx4 * sin_heading_ - dy4 * cos_heading_) +
367 half_width_ &&
368 std::abs(shift_x * box.cos_heading() + shift_y * box.sin_heading()) <=
369 std::abs(dx1 * box.cos_heading() + dy1 * box.sin_heading()) +
370 std::abs(dx2 * box.cos_heading() + dy2 * box.sin_heading()) +
371 box.half_length() &&
372 std::abs(shift_x * box.sin_heading() - shift_y * box.cos_heading()) <=
373 std::abs(dx1 * box.sin_heading() - dy1 * box.cos_heading()) +
374 std::abs(dx2 * box.sin_heading() - dy2 * box.cos_heading()) +
375 box.half_width();
376}
double min_y() const
Definition box2d.h:272
double min_x() const
Definition box2d.h:270
double max_y() const
Definition box2d.h:271
double max_x() const
Definition box2d.h:269

◆ HasOverlap() [2/2]

bool apollo::common::math::Box2d::HasOverlap ( const LineSegment2d line_segment) const

Determines whether this box overlaps a given line segment

参数
line_segmentThe line-segment
返回
True if they overlap

在文件 box2d.cc184 行定义.

184 {
185 if (line_segment.length() <= kMathEpsilon) {
186 return IsPointIn(line_segment.start());
187 }
188 if (std::fmax(line_segment.start().x(), line_segment.end().x()) < min_x() ||
189 std::fmin(line_segment.start().x(), line_segment.end().x()) > max_x() ||
190 std::fmax(line_segment.start().y(), line_segment.end().y()) < min_y() ||
191 std::fmin(line_segment.start().y(), line_segment.end().y()) > max_y()) {
192 return false;
193 }
194 // Construct coordinate system with origin point as left_bottom corner of
195 // Box2d, y axis along direction of heading.
196 Vec2d x_axis(sin_heading_, -cos_heading_);
197 Vec2d y_axis(cos_heading_, sin_heading_);
198 // corners_[2] is the left bottom point of the box.
199 Vec2d start_v = line_segment.start() - corners_[2];
200 // "start_point" is the start point of "line_segment" mapped in the new
201 // coordinate system.
202 Vec2d start_point(start_v.InnerProd(x_axis), start_v.InnerProd(y_axis));
203 // Check if "start_point" is inside the box.
204 if (is_inside_rectangle(start_point)) {
205 return true;
206 }
207 // Check if "end_point" is inside the box.
208 Vec2d end_v = line_segment.end() - corners_[2];
209 Vec2d end_point(end_v.InnerProd(x_axis), end_v.InnerProd(y_axis));
210 if (is_inside_rectangle(end_point)) {
211 return true;
212 }
213 // Exclude the case when the 2 points of "line_segment" are at the same side
214 // of rectangle.
215 if ((start_point.x() < 0.0) && (end_point.x() < 0.0)) {
216 return false;
217 }
218 if ((start_point.y() < 0.0) && (end_point.y() < 0.0)) {
219 return false;
220 }
221 if ((start_point.x() > width_) && (end_point.x() > width_)) {
222 return false;
223 }
224 if ((start_point.y() > length_) && (end_point.y() > length_)) {
225 return false;
226 }
227 // Check if "line_segment" intersects with box.
228 Vec2d line_direction = line_segment.end() - line_segment.start();
229 Vec2d normal_vec(line_direction.y(), -line_direction.x());
230 Vec2d p1 = center_ - line_segment.start();
231 Vec2d diagonal_vec = center_ - corners_[0];
232 // if project_p1 < projection of diagonal, "line_segment" intersects with box.
233 double project_p1 = fabs(p1.InnerProd(normal_vec));
234 if (fabs(diagonal_vec.InnerProd(normal_vec)) >= project_p1) {
235 return true;
236 }
237 diagonal_vec = center_ - corners_[1];
238 if (fabs(diagonal_vec.InnerProd(normal_vec)) >= project_p1) {
239 return true;
240 }
241 return false;
242}
bool IsPointIn(const Vec2d &point) const
Tests points for membership in the box
Definition box2d.cc:149

◆ heading()

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

Getter of the heading

返回
The counter-clockwise angle between the x-axis and the heading-axis

在文件 box2d.h148 行定义.

148{ return heading_; }

◆ InitCorners()

void apollo::common::math::Box2d::InitCorners ( )

在文件 box2d.cc99 行定义.

99 {
100 const double dx1 = cos_heading_ * half_length_;
101 const double dy1 = sin_heading_ * half_length_;
102 const double dx2 = sin_heading_ * half_width_;
103 const double dy2 = -cos_heading_ * half_width_;
104 corners_.clear();
105 corners_.emplace_back(center_.x() + dx1 + dx2, center_.y() + dy1 + dy2);
106 corners_.emplace_back(center_.x() + dx1 - dx2, center_.y() + dy1 - dy2);
107 corners_.emplace_back(center_.x() - dx1 - dx2, center_.y() - dy1 - dy2);
108 corners_.emplace_back(center_.x() - dx1 + dx2, center_.y() - dy1 + dy2);
109
110 for (auto &corner : corners_) {
111 max_x_ = std::fmax(corner.x(), max_x_);
112 min_x_ = std::fmin(corner.x(), min_x_);
113 max_y_ = std::fmax(corner.y(), max_y_);
114 min_y_ = std::fmin(corner.y(), min_y_);
115 }
116}

◆ IsPointIn()

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

Tests points for membership in the box

参数
pointA point that we wish to test for membership in the box
返回
True iff the point is contained in the box

在文件 box2d.cc149 行定义.

149 {
150 const double x0 = point.x() - center_.x();
151 const double y0 = point.y() - center_.y();
152 const double dx = std::abs(x0 * cos_heading_ + y0 * sin_heading_);
153 const double dy = std::abs(-x0 * sin_heading_ + y0 * cos_heading_);
154 return dx <= half_length_ + kMathEpsilon && dy <= half_width_ + kMathEpsilon;
155}

◆ IsPointOnBoundary()

bool apollo::common::math::Box2d::IsPointOnBoundary ( const Vec2d point) const

Tests points for membership in the boundary of the box

参数
pointA point that we wish to test for membership in the boundary
返回
True iff the point is a boundary point of the box

在文件 box2d.cc157 行定义.

157 {
158 const double x0 = point.x() - center_.x();
159 const double y0 = point.y() - center_.y();
160 const double dx = std::abs(x0 * cos_heading_ + y0 * sin_heading_);
161 const double dy = std::abs(x0 * sin_heading_ - y0 * cos_heading_);
162 return (std::abs(dx - half_length_) <= kMathEpsilon &&
163 dy <= half_width_ + kMathEpsilon) ||
164 (std::abs(dy - half_width_) <= kMathEpsilon &&
165 dx <= half_length_ + kMathEpsilon);
166}

◆ LateralExtend()

void apollo::common::math::Box2d::LateralExtend ( const double  extension_length)

在文件 box2d.cc412 行定义.

412 {
413 width_ += extension_length;
414 half_width_ += extension_length / 2.0;
415 InitCorners();
416}

◆ length()

double apollo::common::math::Box2d::length ( ) const
inline

Getter of the length

返回
The length of the heading-axis

在文件 box2d.h124 行定义.

124{ return length_; }

◆ LongitudinalExtend()

void apollo::common::math::Box2d::LongitudinalExtend ( const double  extension_length)

Extend the box longitudinally

参数
extension_lengththe length to extend

在文件 box2d.cc406 行定义.

406 {
407 length_ += extension_length;
408 half_length_ += extension_length / 2.0;
409 InitCorners();
410}

◆ max_x()

double apollo::common::math::Box2d::max_x ( ) const
inline

在文件 box2d.h269 行定义.

269{ return max_x_; }

◆ max_y()

double apollo::common::math::Box2d::max_y ( ) const
inline

在文件 box2d.h271 行定义.

271{ return max_y_; }

◆ min_x()

double apollo::common::math::Box2d::min_x ( ) const
inline

在文件 box2d.h270 行定义.

270{ return min_x_; }

◆ min_y()

double apollo::common::math::Box2d::min_y ( ) const
inline

在文件 box2d.h272 行定义.

272{ return min_y_; }

◆ RotateFromCenter()

void apollo::common::math::Box2d::RotateFromCenter ( const double  rotate_angle)

Rotate from center.

参数
rotate_angleAngle to rotate.

在文件 box2d.cc386 行定义.

386 {
387 heading_ = NormalizeAngle(heading_ + rotate_angle);
388 cos_heading_ = std::cos(heading_);
389 sin_heading_ = std::sin(heading_);
390 InitCorners();
391}
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
Definition math_utils.cc:53

◆ Shift()

void apollo::common::math::Box2d::Shift ( const Vec2d shift_vec)

Shifts this box by a given vector

参数
shift_vecThe vector determining the shift

在文件 box2d.cc393 行定义.

393 {
394 center_ += shift_vec;
395 for (size_t i = 0; i < 4; ++i) {
396 corners_[i] += shift_vec;
397 }
398 for (auto &corner : corners_) {
399 max_x_ = std::fmax(corner.x(), max_x_);
400 min_x_ = std::fmin(corner.x(), min_x_);
401 max_y_ = std::fmax(corner.y(), max_y_);
402 min_y_ = std::fmin(corner.y(), min_y_);
403 }
404}

◆ sin_heading()

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

Getter of the sine of the heading

返回
The sine of the heading

在文件 box2d.h160 行定义.

160{ return sin_heading_; }

◆ width()

double apollo::common::math::Box2d::width ( ) const
inline

Getter of the width

返回
The width of the box taken perpendicularly to the heading

在文件 box2d.h130 行定义.

130{ return width_; }

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