Clutter Engine 0.0.1
Loading...
Searching...
No Matches
closest_point.inl
1
2
3namespace glm
4{
5 template<typename T, qualifier Q>
7 (
8 vec<3, T, Q> const& point,
9 vec<3, T, Q> const& a,
10 vec<3, T, Q> const& b
11 )
12 {
13 T LineLength = distance(a, b);
14 vec<3, T, Q> Vector = point - a;
15 vec<3, T, Q> LineDirection = (b - a) / LineLength;
16
17 // Project Vector to LineDirection to get the distance of point from a
18 T Distance = dot(Vector, LineDirection);
19
20 if(Distance <= T(0)) return a;
21 if(Distance >= LineLength) return b;
22 return a + LineDirection * Distance;
23 }
24
25 template<typename T, qualifier Q>
27 (
28 vec<2, T, Q> const& point,
29 vec<2, T, Q> const& a,
30 vec<2, T, Q> const& b
31 )
32 {
33 T LineLength = distance(a, b);
34 vec<2, T, Q> Vector = point - a;
35 vec<2, T, Q> LineDirection = (b - a) / LineLength;
36
37 // Project Vector to LineDirection to get the distance of point from a
38 T Distance = dot(Vector, LineDirection);
39
40 if(Distance <= T(0)) return a;
41 if(Distance >= LineLength) return b;
42 return a + LineDirection * Distance;
43 }
44
45}//namespace glm
GLM_FUNC_DECL vec< 3, T, Q > closestPointOnLine(vec< 3, T, Q > const &point, vec< 3, T, Q > const &a, vec< 3, T, Q > const &b)
Definition closest_point.inl:7
Core features
Definition common.hpp:21
Definition qualifier.hpp:35