-
Notifications
You must be signed in to change notification settings - Fork 2
/
Angle.cpp
65 lines (55 loc) · 1.67 KB
/
Angle.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
//
// Created by Ryan.Zurrin001 on 12/16/2021.
//
#include <cmath>
#include "Angle.h"
//float rez::AngleLines2D( const Line2d& l1, const Line2d l2)
//{
// auto mag_l1 = l1.direction().magnitude();
// auto mag_l2 = l2.direction().magnitude();
// auto dot = dot(l1.direction(), l2.direction());
//
// auto theta = acos( fabs(dot) / (mag_l1 * mag_l2));
// return RadianceToDegrees(theta);
//}
//float rez::AngleLines3D(const Line& l1, const Line& l2)
//{
// auto mag_l1 = l1.direction().magnitude();
// auto mag_l2 = l2.direction().magnitude();
// auto dot = dot(l1.direction(), l2.direction());
//
// auto theta = acos(fabs(dot) / (mag_l1 * mag_l2));
// return RadianceToDegrees(theta);
//}
//float rez::AngleLinePlane(const Line& l, const Planef p)
//{
// auto dot = dot(l.direction(), p.getNormal());
// auto theta = acos(fabs(dot));
// theta = RadianceToDegrees(theta);
// return 90- theta;
//}
using namespace rez;
template<class T, size_t dimensions >
static float getAngle(rez::Vector<T, dimensions> v1, rez::Vector<T, dimensions> v2)
{
auto dot = dotProduct(v1, v2);
auto theta = acos(fabs(dot));
return RadianceToDegrees(theta);
}
float rez::AngleLines2D(const Line2d& l1, const Line2d l2)
{
return getAngle(l1.direction(), l2.direction());
}
float rez::AngleLines3D(const Line& l1, const Line& l2)
{
return getAngle(l1.direction(), l2.direction());
}
float rez::AngleLinePlane(const Line& l, const Planef p)
{
auto theta = getAngle(l.direction(), p.getNormal());
return 90 - theta;
}
float rez::AnglePlanes(const Planef p1, const Planef p2)
{
return getAngle(p1.getNormal(), p2.getNormal());
}