Vector.h
1 /*
2  Copyright (C) 2008 Alex Diener
3 
4  This software is provided 'as-is', without any express or implied
5  warranty. In no event will the authors be held liable for any damages
6  arising from the use of this software.
7 
8  Permission is granted to anyone to use this software for any purpose,
9  including commercial applications, and to alter it and redistribute it
10  freely, subject to the following restrictions:
11 
12  1. The origin of this software must not be misrepresented; you must not
13  claim that you wrote the original software. If you use this software
14  in a product, an acknowledgment in the product documentation would be
15  appreciated but is not required.
16  2. Altered source versions must be plainly marked as such, and must not be
17  misrepresented as being the original software.
18  3. This notice may not be removed or altered from any source distribution.
19 
20  Alex Diener adiener@sacredsoftware.net
21 */
22 
23 #ifndef __VECTOR_H__
24 #define __VECTOR_H__
25 
26 namespace VoxelFarm
27 {
29  namespace Algebra
30  {
31  typedef struct Vector Vector;
32 
34  struct Vector
35  {
36  float x;
37  float y;
38  float z;
39  };
40 
42  inline Vector Vector_withValues(float x, float y, float z)
43  {
44  Vector vector;
45  vector.x = x;
46  vector.y = y;
47  vector.z = z;
48  return vector;
49  }
50 
52  bool Vector_normalize(Vector * vector);
54  Vector Vector_normalized(Vector vector);
55 
57  float Vector_magnitude(Vector vector);
59  float Vector_magnitudeSquared(Vector vector);
61  Vector Vector_add(Vector vector1, Vector vector2);
63  Vector Vector_subtract(Vector vector1, Vector vector2);
65  float Vector_dot(Vector vector1, Vector vector2);
67  Vector Vector_cross(Vector vector1, Vector vector2);
68  Vector Vector_mutiply(float value, Vector vector);
69 
70  const double piover180 = 0.0174532925;
71  const float piover180f = 0.0174532925f;
72 
73  Vector closestPtPointTriangle(Vector p, Vector a, Vector b, Vector c);
74  bool testSphereTriangle(Vector center, float r, Vector a, Vector b, Vector c, Vector &p);
75  double sign2D(double p1x, double p1y, double p2x, double p2y, double p3x, double p3y);
76 
77  bool pointInsideTriangle3D(Vector p, Vector v0, Vector v1, Vector v2);
78  int segmentIntersectTriangle3D(Vector p0, Vector p1, Vector v0, Vector v1, Vector v2, Vector* p);
79  }
80 }
81 #endif
Vector Vector_add(Vector vector1, Vector vector2)
Returns sum of two vectors.
Vector Vector_normalized(Vector vector)
Returns normalized vector.
Contains all classes and functions for the VoxelFarm engine.
bool Vector_normalize(Vector *vector)
Normalizes vector.
A 3D Vector.
Definition: Vector.h:34
float Vector_magnitude(Vector vector)
Returns the magnitude of the vector.
Vector Vector_withValues(float x, float y, float z)
Initializes a vector.
Definition: Vector.h:42
Vector Vector_subtract(Vector vector1, Vector vector2)
Returns substraction of two vectors.
Vector Vector_cross(Vector vector1, Vector vector2)
Returns cross product between two vectors.
float Vector_magnitudeSquared(Vector vector)
Returns the squared magnitude.
float Vector_dot(Vector vector1, Vector vector2)
Returns dot product between two vectors.