31 const float l = std::sqrt(l2);
37 const float dot_p_w =
Dot2D(p - v, w - v);
39 const float t =
Clamp(dot_p_w / l2);
41 const Vector3D projection = v + t * (w - v);
43 return std::make_pair(t * l,
Distance2D(projection, p));
60 start_pos.
y = -start_pos.
y;
62 curvature = -curvature;
66 if (curvature < 0.0f) {
68 start_pos.
y = -start_pos.
y;
70 curvature = -curvature;
78 const float radius = 1.0f / curvature;
80 const Vector3D circ_center(0.0f, radius, 0.0f);
85 if (rotated_p == circ_center) {
86 return std::make_pair(0.0f, radius);
91 const Vector3D intersection = ((rotated_p - circ_center).MakeUnitVector() * radius) + circ_center;
95 const float last_point_angle = length / radius;
97 constexpr float pi_half = Pi<float>() / 2.0f;
102 float angle = std::atan2(intersection.
y - radius, intersection.
x) + pi_half;
106 angle += Pi<float>() * 2.0f;
112 if (angle <= last_point_angle) {
113 return std::make_pair(
124 radius * std::cos(last_point_angle - pi_half),
125 radius * std::sin(last_point_angle - pi_half) + circ_center.
y,
128 const float end_dist =
Distance2D(end_pos, rotated_p);
131 return (start_dist < end_dist)?
132 std::make_pair(0.0f, start_dist) :
133 std::make_pair(length, end_dist);
139 const float s = std::sin(angle);
140 const float c = std::cos(angle);
141 return Vector3D(p.
x * c - p.
y * s, p.
x * s + p.
y * c, 0.0f);
152 return {cy * cp, sy * cp, sp};
166 cy * sp * sr - sy *
cr,
167 sy * sp * sr + cy *
cr,
181 -cy * sp *
cr - sy * sr,
182 -sy * sp *
cr + cy * sr,
192 std::vector<int> result;
195 for(
int i = a; i <= b; ++i) {
199 for(
int i = a; i >= b; --i) {
#define DEBUG_ASSERT(predicate)
static auto DistanceSquared2D(const Vector3D &a, const Vector3D &b)
static Vector3D GetRightVector(const Rotation &rotation)
计算指向 rotation 的 Y 轴的单位向量
static constexpr T ToRadians(T deg)
static double GetVectorAngle(const Vector3D &a, const Vector3D &b)
返回两个向量之间的夹角(弧度)
static Vector3D GetUpVector(const Rotation &rotation)
计算指向 rotation 的 Z 轴的单位向量
static auto Distance2D(const Vector3D &a, const Vector3D &b)
static std::vector< int > GenerateRange(int a, int b)
static Vector3D RotatePointOnOrigin2D(Vector3D p, float angle)
static T Clamp(T a, T min=T(0), T max=T(1))
static auto Dot(const Vector3D &a, const Vector3D &b)
static Vector3D GetForwardVector(const Rotation &rotation)
计算指向 rotation 的 X 轴的单位向量
static std::pair< float, float > DistanceSegmentToPoint(const Vector3D &p, const Vector3D &v, const Vector3D &w)
计算点到线段的距离 返回一个包含:
static auto Dot2D(const Vector3D &a, const Vector3D &b)
static std::pair< float, float > DistanceArcToPoint(Vector3D p, Vector3D start_pos, float length, float heading, float curvature)
计算点到弧的距离 返回一个包含: