-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.h
More file actions
68 lines (58 loc) · 1.68 KB
/
Copy pathVector.h
File metadata and controls
68 lines (58 loc) · 1.68 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
//
// Vector.h
// raytracer2
//
// Created by Jean Wolff on 11/01/2020.
// Copyright © 2020 Jean Wolff. All rights reserved.
//
#pragma once
#ifndef Vector_h
#define Vector_h
#define M_pi 3.1416
#endif /* Vector_h */
#include <math.h>
#include <vector>
// Pour afficher des variables
#include <iostream>
using namespace std;
class Vector {
public:
// Constructeur
Vector(double x=0, double y=0, double z=0){
coord[0] = x;
coord[1] = y;
coord[2] = z;
}
// Accesseur pour acceder au i eme element de la coordonnee du vecteur
const double& operator[](int i) const { return coord[i]; }
double& operator[](int i) { return coord[i]; }
// On evitera le calcul couteux de racines carres
double getNorm2() {
return coord[0] * coord[0] + coord[1] * coord[1] + coord[2] * coord[2];
}
// Normaliser un vecteur
void normalize() {
double norm = sqrt(getNorm2());
coord[0] /= norm;
coord[1] /= norm;
coord[2] /= norm;
}
// Renvoie le vecteur normalise, mais sans modifier le vecteur initial
Vector getNormalized() {
// Copie du vecteur
Vector result(*this);
result.normalize();
return result;
}
private:
double coord[3];
};
Vector operator+(const Vector& a, const Vector &b);
Vector operator-(const Vector& a, const Vector &b);
Vector operator*(double a, const Vector &b);
Vector operator*(const Vector &a, const Vector &b);
Vector operator*(const Vector &b, double a);
Vector operator/(const Vector& a, double b);
Vector operator-(const Vector& a);
double dot(const Vector& a, const Vector& b);
Vector cross(const Vector& a, const Vector& b);