VR-Forces 4.3 Class Documentation
Home
Modules
Namespaces
Classes
Files
Examples
Behavior Models
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
include
vrvDrawControl
DtVdcVector2D.h
Go to the documentation of this file.
1
/*********************************************************************
2
** Copyright (c) 2010 MaK Technologies, Inc.
3
** All rights reserved.
4
*********************************************************************/
5
/*********************************************************************
6
** $RCSfile: DtVdcVector2D.h,v $ $Revision: 1.3 $ $State: Exp $
7
*********************************************************************/
8
#pragma once
9
10
#include <vlutil/vlString.h>
11
#include <matrix/vlVector.h>
12
#include <iosfwd>
13
14
#include <
vrvDrawControl/vrvDrawControl.h
>
15
16
// \file DtVdcVector2D.h
17
// \brief DtVdcVector2D.h provides an implimentation of a 2D Vector class as well as
18
// many methods which operate on DtVdcVector2Ds.
19
namespace
vrvControlToolkit
20
{
21
22
enum
DtVdcVector2DOffset
23
{
24
DtVdcX
,
25
DtVdcY
26
};
27
28
class
DtVdcVector2D
;
29
30
typedef
const
DtVdcVector2D
&
DtVdcConstVector2D
;
31
typedef
DtVdcVector2D
&
DtVdcVector2DRef
;
32
33
// \brief DtVdcVector2Ds represent vectors in 2-d space, X, Y
34
//
35
// A DtVdcVector2D is the 2D equivalent of the 3D DtVector
36
class
DT_DLL_VRVDRAWCONTROL
DtVdcVector2D
37
{
38
public
:
39
40
DtVdcVector2D
();
41
42
// Construct from two doubles.
43
DtVdcVector2D
(
const
double
& x,
const
double
& y );
44
45
// destructor
46
~
DtVdcVector2D
();
47
48
// copy constructor
49
DtVdcVector2D
(
const
DtVdcVector2D
& vec);
50
51
// assignment operator
52
DtVdcVector2D
& operator=(
const
DtVdcVector2D
& vec);
53
54
// set Vector to all zeros
55
void
setToZero();
56
57
// @{
58
// gets/sets the x component of a Vector
59
const
double
& x()
const
;
60
void
setX(
const
double
& x);
61
// @}
62
63
// @{
64
// gets/sets the y component of a Vector
65
const
double
& y()
const
;
66
void
setY(
const
double
& y);
67
// @}
68
69
// adds other to this vector
70
DtVdcVector2D
&operator+=(
const
DtVdcVector2D
&other);
71
72
// subtracts other from this vector (this - other)
73
DtVdcVector2D
&operator-=(
const
DtVdcVector2D
&other);
74
75
// subtraction
76
DtVdcVector2D
operator-(
const
DtVdcVector2D
&other)
const
;
77
78
// addition
79
DtVdcVector2D
operator+(
const
DtVdcVector2D
&other)
const
;
80
81
// multiplies this vector by scalar
82
DtVdcVector2D
operator*(
float
scale)
const
;
83
84
// multiplies this vector by scalar
85
DtVdcVector2D
& operator*=(
float
scale);
86
87
// Get the value for the specified subscript. (int version)
88
double
& operator[](
int
ind);
89
90
// A const version to get the value for the specified subscript
91
double
operator[](
int
ind)
const
;
92
93
// Get the value for the specified subscript. (enum version)
94
double
& operator[](
DtVdcVector2DOffset
ind);
95
96
// a const version to get the value for the specified subscript. (enum version)
97
double
operator[](
DtVdcVector2DOffset
ind)
const
;
98
99
// Get whether another vector equals this vector. Warning: This
100
// operation compares floats of exact equality.
101
int
operator==
(
const
DtVdcVector2D
& vec)
const
;
102
103
// Get whether another vector does not equal this vector. Warning:
104
// this operation calles operator== which tests floats for exact equality
105
int
operator!=
(
const
DtVdcVector2D
& vec)
const
;
106
107
// Get a string representation of the vector.
108
DtString
string()
const
;
109
110
// Create a DtVector (with z==0) from a DtVdcVector2D
111
DtVector
vector3D()
const
;
112
113
// Get the magnitude of the vector squared,
114
// i.e. x^2 + y^2
115
double
magnitudeSquared()
const
;
116
117
// Normalize the vector; i.e., magnitude = 1.
118
void
normalize();
119
120
// Returns true of the vector is Normalized
121
bool
isNormalized()
const
;
122
123
// Compute dot product with another vector
124
double
dotProduct(
const
DtVdcVector2D
& v)
const
;
125
126
// check if the vector is zero-ed out withing the tolerace passed
127
bool
approxEq(
const
DtVdcVector2D
& v,
const
double
& tolerance)
const
;
128
129
// check if the magnitide of this vector is zero
130
bool
magnitudeIsZero()
const
;
131
132
// check if the magnitide of this vector is zero, within the tolerance passed.
133
// \Note This tolerance is comparied against each component of the vector,
134
// not the magnitude.
135
bool
magnitudeIsZero(
double
tolerance)
const
;
136
137
// prints out a formated string to the stream
138
std::ostream &printDataToStream(std::ostream &str)
const
;
139
140
public
:
141
142
// @name These functions reveal the internal representation of DtVector
143
// and should not be used. They are provided for backwards compatability
144
// @{
145
operator
double
* ();
146
operator
const
double
* ()
const
;
147
// @}
148
149
public
:
150
151
152
// Get a zero'ed vector.
153
static
const
DtVdcVector2D
& zero();
154
155
// Get a (1,0) vector.
156
static
const
DtVdcVector2D
& i();
157
158
// Get a (0,1) vector.
159
static
const
DtVdcVector2D
& j();
160
161
// Get a vector set to all ones.
162
static
const
DtVdcVector2D
& ones();
163
164
165
protected
:
166
167
double
myRep[2];
168
169
170
};
171
172
//
173
// Vector routines.
174
//
175
176
#define DtSetVec2D(v, x, y) v[DtSdcX]=x;v[DtSdcY]=y;
177
178
DT_DLL_VRVDRAWCONTROL
void
DtVecScale
(
const
DtVdcVector2D& v,
double
scale_factor, DtVdcVector2D& result);
179
DT_DLL_VRVDRAWCONTROL
void
DtVecNeg
(
const
DtVdcVector2D& v1, DtVdcVector2D& result);
// result = -vec
180
181
// cos of angle between v1 and V2
182
DT_DLL_VRVDRAWCONTROL
double
DtVecCosProd
(
const
DtVdcVector2D& v1,
const
DtVdcVector2D& v2);
183
184
DT_DLL_VRVDRAWCONTROL
double
DtVecInfNorm
(
const
DtVdcVector2D& v1);
185
DT_DLL_VRVDRAWCONTROL
void
DtVecInit
(DtVdcVector2D& v);
// Initialize to all zeros.
186
187
/* ||p1-p2||_{2} */
188
DT_DLL_VRVDRAWCONTROL
double
DtDistance
(
const
DtVdcVector2D& p1,
const
DtVdcVector2D& p2);
189
190
DT_DLL_VRVDRAWCONTROL
double
DtDistSqr
(
const
DtVdcVector2D& p1,
const
DtVdcVector2D& p2);
191
}
192
193
std::ostream &
operator <<
(std::ostream &str,
const
vrvControlToolkit::DtVdcVector2D
&vec);
194
195
196
// Include inline definitions for vlVector
197
#define DtVdcVector2D_inl
198
#include <vrvDrawControl/DtVdcVector2D.inl>
199
#undef DtVdcVector2D_inl
200
201
Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (
www.mak.com
)