-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector.cpp
85 lines (66 loc) · 2.34 KB
/
vector.cpp
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
#include "vector.h"
//coordinate
x_yCoordinate::x_yCoordinate() :x(0), y(0) {}
x_yCoordinate::x_yCoordinate(float a, float b,float c) :x(a), y(b) , z(c){}
x_yCoordinate::x_yCoordinate(x_y_zCoordinate p):x(p.x),y(p.y),z(p.z),m(sqrt(x*x+y*y+z*z)){}
x_yCoordinate x_yCoordinate::operator +(const x_yCoordinate &c) const {
return x_yCoordinate(x + c.x, y + c.y, z + c.z);
}
x_yCoordinate x_yCoordinate::operator -(const x_yCoordinate &c) const {
return x_yCoordinate(x - c.x, y - c.y, z - c.z);
}
x_yCoordinate x_yCoordinate::scale(float a)
{
return (x_yCoordinate(a*x,a*y,a*z));
}
x_yCoordinate x_yCoordinate::crossProduct(x_yCoordinate v)
{
return (x_yCoordinate(y*v.z-z*v.y ,v.x*z-x*v.z ,x*v.y-y*v.x));
}
x_yCoordinate x_yCoordinate::getUnitVector()
{
return (x_yCoordinate(x/m,y/m,z/m));
}
float x_yCoordinate::dotProduct(x_yCoordinate v)
{
//float dotP = x*v.x + y*v.y+ z*v.z;
//return dotP;
return (float(x*v.x + y*v.y+ z*v.z));
}
x_y_zCoordinate::x_y_zCoordinate():x(0), y(0), z(0), p(1) ,magnitude(sqrt(x*x+y*y+z*z)){}
x_y_zCoordinate::x_y_zCoordinate(float a, float b, float c, float d,Color e)
:x(a), y(b), z(c), p(d),color(e),magnitude(sqrt(x*x+y*y+z*z)) {}
x_y_zCoordinate x_y_zCoordinate::operator +(const x_y_zCoordinate &c) const {
return x_y_zCoordinate(x + c.x, y + c.y, z + c.z);
}
x_y_zCoordinate x_y_zCoordinate::operator -(const x_y_zCoordinate &c) const {
return x_y_zCoordinate(x - c.x, y - c.y, z - c.z);
}
x_y_zCoordinate x_y_zCoordinate::operator /(float f) const{
return x_y_zCoordinate(x/f,y/f,z/f);
}
//faces
Faces::Faces():w(0),x(0),y(0),z(0){}
Faces::Faces(float a):w(a),x(0),y(0),z(0){}
Faces::Faces(float a,float b):w(a),x(b),y(0),z(0){}
Faces::Faces(float a,float b,float c):w(a),x(b),y(c),z(0){}
Faces::Faces(float a,float b,float c,float d):w(a),x(b),y(c),z(d){}
//x_y_zCoordinate
x_y_zCoordinate x_y_zCoordinate::scale(float a)
{
return (x_y_zCoordinate(a*x,a*y,a*z));
}
x_y_zCoordinate x_y_zCoordinate::crossProduct(x_y_zCoordinate v)
{
return (x_y_zCoordinate(y*v.z-z*v.y ,v.x*z-x*v.z ,x*v.y-y*v.x));
}
x_y_zCoordinate x_y_zCoordinate::getUnitVector()
{
return (x_y_zCoordinate(x/magnitude,y/magnitude,z/magnitude));
}
float x_y_zCoordinate::dotProduct(x_y_zCoordinate v)
{
//float dotP = x*v.x + y*v.y+ z*v.z;
//return dotP;
return (float(x*v.x + y*v.y+ z*v.z));
}