blob: 7906f34c9cf3d26faace1c66371ee49750c004d2 (
plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
// Copyright 2006-2007 Nanorex, Inc. See LICENSE file for details.
/*
Name: triple.cpp
Author: Oleksandr Shevchenko
Description: coordinate 3D point management class
*/
#include "triple.h"
//----------------------------------------------------------------------------
// Closest()
//
// closest point on edge
//
double Triple::Closest(
const Triple & vertex0,
const Triple & vertex1,
Triple & p) const
{
Triple edge(vertex0,vertex1);
double t = ((*this-vertex0)%edge)/edge.Len2();
if (t < 0.0)
{
p = vertex0;
t = 0.0;
}
else if (t > 1.0)
{
p = vertex1;
t = 1.0;
}
else
{
p = vertex0 + t*edge;
}
return t;
}
//----------------------------------------------------------------------------
// Greatest()
//
// calculate greatest value
//
int Triple::Greatest(
double & value) const
{
if (X() > Y())
{
if(X() > Z())
{
// x is greatest
value = X();
return (0);
}
else
{
// z is greatest
value = Z();
return (2);
}
}
else
{
if(Y() > Z())
{
// y is greatest
value = Y();
return (1);
}
else
{
// z is greatest
value = Z();
return (2);
}
}
return (2);
}
//----------------------------------------------------------------------------
// Len()
//
// vector length
//
double Triple::Len() const
{
return sqrt(X()*X() + Y()*Y() + Z()*Z());
}
//----------------------------------------------------------------------------
// Len2()
//
// square of vector length
//
double Triple::Len2() const
{
return (X()*X() + Y()*Y() + Z()*Z());
}
//----------------------------------------------------------------------------
// Normalize()
//
// normalize vector to unit length
//
Triple & Triple::Normalize()
{
double length= Len();
*this /= length;
return *this;
}
//----------------------------------------------------------------------------
// Normalize()
//
// normalizes vector to unit length
//
Triple & Triple::Normalize(
double &length)
{
length = Len();
*this /= length;
return *this;
}
//----------------------------------------------------------------------------
// Orthogonal()
//
// get orthogonal axes
//
void Triple::Orthogonal(
Triple & ox,
Triple & oy) const
{
double ix = 0.0, iy = 0.0;
if( fabs(X())>fabs(Z()) && fabs(X()) > fabs(Y()) )
iy = 1.0;
else
ix = 1.0;
oy = Triple(iy*Z(), -ix*Z(), ix*Y()-iy*X());
oy.Normalize();
ox = oy * (*this);
ox.Normalize();
}
|