Euphoria
polarcoord.cc
Go to the documentation of this file.
1 #include "base/polarcoord.h"
2 
3 #include "base/numeric.h"
4 #include "base/range.h"
5 #include "assert/assert.h"
6 #include "base/random.h"
7 
8 namespace eu
9 {
10  PolarCoordinate::PolarCoordinate(float azimuthal01, float polar01)
11  : azimuthal(Angle::from_percent_of_360(azimuthal01))
12  , polar(Angle::from_percent_of_180(polar01))
13  {
14  ASSERT(is_within(r01, azimuthal01));
15  ASSERT(is_within(Range<float> {0, 2}, polar01));
16  }
17 
18  unit3f
20  {
21  const float cos_a = cos(azimuthal);
22  const float sin_p = sin(polar);
23  const float sin_a = sin(azimuthal);
24  const float cos_p = cos(polar);
25 
26  const float x = cos_a * sin_p;
27  const float y = sin_a * sin_p;
28  const float z = cos_p;
29 
30  return unit3f::to_unit(x, y, z);
31  }
32 
35  {
36  const float az = random->get_next_float01();
37  const float polar = random->get_next_float01();
38  return {az, polar};
39  }
40 
41  unit3f
43  {
45  }
46 
47 }
#define ASSERT(x)
Definition: assert.h:29
Definition: assert.h:90
unit3f get_random_unit3(Random *random)
Definition: polarcoord.cc:42
float cos(const Angle &ang)
Definition: angle.cc:68
constexpr Range< float > r01
Definition: range.h:57
float sin(const Angle &ang)
Definition: angle.cc:61
bool is_within(const Range< T > &range, T value)
Definition: range.h:108
PolarCoordinate(float azimuthal01, float polar01)
Definition: polarcoord.cc:10
static PolarCoordinate create_random(::eu::Random *random)
Definition: polarcoord.cc:34
unit3f to_unit_vector() const
Definition: polarcoord.cc:19
WEL512 Random Number Generator.
Definition: random.h:21
static unit3f to_unit(float x, float y, float z)
Definition: vec3.cc:192