1 #ifndef MATH3D_VECTOR_INLINES_H 2 #define MATH3D_VECTOR_INLINES_H 4 #include "inlinetypes.h" 11 inline void vec2_zero(vec2_t x)
17 inline void vec2_make(vec2_t x, Real a, Real b)
24 inline void vec2_equal(vec2_t x,
const vec2_t a)
31 inline void vec2_add(vec2_t x,
const vec2_t a,
const vec2_t b)
38 inline void vec2_sub(vec2_t x,
const vec2_t a,
const vec2_t b)
45 inline void vec2_multiply(vec2_t x,
const vec2_t a, Real c)
52 inline void vec2_madd(vec2_t x,
const vec2_t a, Real c)
59 inline void vec2_negate(vec2_t x,
const vec2_t a)
66 inline Real vec2_dot(
const vec2_t a,
const vec2_t b)
68 return a[0]*b[0] + a[1]*b[1];
72 inline float vec2_cross(
const vec2_t a,
const vec2_t b)
74 return a[0]*b[1] - a[1]*b[0];
78 inline Real vec2_length(
const vec2_t x)
80 return Sqrt(vec2_dot(x,x));
84 inline void vec2_normalize(vec2_t x)
86 Real l = Sqrt(vec2_dot(x,x));
87 if(FuzzyZero(l))
return;
88 vec2_multiply(x, x,
Inv(l));
92 inline void vec2_project(vec2_t x,
const vec2_t a,
const vec2_t b)
94 vec2_multiply(x, b, vec2_dot(a,b)/vec2_dot(b,b));
101 inline void vec3_zero(vec3_t x)
107 inline void vec3_make(vec3_t x, Real a, Real b, Real c)
115 inline void vec3_equal(vec3_t x,
const vec3_t a)
123 inline void vec3_add(vec3_t x,
const vec3_t a,
const vec3_t b)
131 inline void vec3_sub(vec3_t x,
const vec3_t a,
const vec3_t b)
139 inline void vec3_multiply(vec3_t x,
const vec3_t a, Real c)
147 inline void vec3_madd(vec3_t x,
const vec3_t a, Real c)
155 inline void vec3_negate(vec3_t x,
const vec3_t a)
163 inline Real vec3_dot(
const vec3_t a,
const vec3_t b)
165 return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
169 inline void vec3_cross(vec3_t x,
const vec3_t a,
const vec3_t b)
171 x[0] = a[1]*b[2] - a[2]*b[1];
172 x[1] = a[2]*b[0] - a[0]*b[2];
173 x[2] = a[0]*b[1] - a[1]*b[0];
177 inline Real vec3_length(
const vec3_t x)
179 return Sqrt(vec3_dot(x,x));
183 inline void vec3_normalize(vec3_t x)
185 Real l = Sqrt(vec3_dot(x,x));
186 if(FuzzyZero(l))
return;
187 vec3_multiply(x, x,
Inv(l));
191 inline void vec3_project(vec3_t x,
const vec3_t a,
const vec3_t b)
193 vec3_multiply(x, b, vec3_dot(a,b)/vec3_dot(b,b));
201 inline void vec4_zero(vec4_t x)
203 x[0]=x[1]=x[2]=x[3]=Zero;
207 inline void vec4_make(vec4_t x, Real a, Real b, Real c, Real d)
216 inline void vec4_equal(vec4_t x,
const vec4_t a)
225 inline void vec4_add(vec4_t x,
const vec4_t a,
const vec4_t b)
234 inline void vec4_sub(vec4_t x,
const vec4_t a,
const vec4_t b)
243 inline void vec4_multiply(vec4_t x,
const vec4_t a, Real c)
252 inline void vec4_madd(vec4_t x,
const vec4_t a, Real c)
261 inline void vec4_negate(vec4_t x,
const vec4_t a)
270 inline Real vec4_dot(
const vec4_t a,
const vec4_t b)
272 return a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3];
276 inline void vec4_normalize(vec4_t x)
278 Real l = Sqrt(vec4_dot(x,x));
279 if(FuzzyZero(l))
return;
280 vec4_multiply(x, x,
Inv(l));
284 inline void vec4_plane_project(vec4_t x,
const vec4_t a,
const vec4_t b)
289 vec4_multiply(x, n, vec4_dot(a,b)/vec3_dot(b,b));
Contains all the definitions in the Math3D package.
Definition: AnyGeometry.h:12
double Inv(double x)
1/x
Definition: math.h:205