1 |
kusanagi |
1.1 |
//
|
2 |
|
|
// cVector.cpp
|
3 |
|
|
//
|
4 |
|
|
// Copyright (c) 2001-2003 Michael F. Henry
|
5 |
|
|
//
|
6 |
|
|
#include "stdafx.h"
|
7 |
|
|
|
8 |
|
|
#include "math.h"
|
9 |
|
|
#include "cVector.h"
|
10 |
|
|
|
11 |
|
|
//*****************************************************************************
|
12 |
|
|
// Multiply each component in the vector by 'factor'.
|
13 |
|
|
//*****************************************************************************
|
14 |
|
|
void cVector::Mul(double factor)
|
15 |
|
|
{
|
16 |
|
|
m_x *= factor;
|
17 |
|
|
m_y *= factor;
|
18 |
|
|
m_z *= factor;
|
19 |
|
|
m_w *= fabs(factor);
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
//*****************************************************************************
|
23 |
|
|
// Subtract a vector from this one.
|
24 |
|
|
//*****************************************************************************
|
25 |
|
|
void cVector::Sub(const cVector& vec)
|
26 |
|
|
{
|
27 |
|
|
m_x -= vec.m_x;
|
28 |
|
|
m_y -= vec.m_y;
|
29 |
|
|
m_z -= vec.m_z;
|
30 |
|
|
m_w -= vec.m_w;
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
//*****************************************************************************
|
34 |
|
|
// Calculate the angle between this vector and another
|
35 |
|
|
//*****************************************************************************
|
36 |
|
|
double cVector::Angle(const cVector& vec) const
|
37 |
|
|
{
|
38 |
|
|
return acos(Dot(vec) / (Magnitude() * vec.Magnitude()));
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
//*****************************************************************************
|
42 |
|
|
//
|
43 |
|
|
//*****************************************************************************
|
44 |
|
|
double cVector::Magnitude() const
|
45 |
|
|
{
|
46 |
|
|
return sqrt((m_x * m_x) +
|
47 |
|
|
(m_y * m_y) +
|
48 |
|
|
(m_z * m_z));
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
//*****************************************************************************
|
52 |
|
|
// Return the dot product
|
53 |
|
|
//*****************************************************************************
|
54 |
|
|
double cVector::Dot(const cVector& vec) const
|
55 |
|
|
{
|
56 |
|
|
return (m_x * vec.m_x) +
|
57 |
|
|
(m_y * vec.m_y) +
|
58 |
|
|
(m_z * vec.m_z);
|
59 |
|
|
}
|