1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// OpenGL Mathematics Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
3
///////////////////////////////////////////////////////////////////////////////////////////////////
4
// Created : 2005-12-30
5
// Updated : 2008-10-05
6
// Licence : This source is under MIT License
7
// File : glm/gtx/closest_point.inl
8
///////////////////////////////////////////////////////////////////////////////////////////////////
10
#ifndef glm_gtx_closest_point
11
#define glm_gtx_closest_point
15
template <typename valType>
16
GLM_FUNC_QUALIFIER detail::tvec3<valType> closestPointOnLine
18
detail::tvec3<valType> const & point,
19
detail::tvec3<valType> const & a,
20
detail::tvec3<valType> const & b
23
valType LineLength = distance(a, b);
24
detail::tvec3<valType> Vector = point - a;
25
detail::tvec3<valType> LineDirection = (b - a) / LineLength;
27
// Project Vector to LineDirection to get the distance of point from a
28
valType Distance = dot(Vector, LineDirection);
30
if(Distance <= valType(0)) return a;
31
if(Distance >= LineLength) return b;
32
return a + LineDirection * Distance;
36
#endif//glm_gtx_closest_point