-
Notifications
You must be signed in to change notification settings - Fork 6
/
VerdictVector.cpp
82 lines (67 loc) · 1.76 KB
/
VerdictVector.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
/*=========================================================================
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 <cmath>
namespace VERDICT_NAMESPACE
{
// scale the length of the vector to be the new_length
VerdictVector& VerdictVector::length(const double new_length)
{
double len = this->length();
xVal *= new_length / len;
yVal *= new_length / len;
zVal *= new_length / len;
return *this;
}
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
{
assert(len1 > 0);
assert(len2 > 0);
}
if ((cosAngle > 1.0) && (cosAngle < 1.0001))
{
cosAngle = 1.0;
angleRad = std::acos(cosAngle);
}
else if (cosAngle < -1.0 && cosAngle > -1.0001)
{
cosAngle = -1.0;
angleRad = std::acos(cosAngle);
}
else if (cosAngle >= -1.0 && cosAngle <= 1.0)
{
angleRad = std::acos(cosAngle);
}
else
{
assert(cosAngle < 1.0001 && cosAngle > -1.0001);
}
return ((angleRad * 180.) / VERDICT_PI);
}
VerdictVector::VerdictVector(const double xyz[3])
: xVal(xyz[0])
, yVal(xyz[1])
, zVal(xyz[2])
{
}
} // namespace verdict