summaryrefslogtreecommitdiffstats
path: root/Master/Real-Time Systems/RTS_A8/src/POS.h
blob: 490838a0c573a48fa0768748d8b69ecb1406a208 (plain)
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
/*
 * POS.h
 *
 *  Created on: 30.11.2010
 *      Author: istsveise
 */

#ifndef POS_H_
#define POS_H_

#include <iostream>
#include <cmath>

using namespace std;

extern const double PI;

struct vector3d {
	double x;
	double y;
	double z;
	vector3d(double px,double py):x(px),y(py),z(1) {};
	vector3d():x(0),y(0),z(1) {};
	double length() {
		return sqrt( (x*x) + (y*y) );
	}
	double scalarProduct(const vector3d& l) {
		return (x*l.x)+(y*l.y)+(z*l.z);
	}
	void crossProduct(const vector3d& l,vector3d& res)
	{
		res.x = ( (y*l.z) - (z*l.y) );
		res.y = ( (z*l.x) - (x*l.z) );
		res.z = ( (x*l.y) - (y*l.x) );
	}
	void normalize()
	{
		double len = length();
		x = x / len;
		y = y / len;
		z = z / len;
	}
};

struct POS {
	double x;
	double y;
	void move(double v, double dir)
	{
//		cout << "v: " << v << " dir: " << dir <<endl;
		double dx = v * cos(dir*PI/180);
		double dy = v * sin(dir*PI/180);
//		cout << "dx: " << dx << " dy: " << dy <<endl;
		x += dx;
		y += dy;
	}
	void display(const char* prefix) {
		cout << prefix << " "<< x << " " << y << endl;
	}
};

#ifndef ABSTAND
#define ABSTAND

extern double Abstand(POS p,double Ldir);

#endif

#endif /* POS_H_ */