Repository navigation
Expand file tree
/
Copy pathVectors.cpp
More file actions
78 lines (61 loc) · 3.59 KB
/
Copy pathVectors.cpp
File metadata and controls
78 lines (61 loc) · 3.59 KB
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
// Introduccion.cpp: define el punto de entrada de la aplicación de consola.
//
#include "stdafx.h"
#include <iostream>
#include <math.h>
const double PI = 3.14159265359;
class Vector {
public:
float x, y, z;
Vector(float _x, float _y, float _z) {
x = _x;
y = _y;
z = _z;
}
};
double CosDeg(float angle) {
if (angle == 90 || angle == -90 || angle == 270 || angle == -270)
return 0;
else
return cos(angle * PI/180);
}
double SinDeg(float angle) {
if (angle == 0 || angle == 180 || angle == -180)
return 0;
else
return sin(angle * PI/180);
}
// ROTAR SOBRE EL EJE Z
Vector ZRotation(Vector p, float angle) {
return Vector(CosDeg(angle) * p.x + (-SinDeg(angle) * p.y), SinDeg(angle) * p.x + CosDeg(angle) * p.y, p.z);
}
double Lenght(Vector a) {
return sqrt(pow(a.x, 2.0) + pow(a.y, 2.0));
}
float Dot(Vector a, Vector b) {
return float(a.x * b.x + a.y * b.y + a.z * b.z);
}
double AngleBetween(Vector a, Vector b) {
return acos(
(Dot(a, b)) / // NUMERATOR
(Lenght(a) * Lenght(b)) // DENOMINATOR
) * 180 / PI;
}
double AngleOfVector(Vector a) {
return atan(a.x / a.y) * 180 / PI;
}
int main()
{
Vector _vectorPrueba(0, 2, 0);
Vector _vectorPrueba1(1, 0, 0);
Vector _resultado(0,0,0);
std::cout << "DOT PRODUCT: " << Dot(_vectorPrueba, _vectorPrueba1) << std::endl;
std::cout << "LENGHT: " << Lenght(_vectorPrueba) << std::endl;
std::cout << "ANGLE: " << AngleOfVector(_vectorPrueba) << std::endl;
std::cout << "ANGLE BETWEEN: " << AngleBetween(_vectorPrueba, _vectorPrueba1) << std::endl;
std::cout << "COSENO: " << CosDeg(60) << std::endl;
_resultado = ZRotation(_vectorPrueba, 30);
std::cout << "x: " << _resultado.x << " y: " << _resultado.y << " z: " << _resultado.z;
std::cin.get();
return 0;
}