File: RayVector.cpp

package info (click to toggle)
r-cran-igraph 0.7.1-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 14,280 kB
  • sloc: ansic: 150,105; cpp: 19,404; fortran: 3,777; yacc: 1,164; tcl: 931; lex: 484; makefile: 13; sh: 9
file content (128 lines) | stat: -rwxr-xr-x 2,268 bytes parent folder | download | duplicates (9)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "RayVector.h"
#include <math.h>

namespace igraph {

Vector::Vector()
{
	mI = mJ = mK = 0.0;
}

Vector::Vector(const Point& vStartPoint, const Point& vEndPoint)
{
	mI = vEndPoint.X() - vStartPoint.X();
	mJ = vEndPoint.Y() - vStartPoint.Y();
	mK = vEndPoint.Z() - vStartPoint.Z();
}

Vector::Vector(double vI, double vJ, double vK)
{
	mI = vI;
	mJ = vJ;
	mK = vK;
}

Vector::~Vector()
{}

// returns a unit vector of this vector
Vector Vector::Normalize() const
{
	double magnitude = Magnitude();
	return Vector(mI/magnitude, mJ/magnitude, mK/magnitude);
}

void Vector::NormalizeThis()
{
	*this = Normalize();
}

void Vector::ReverseDirection()
{
	*this = *this * -1.0;
}

bool Vector::IsSameDirection(const Vector& rVector) const
{
	return ( this->Normalize().Dot(rVector.Normalize()) > 0.0 );
}


void Vector::I(double vI)
{
	mI = vI;
}

double Vector::I() const
{
	return mI;
}

void Vector::J(double vJ)
{
	mJ = vJ;
}

double Vector::J() const
{
	return mJ;
}
void Vector::K(double vK)
{
	mK = vK;
}

double Vector::K() const
{
	return mK;
}

// returns the dot product of this and rVector
double Vector::Dot(const Vector& rVector) const
{
	return mI*rVector.I() + mJ*rVector.J() + mK*rVector.K();
}

// returns the cross product of this and vVector
Vector Vector::Cross(const Vector& rVector) const
{
	return Vector(mJ*rVector.K() - rVector.J()*mK, -1.0*(mI*rVector.K() - rVector.I()*mK), mI*rVector.J() - rVector.I()*mJ);
}

// returns the sum of this vector with another vector
Vector Vector::operator+ (Vector vRhs) const
{
	return Vector(mI + vRhs.I(), mJ + vRhs.J(), mK + vRhs.K());
}

// returns the sume of a vector and a Point
Point Vector::operator+ (Point vRhs) const
{
	return Point(mI + vRhs.X(), mJ + vRhs.Y(), mK + vRhs.Z());
}

// returns the difference of two vectors
Vector Vector::operator- (Vector vRhs) const
{
	return Vector(mI-vRhs.I(), mJ-vRhs.J(), mK-vRhs.K());
}

// returns multiplication of a scalar with this vector
Vector Vector::operator* (double vRhs) const
{
	return Vector(mI*vRhs, mJ*vRhs, mK*vRhs);
}

// converts this vector to a point
Point Vector::ToPoint() const
{
	return Point(mI,mJ,mK);
}

// returns the magnitude
double Vector::Magnitude() const
{
	return sqrt(mI*mI + mJ*mJ + mK*mK);
}

} // namespace igraph