gwnavruntime/navmesh/closestpoint.h Source File

closestpoint.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 #pragma once
8 
10 
11 namespace Kaim
12 {
13 
14 class ClosestPoint // class with static functions only
15 {
16 public:
17 // oneShape1VsShape2 = compute the closest point of Shape1 from Shape2
18 
19 // Compute the point of the Segment [ab] the is closest from the Point p
20 static void OnSegmentVsPoint2d(const Vec3f& a, const Vec3f& b, const Vec3f& p, Vec3f& closestPointOnSegment, KyFloat32& squareDist2d);
21 static void OnSegmentVsPoint2d(const CoordPos64& a, const CoordPos64& b, const CoordPos64& p, CoordPos64& closestPointOnSegment, KyInt64& squareDist2d);
22 
23 // Compute the point the Triangle [v1, v2, v3] the is closest from the Point p
24 static void OnTriangleVsPoint2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3, const Vec3f& p, Vec3f& closestPointOnTriangle, KyFloat32& squareDist2d);
25 
26 // Compute the point of the Segment [v1v2] that is the closest from the Segment[ab]
27 static void OnSegmentVsSegmentCast2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& a, const Vec3f& b,
28  const KyFloat32 distCast, Vec3f& closestPointonTriangle, KyFloat32& squareDist2d);
29 // Compute the point the Triangle [v1, v2, v3] the is closest from the Segment [ab]
30 static void OnTriangleVsSegmentCast2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3, const Vec3f& a,
31  const Vec3f& b, const KyFloat32 distCast, Vec3f& closestPointonTriangle, KyFloat32& squareDist2d);
32 
33 // Compute the point the Segment [v1v2] the is closest from the Disk (center, radius)
34 static void OnSegmentVsDiskCast2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& center, const KyFloat32 radius,
35  const Vec2f& normalizedDir2D, const KyFloat32 distCast, Vec3f& closestPointonTriangle, KyFloat32& squareDist2d);
36 // Compute the point the Triangle [v1, v2, v3] the is closest from the Disk (center, radius)
37 static void OnTriangleVsDiskCast2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3, const Vec3f& center, const KyFloat32 radius,
38  const Vec2f& normalizedDir2D, const KyFloat32 distCast, Vec3f& closestPointonTriangle, KyFloat32& squareDist2d);
39 
40 // Compute the point the Segment [v1v2] the is closest from the Cone (apex, normalizedDir2D, length, halfAngleSine)
41 static void OnSegmentVsConeCast2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& apex, const Vec2f& normalizedDir2D, KyFloat32 length,
42  const KyFloat32 halfAngleSine, Vec3f& closestPointonTriangle, KyFloat32& squareDist2d);
43 // Compute the point the Triangle [v1, v2, v3] the is closest from the Cone (apex, normalizedDir2D, length, halfAngleSine)
44 static void OnTriangleVsConeCast2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3, const Vec3f& apex, const Vec2f& normalizedDir2D,
45  KyFloat32 length, const KyFloat32 halfAngleSine, Vec3f& closestPointonTriangle, KyFloat32& squareDist2d);
46 
47 // Compute only the square distance between a segment and a point
48 static KyUInt64 GetSquareDistancePointToSegment(const CoordPos64& P, const CoordPos64& A, const CoordPos64& B, const KyInt64& sqDistAB);
49 
50 // Compute only the square distance between a segment and a point multiplied by the segment square length
51 // NOTE: Be cautious to cases where sqDistAB == 0 !
52 static KyUInt64 GetSquareDistancePointToSegmentFactorSegmentSquareLength(const CoordPos64& P, const CoordPos64& A, const CoordPos64& B, const KyInt64& sqDistAB);
53 
54 // Compute only the square distance between two segments
55 static KyUInt64 GetSquareDistanceSegmentToSegment(const CoordPos64& P, const CoordPos64& Q, const CoordPos64& A, const CoordPos64& B);
56 
57 // The same as the previous ones, but in float metrics.
58 static KyFloat32 GetSquareDistancePointToSegment(const Vec2f& P, const Vec2f& A, const Vec2f& B);
59 static KyFloat32 GetSquareDistancePointToSegment(const Vec2f& P, const Vec2f& A, const Vec2f& B, const KyFloat32& sqDistAB);
60 static KyFloat32 GetSquareDistancePointToSegmentFactorSegmentSquareLength(const Vec2f& P, const Vec2f& A, const Vec2f& B, KyFloat32 sqDistAB);
61 static KyFloat32 GetSquareDistanceSegmentToSegment(const Vec2f& P, const Vec2f& Q, const Vec2f& A, const Vec2f& B);
62 
63 static bool OnSegmentVsDisk2dIfIntersection(const Vec3f& A, const Vec3f& B, const Vec3f& C, KyFloat32 radius, Vec3f& intersection);
64 static bool OnSegmentCapsule2dIfIntersection(const Vec3f& P, const Vec3f& Q, const Vec3f& A, const Vec3f& B, KyFloat32 radius, Vec3f& intersection);
65 };
66 
67 KY_INLINE KyFloat32 ClosestPoint::GetSquareDistancePointToSegment(const Vec2f& P, const Vec2f& A, const Vec2f& B) { return GetSquareDistancePointToSegment(P, A, B, SquareDistance(A, B)); }
68 
69 }
70 
71 
std::uint64_t KyUInt64
uint64_t
Definition: types.h:30
KyFloat32 SquareDistance(const Vec2f &A, const Vec2f &B)
Returns the square of the distance between A and B.
Definition: vec2f.h:130
std::int64_t KyInt64
int64_t
Definition: types.h:25
Vec2LL CoordPos64
A type that represents the position of a point within the 2D integer grid.
Definition: navmeshtypes.h:16
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
float KyFloat32
float
Definition: types.h:32