All Classes Namespaces Files Functions Variables Typedefs Pages
Definitions.h
Go to the documentation of this file.
1 /*
2  * Definitions.h
3  *
4  *
5  * All rights are retained by the authors and the University of Minnesota.
6  * Please contact sjguy@cs.umn.edu for licensing inquiries.
7  *
8  * Authors: Ioannis Karamouzas, Brian Skinner, and Stephen J. Guy
9  * Contact: ioannis@cs.umn.edu
10  */
11 
16 #pragma once
17 #include "Vector2D.h"
18 #include <vector>
19 #include <algorithm>
20 
21 namespace TTC {
22 
23 
24  #define _INFTY 9e9f
25 
26  #define _EPSILON 0.00001f
27 
28  #define _M_PI 3.14159265358979323846f
29 
30 
36  inline float Sqr(float a) {return a*a;}
37 
38 
45  inline Vector2D closestPointLineSegment (const Vector2D &line_start,const Vector2D &line_end, const Vector2D &p)
46  {
47  float dota =(p-line_start) * (line_end - line_start);
48  if (dota <= 0) // point line_start is closest to p
49  return line_start;
50 
51  float dotb = (p-line_end)*(line_start - line_end);
52  if (dotb <= 0) // point line_end is closest to p
53  return line_end;
54 
55  // find closest point
56  float slope = dota/(dota+dotb);
57  return line_start + (line_end - line_start)*slope;
58  }
59 
60 }
Contains the Vector2D class; a two-dimensional vector class and related vector operations.
float Sqr(float a)
The square of a value.
Definition: Definitions.h:36
Vector2D closestPointLineSegment(const Vector2D &line_start, const Vector2D &line_end, const Vector2D &p)
Determine the closest point on a line segment given a test point.
Definition: Definitions.h:45
A two-dimensional vector class.
Definition: Vector2D.h:28