Apollo 10.0
自动驾驶开放平台
line_segment2d.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22#pragma once
23
24#include <string>
25
27
32namespace apollo {
33namespace common {
34namespace math {
35
41 public:
46
52 LineSegment2d(const Vec2d &start, const Vec2d &end);
53
58 const Vec2d &start() const { return start_; }
59
64 const Vec2d &end() const { return end_; }
65
70 const Vec2d &unit_direction() const { return unit_direction_; }
71
76 Vec2d center() const { return (start_ + end_) / 2.0; }
77
82 Vec2d rotate(const double angle);
83
88 double heading() const { return heading_; }
89
94 double cos_heading() const { return unit_direction_.x(); }
95
100 double sin_heading() const { return unit_direction_.y(); }
101
106 double length() const;
107
112 double length_sqr() const;
113
120 double DistanceTo(const Vec2d &point) const;
121
131 double DistanceTo(const Vec2d &point, Vec2d *const nearest_pt) const;
132
140 double DistanceSquareTo(const Vec2d &point) const;
141
152 double DistanceSquareTo(const Vec2d &point, Vec2d *const nearest_pt) const;
153
159 bool IsPointIn(const Vec2d &point) const;
160
168 bool HasIntersect(const LineSegment2d &other_segment) const;
169
178 bool GetIntersect(const LineSegment2d &other_segment,
179 Vec2d *const point) const;
180
188 double ProjectOntoUnit(const Vec2d &point) const;
189
198 double ProductOntoUnit(const Vec2d &point) const;
199
208 double GetPerpendicularFoot(const Vec2d &point,
209 Vec2d *const foot_point) const;
210
215 std::string DebugString() const;
216
217 private:
218 Vec2d start_;
219 Vec2d end_;
220 Vec2d unit_direction_;
221 double heading_ = 0.0;
222 double length_ = 0.0;
223};
224
225} // namespace math
226} // namespace common
227} // namespace apollo
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.
bool HasIntersect(const LineSegment2d &other_segment) const
Check if the line segment has an intersect with another line segment in 2-D.
const Vec2d & end() const
Get the end point.
const Vec2d & unit_direction() const
Get the unit direction from the start point to the end point.
double sin_heading() const
Get the sine of the heading.
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.
double ProjectOntoUnit(const Vec2d &point) const
Compute the projection of a vector onto the line segment.
double ProductOntoUnit(const Vec2d &point) const
Compute the cross product of a vector onto the line segment.
Vec2d rotate(const double angle)
Get a new line-segment with the same start point, but rotated counterclock-wise by the given amount.
double cos_heading() const
Get the cosine of the heading.
double length() const
Get the length of the line segment.
bool GetIntersect(const LineSegment2d &other_segment, Vec2d *const point) const
Compute the intersect with another line segment in 2-D if any.
double DistanceTo(const Vec2d &point) const
Compute the shortest distance from a point on the line segment to a point in 2-D.
const Vec2d & start() const
Get the start point.
double length_sqr() const
Get the square of length of the line segment.
std::string DebugString() const
Get the debug string including the essential information.
Vec2d center() const
Get the center of the line segment.
bool IsPointIn(const Vec2d &point) const
Check if a point is within the line segment.
double heading() const
Get the heading of the line segment.
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
double y() const
Getter for y component
Definition vec2d.h:57
double x() const
Getter for x component
Definition vec2d.h:54
class register implement
Definition arena_queue.h:37
Defines the Vec2d class.