atan2d (Core Functions)


Import

#include <archr/core/atan2d.h>
#include <archr/core/atan2d.hpp>
import archr.core
atomsLoads('archr')

Synopsis

 float archr_core_atan2d_1f32f32(const float i1, const float i2);
(1)
 double archr_core_atan2d_1f64f64(const double i1, const double i2);
(2)
 void archr_core_atan2d_f32f32(float *o0, const float *i1, size_t sz, const float *i2);
(3)
 void archr_core_atan2d_f64f64(double *o0, const double *i1, size_t sz, const double *i2);
(4)
 float atan2d(const float i1, const float i2);
(1)
 double atan2d(const double i1, const double i2);
(2)
 void atan2d(const float *i1, size_t sz, const float *i2, float *o0);
(3)
 void atan2d(const double *i1, size_t sz, const double *i2, double *o0);
(4)
template <typename Range> void atan2d(const Range& i1, const Range& i2, Range& o0);
(5)
subroutine archr_core_atan2d_1f32f32(real(4) :: r, real(4), parameter :: i1, real(4), parameter :: i2)
(1)
subroutine archr_core_atan2d_1f64f64(real(8) :: r, real(8), parameter :: i1, real(8), parameter :: i2)
(2)
subroutine archr_core_atan2d_f32f32(real(4), dimension(*), parameter :: i1, integer(4) :: sz, real(4), dimension(*), parameter :: i2, real(4), dimension(*) :: o0)
(3)
subroutine archr_core_atan2d_f64f64(real(8), dimension(*), parameter :: i1, integer(4) :: sz, real(8), dimension(*), parameter :: i2, real(8), dimension(*) :: o0)
(4)
def atan2d(i1, i2):
    return o0
(1)
function o0 = archr_core_atan2d(i1, i2)
(1)

Description

Computes the Four-Quadrant Inverse Tangent in Degrees:

Parameters

i1_first, i1_last

The first range of input elements

i2

The beggining of the the second range of input elements

o0

The beginning of the destination range, may be equal to i1 or i2

i1, i2

The scalar/contiguous data input elements

Example


#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <archr/core/atan2d.h>

double rand_in(double min, double max) {
  return min + ((double)(max - min) * ((double)rand() / RAND_MAX));
}

int main() {
  time_t t;
  size_t i;
  size_t sz = 10;
  float* i1 = (float*)malloc(sz * sizeof(float));
  float* i2 = (float*)malloc(sz * sizeof(float));
  float* o1 = (float*)malloc(sz * sizeof(float));

  srand((unsigned int)time(&t));
  for (i = 0; i < sz; ++i) {
    i1[i] = (float)rand_in((float)-10, (float)10);
  i2[i] = (float)rand_in((float)-10, (float)10);
  }
  archr_core_atan2d_f32f32(o1, i1, sz, i2);
  for (i = 0; i < sz; ++i) {
    printf("%4lu: atan2d(%f, %f) = %f\n", i, (double)i1[i], (double)i2[i], (double)o1[i]);
  }
}

Possible Output

   0: atan2d(9.422858, 1.837882) = 78.963303
   1: atan2d(-3.262253, -7.822172) = -157.361328
   2: atan2d(-5.006380, -8.051063) = -148.125488
   3: atan2d(4.945784, 9.347142) = 27.884327
   4: atan2d(5.106514, 6.345078) = 38.827084
   5: atan2d(-0.338315, -6.329839) = -176.940582
   6: atan2d(1.881994, 0.493357) = 75.310677
   7: atan2d(-2.940464, -9.900811) = -163.459000
   8: atan2d(-3.023084, -9.771577) = -162.809235
   9: atan2d(8.596566, 9.594168) = 41.860977

#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <archr/core/atan2d.hpp>

double rand_in(double min, double max) {
  return min + (double(max - min) * (double(std::rand()) / RAND_MAX));
}

int main() {
  std::size_t i;
  std::size_t sz = 10;
  std::vector<float> i1(sz);
  std::vector<float> i2(sz);
  std::vector<float> o1(sz);

  std::srand(std::time(0));
  std::generate(i1.begin(), i1.end(), []() { return rand_in(float(-10), float(10)); });
  std::generate(i2.begin(), i2.end(), []() { return rand_in(float(-10), float(10)); });
  archr::core::atan2d(i1.data(), sz, i2.data(), o1.data());
  for (i = 0; i < sz; ++i) {
    std::cout << std::setw(4) << i << ": " << "atan2d" << "(" << i1[i] << ", " << i2[i] << ")" << " = " << o1[i] << std::endl;
  }
}

Possible Output

   0: atan2d(9.42286, -0.338315) = 92.0563
   1: atan2d(1.83788, -6.32984) = 163.809
   2: atan2d(-3.26225, 1.88199) = -60.0193
   3: atan2d(-7.82217, 0.493357) = -86.391
   4: atan2d(-5.00638, -2.94046) = -120.428
   5: atan2d(-8.05106, -9.90081) = -140.883
   6: atan2d(4.94578, -3.02308) = 121.435
   7: atan2d(9.34714, -9.77158) = 136.272
   8: atan2d(5.10651, 8.59657) = 30.7111
   9: atan2d(6.34508, 9.59417) = 33.4786

program main
  integer(4), parameter  :: sz = 10
  real(4), dimension(sz) :: o0
  real(4), dimension(sz) :: i0
  real(4), dimension(sz) :: i1
  real(8)                :: r0, r1
  real(8)                :: min0, max0
  real(8)                :: min1, max1
  real(8)                :: min2, max2
  ! Init:
    min0 = -10
    max0 = 10
    min1 = -10
    max1 = 10
  do i=1,sz
    r0 = random_in(min0, max0)
    r1 = random_in(min1, max1)
    i0(i) = r0
    i1(i) = r1
  end do
  ! Example:
  call archr_core_atan2d_f32f32(o0, i0, size(i0), i1)
  ! Output:
  do i=1,sz
    print *, i, ": ", o0(i)
  end do
contains
  ! Generate a random number within a range
  function random_in(mn, mx) result(r)
    real(8) :: r
    real(8), intent(in) :: mn, mx
    r = mn + (rand() * (mx - mn))
  end function random_in
end program

Possible Output

           1 :   -126.387840    
           2 :    99.1892776    
           3 :    173.349823    
           4 :   -68.4517746    
           5 :    22.4145088    
           6 :   -80.5376816    
           7 :    144.583420    
           8 :   -86.1947632    
           9 :    160.829941    
          10 :   -164.935822