forked from shubhamag/gipuma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mathUtils.h
32 lines (27 loc) · 797 Bytes
/
mathUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* some math helper functions
*/
#pragma once
#ifndef M_PI
#define M_PI 3.14159265358979323846f
#endif
#define M_PI_float 3.14159265358979323846f
//rounding of positive float values
#if defined(_WIN32)
static float roundf ( float val ) {
return floor ( val+0.5f );
};
#endif
/* get angle between two vectors in 3D
* Input: v1,v2 - vectors
* Output: angle in radian
*/
static float getAngle ( Vec3f v1, Vec3f v2 ) {
float angle = acosf ( v1.dot ( v2 ) );
//if angle is not a number the dot product was 1 and thus the two vectors should be identical --> return 0
if ( angle != angle )
return 0.0f;
//if ( acosf ( v1.dot ( v2 ) ) != acosf ( v1.dot ( v2 ) ) )
//cout << acosf ( v1.dot ( v2 ) ) << " / " << v1.dot ( v2 )<< " / " << v1<< " / " << v2 << endl;
return angle;
}