File: vec3.C

package info (click to toggle)
flying 6.20-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 752 kB
  • ctags: 1,873
  • sloc: cpp: 10,966; makefile: 189
file content (110 lines) | stat: -rw-r--r-- 2,413 bytes parent folder | download | duplicates (4)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef _global_h
#	include "global.h"
#endif

#ifndef _vec3_h
#	include "vec3.h"
#endif

Vec3 Vec3Zero( RealZero, RealZero, RealZero );

#if (Vec3IsVector)
Vec3::Vec3( const Real &l, const Real &b ) : Vector(3,0.0,0.0,0.0) {
Real	hr = sin(b/180.0*M_PI);		// Radius am 'Breitengrad' b;

	data[0] = hr*cos(l/180.0*M_PI);
	data[1] = hr*sin(l/180.0*M_PI);
	data[2] = cos(b/180.0*M_PI);			// H�he, bestimmt durch Breitengrad
}
#else
Vec3::Vec3( const Real &l, const Real &b ) {
Real	hr = sin(b/180.0*M_PI);		// Radius am 'Breitengrad' b;

	x_val = hr*cos(l/180.0*M_PI);
	y_val = hr*sin(l/180.0*M_PI);
	z_val = cos(b/180.0*M_PI);			// H�he, bestimmt durch Breitengrad

	norm  = RealZero;
}
#endif

//
// Berechnung des Winkels zwischen 2 Vec2en
//
Real Vec3::AngleRadTo( Vec3 &d )
{
Real	cos_phi = (*this)*d/(Norm()*d.Norm());

		return acos( cos_phi );
}


Real Vec3::AngleRad( const Real &dx, const Real &dy )
{
Real	erg;

#if (0)
static FunTab	*TAN=0;
	if (!TAN)			TAN = new FunTab( tan, -M_PI_2, M_PI_2, 64 );
#endif

	if (dx)		erg = atan( dy/dx );
	else					erg = (dy>=RealZero)?M_PI_2:3*M_PI_2;
	if (dx<RealZero)	erg+= M_PI;
	if (erg<RealZero)	erg+= 2*M_PI;
	return erg;
}


void Vec3::GetPolarRad( Real *l, Real *b ) const
{
	*l = AngleRad( X(), Y() );
	*b = AngleRad( Z(), sqrt( X()*X() + Y()*Y() ) );
}
void Vec3::GetPolarRad( Real *l, Real *b, Real *r )
{
	*r = Norm();
	GetPolarRad(l,b);
}



Vec3 Vec3::XTurnAngleRad( const Real &angle ) const
{
	if (Y()!=RealZero||Z()!=RealZero) {
			Real	len = sqrt( Y()*Y() + Z()*Z() );
			Real	ang = AngleRad(Y(),Z()) + angle;
#if (Vec3IsVector)
			return Vec3( X(), len*cos(ang), len*sin(ang) );
#else
			return Vec3( X(), len*cos(ang), len*sin(ang), norm );
#endif
	}
	else	return *this;
}
Vec3 Vec3::YTurnAngleRad( const Real &angle ) const
{
	if (X()!=RealZero||Z()!=RealZero) {
			Real	len = sqrt( X()*X() + Z()*Z() );
			Real	ang = AngleRad(X(),Z()) + angle;
#if (Vec3IsVector)
			return Vec3( len*cos(ang), Y(), len*sin(ang) );
#else
			return Vec3( len*cos(ang), Y(), len*sin(ang), norm );
#endif
	}
	else	return *this;
}
Vec3 Vec3::ZTurnAngleRad( const Real &angle ) const
{
	if (X()!=RealZero||Y()!=RealZero) {
			Real	len = sqrt( X()*X() + Y()*Y() );
			Real	ang = AngleRad(X(),Y()) + angle;
#if (Vec3IsVector)
			return Vec3( len*cos(ang), len*sin(ang), Z() );
#else
			return Vec3( len*cos(ang), len*sin(ang), Z(), norm );
#endif
	}
	else	return *this;
}