-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlane.cpp
62 lines (46 loc) · 1.1 KB
/
Plane.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
/* ------------------------------------------------------
Plane - Std3D
--------------------------------------------------------*/
#include "Plane.h"
#include <stdio.h>
Plane::Plane()
: normal()
, d(0.f)
{}
Plane::Plane(const Vec3 &v1, const Vec3 &v2, const Vec3 &v3)
{
set3Points(v1, v2, v3);
}
void Plane::set3Points(const Vec3 &v1, const Vec3 &v2, const Vec3 &v3)
{
normal = Vec3::cross((v2 - v1), (v3 - v1));
normal.normalize();
d = -Vec3::dot(normal, v1);
}
void Plane::setNormalAndPoint(const Vec3 &normal, const Vec3 &point)
{
this->normal = normal;
this->normal.normalize();
d = -Vec3::dot(normal, point);
}
void Plane::setCoefficients(float a, float b, float c, float d)
{
// set the normal vector
normal.set(a, b, c);
//compute the lenght of the vector
float l = normal.length();
// normalize the vector
normal.set(a/l, b/l, c/l);
// and divide d by th length as well
this->d = d/l;
}
float Plane::distance(const Vec3 &p) const
{
return (d + Vec3::dot(normal, p));
}
void Plane::print()
{
printf("Plane(");
normal.print();
printf("# %f)", d);
}