-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoint3.cpp
More file actions
88 lines (73 loc) · 1.98 KB
/
point3.cpp
File metadata and controls
88 lines (73 loc) · 1.98 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
79
80
81
82
83
84
85
86
87
88
#include "point3.h"
#include "transformation.h"
#include "math.h"
#include <cmath>
libMesh::Point3::Point3() : Point3(0.0f, 0.0f, 0.0f)
{
}
libMesh::Point3::Point3(float x, float y, float z) : x(x), y(y), z(z)
{
}
libMesh::Point3::Point3(const Point3 &other)
{
x = other.x;
y = other.y;
z = other.z;
}
libMesh::Vector3 libMesh::Point3::betweenPoints(Point3 p0, Point3 p1)
{
return Vector3(p1.x - p0.x, p1.y - p0.y, p1.z - p0.z);
}
void libMesh::Point3::add(Vector3 vector)
{
x += vector.x;
y += vector.y;
z += vector.z;
}
libMesh::Point3 libMesh::Point3::added(Vector3 vector)
{
return Point3(x + vector.x, y + vector.y, z + vector.z);
}
void libMesh::Point3::subtract(Vector3 vector)
{
x -= vector.x;
y -= vector.y;
z -= vector.z;
}
libMesh::Point3 libMesh::Point3::subtracted(Vector3 vector)
{
return Point3(x - vector.x, y - vector.y, z - vector.z);
}
float libMesh::Point3::distanceTo(Point3 other)
{
return std::sqrt(squaredDistanceTo(other));
}
float libMesh::Point3::squaredDistanceTo(Point3 other)
{
Vector3 diff = betweenPoints(*this, other);
return diff.dot(diff);
}
void libMesh::Point3::transform(Transformation t)
{
float newX = (x * t.m00 + y * t.m10 + z * t.m20 + t.m03) / t.m33;
float newY = (x * t.m01 + y * t.m11 + z * t.m21 + t.m13) / t.m33;
float newZ = (x * t.m02 + y * t.m12 + z * t.m22 + t.m23) / t.m33;
x = newX;
y = newY;
z = newZ;
}
libMesh::Point3 libMesh::Point3::transformed(Transformation t)
{
float newX = (x * t.m00 + y * t.m10 + z * t.m20 + t.m03) / t.m33;
float newY = (x * t.m01 + y * t.m11 + z * t.m21 + t.m13) / t.m33;
float newZ = (x * t.m02 + y * t.m12 + z * t.m22 + t.m23) / t.m33;
return Point3(newX, newY, newZ);
}
bool libMesh::Point3::operator==(const Point3 &other) const
{
return Math::Equals(x, other.x) && Math::Equals(y, other.y) && Math::Equals(z, other.z);
}
bool libMesh::Point3::operator!=(const Point3 &other) const
{
return !(*this == other);
}