-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathVerdictVector.cpp
More file actions
96 lines (80 loc) · 2.04 KB
/
Copy pathVerdictVector.cpp
File metadata and controls
96 lines (80 loc) · 2.04 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
89
90
91
92
93
94
95
96
/*=========================================================================
Module: VerdictVector.cpp
Copyright 2003,2006,2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
Under the terms of Contract DE-NA0003525 with NTESS,
the U.S. Government retains certain rights in this software.
See LICENSE for details.
=========================================================================*/
/*
*
* VerdictVector.cpp contains implementation of Vector operations
*
* This file is part of VERDICT
*
*/
#include "VerdictVector.hpp"
#include "verdict.h"
#include <math.h>
namespace VERDICT_NAMESPACE
{
// scale the length of the vector to be the new_length
VERDICT_HOST_DEVICE VerdictVector& VerdictVector::length(const double new_length)
{
double len = this->length();
Val[0] *= new_length / len;
Val[1] *= new_length / len;
Val[2] *= new_length / len;
return *this;
}
VERDICT_HOST_DEVICE double VerdictVector::interior_angle(const VerdictVector& otherVector)
{
double cosAngle = 0., angleRad = 0., len1, len2 = 0.;
if (((len1 = this->length()) > 0) && ((len2 = otherVector.length()) > 0))
{
cosAngle = VerdictVector::Dot(*this, otherVector) / (len1 * len2);
}
else
{
#ifndef __HIP_DEVICE_COMPILE__
assert(len1 > 0);
assert(len2 > 0);
#endif
}
if ((cosAngle > 1.0) && (cosAngle < 1.0001))
{
cosAngle = 1.0;
angleRad = acos(cosAngle);
}
else if (cosAngle < -1.0 && cosAngle > -1.0001)
{
cosAngle = -1.0;
angleRad = acos(cosAngle);
}
else if (cosAngle >= -1.0 && cosAngle <= 1.0)
{
angleRad = acos(cosAngle);
}
else
{
#ifndef __HIP_DEVICE_COMPILE__
assert(cosAngle < 1.0001 && cosAngle > -1.0001);
#endif
}
return ((angleRad * 180.) / VERDICT_PI);
}
VERDICT_HOST_DEVICE double VerdictVector::normalize()
{
double mag = length();
if (mag > VERDICT_DBL_MIN*2.0)
{
Val[0] = Val[0] / mag;
Val[1] = Val[1] / mag;
Val[2] = Val[2] / mag;
return mag;
}
Val[0] = 0.0;
Val[1] = 0.0;
Val[2] = 0.0;
return 0;
}
} // namespace verdict