Nebula
Toggle main menu visibility
Loading...
Searching...
No Matches
polar.h
Go to the documentation of this file.
1
#pragma once
2
#ifndef MATH_POLAR_H
3
#define MATH_POLAR_H
4
//------------------------------------------------------------------------------
20
#include "
math/scalar.h
"
21
#include "
math/vec3.h
"
22
#include "
math/vec2.h
"
23
24
//------------------------------------------------------------------------------
25
namespace
Math
26
{
27
class
polar
28
{
29
public
:
31
polar
();
33
polar
(
scalar
t,
scalar
r);
35
polar
(
const
vec3
& v);
37
polar
(
const
polar
& src);
39
void
operator=
(
const
polar
& rhs);
41
vec3
get_cartesian
()
const
;
43
void
set
(
const
polar
& p);
45
void
set
(
scalar
t,
scalar
r);
47
void
set
(
const
vec3
& v);
48
49
scalar
theta
;
50
scalar
rho
;
51
};
52
53
//------------------------------------------------------------------------------
56
inline
57
polar::polar
() :
58
theta
(0.0f),
59
rho
(0.0f)
60
{
61
// empty
62
}
63
64
//------------------------------------------------------------------------------
67
inline
68
polar::polar
(
scalar
t,
scalar
r) :
69
theta
(t),
70
rho
(r)
71
{
72
// empty
73
}
74
75
//------------------------------------------------------------------------------
78
inline
79
polar::polar
(
const
vec3
& v)
80
{
81
this->
set
(v);
82
}
83
84
//------------------------------------------------------------------------------
87
inline
88
polar::polar
(
const
polar
& src) :
89
theta
(src.
theta
),
90
rho
(src.
rho
)
91
{
92
// empty
93
}
94
95
//------------------------------------------------------------------------------
98
inline
void
99
polar::operator=
(
const
polar
& rhs)
100
{
101
this->
theta
= rhs.
theta
;
102
this->
rho
= rhs.
rho
;
103
}
104
105
//------------------------------------------------------------------------------
108
inline
void
109
polar::set
(
const
polar
& p)
110
{
111
this->
theta
= p.
theta
;
112
this->
rho
= p.
rho
;
113
}
114
115
//------------------------------------------------------------------------------
118
inline
void
119
polar::set
(
scalar
t,
scalar
r)
120
{
121
this->
theta
= t;
122
this->
rho
= r;
123
}
124
125
//------------------------------------------------------------------------------
129
inline
void
130
polar::set
(
const
vec3
& vec)
131
{
132
vec3
normVec3d =
normalize
(vec);
133
this->
theta
=
Math::acos
(normVec3d.
y
);
134
135
// build a normalized 2d vector of the xz component
136
vec2
normVec2d(normVec3d.
x
, normVec3d.
z
);
137
if
(normVec2d.
length
() >
TINY
)
138
{
139
normVec2d =
vec2::normalize
(normVec2d);
140
}
141
else
142
{
143
normVec2d.
set
(1.0f, 0.0f);
144
}
145
146
// adjust dRho based on the quadrant we are in
147
if
((normVec2d.
x
>= 0.0f) && (normVec2d.
y
>= 0.0f))
148
{
149
// quadrant 1
150
this->
rho
=
Math::asin
(normVec2d.
x
);
151
}
152
else
if
((normVec2d.
x
< 0.0f) && (normVec2d.
y
>= 0.0f))
153
{
154
// quadrant 2
155
this->
rho
=
Math::asin
(normVec2d.
y
) +
Math::deg2rad
(270.0f);
156
}
157
else
if
((normVec2d.
x
< 0.0f) && (normVec2d.
y
< 0.0f))
158
{
159
// quadrant 3
160
this->
rho
=
Math::asin
(-normVec2d.
x
) +
Math::deg2rad
(180.0f);
161
}
162
else
163
{
164
// quadrant 4
165
this->
rho
=
Math::asin
(-normVec2d.
y
) +
Math::deg2rad
(90.0f);
166
}
167
}
168
169
//------------------------------------------------------------------------------
173
inline
vec3
174
polar::get_cartesian
()
const
175
{
176
scalar
sinTheta =
Math::sin
(this->
theta
);
177
scalar
cosTheta =
Math::cos
(this->
theta
);
178
scalar
sinRho =
Math::sin
(this->
rho
);
179
scalar
cosRho =
Math::cos
(this->
rho
);
180
vec3
v(sinTheta * sinRho, cosTheta, sinTheta * cosRho);
181
return
v;
182
}
183
184
}
// namespace Math
185
//------------------------------------------------------------------------------
186
#endif
Math::polar::set
void set(const polar &p)
set to polar object
Definition
polar.h:109
Math::polar::theta
scalar theta
Definition
polar.h:49
Math::polar::polar
polar()
the default constructor
Definition
polar.h:57
Math::polar::get_cartesian
vec3 get_cartesian() const
convert to normalized cartesian coords
Definition
polar.h:174
Math::polar::operator=
void operator=(const polar &rhs)
the assignment operator
Definition
polar.h:99
Math::polar::rho
scalar rho
Definition
polar.h:50
Math
Different curves.
Definition
angularpfeedbackloop.h:17
Math::deg2rad
__forceinline constexpr scalar deg2rad(scalar d)
Definition
scalar.h:487
Math::asin
__forceinline scalar asin(scalar x)
Definition
scalar.h:209
Math::normalize
__forceinline plane normalize(const plane &p)
Definition
plane.h:261
Math::scalar
float scalar
Definition
scalar.h:45
Math::cos
__forceinline scalar cos(scalar x)
Definition
scalar.h:191
Math::acos
__forceinline scalar acos(scalar x)
Definition
scalar.h:218
Math::sin
__forceinline scalar sin(scalar x)
Definition
scalar.h:182
scalar.h
Nebula's scalar datatype.
TINY
#define TINY
Definition
scalar.h:41
Math::vec2
A 2-component float vector class.
Definition
vec2.h:21
Math::vec2::set
void set(scalar x, scalar y)
set content
Definition
vec2.h:200
Math::vec2::x
scalar x
Definition
vec2.h:88
Math::vec2::normalize
static vec2 normalize(const vec2 &v)
return normalized version of vector
Definition
vec2.h:323
Math::vec2::y
scalar y
Definition
vec2.h:89
Math::vec2::length
scalar length() const
return length of vector
Definition
vec2.h:230
Math::vec3
A 3D vector.
Definition
vec3.h:37
Math::vec3::x
float x
Definition
vec3.h:93
Math::vec3::z
float z
Definition
vec3.h:93
Math::vec3::y
float y
Definition
vec3.h:93
vec2.h
vec3.h
code
foundation
math
polar.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.