C Library Functions  - cartesian_to_polar (3)

NAME

cartesian_to_polar(3f) - [M_units:TRIGONOMETRY] convert Cartesian coordinates to polar coordinates (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Results
Examples
Author
License

SYNOPSIS

subroutine cartesian_to_polar(x,y,radius,inclination)

     real,intent(in)  :: x,y
     real,intent(out) :: radius,inclination

subroutine cartesian_to_polar(xy,radius,inclination)

     complex,intent(in) :: xy
     real,intent(out) :: radius,inclination

DESCRIPTION

Convert a cartesian point <X,Y> to polar coordinates <radius, inclination> with angles in radians equivalent to using the formulas

       radius=sqrt(x**2+y**2)
       inclination=atan2(y,x)

where if inclination is negative, add PI.

OPTIONS

X The distance along the x-axis
Y The distance along the y-axis
XY Alternatively to using X and Y a complex value may be used. The real component will be treated as the X coordinate, and the imaginary component defines the Y coordinate of the input point.
If the input point <0.0,0.0> is used the inclination is arbitrarily returned as zero.

RESULTS

RADIUS The radial distance from the origin (O) to the point <X,Y>. If it exceeds huge(0.0), (-1)-huge(0.0) is returned.
INCLINATION
  The inclination angle in radians between the inclination reference direction (x-axis) and the orthogonal projection of the line OP of the reference plane (x-y plane) in the range 0 <= INCLINATION < 2*PI radians. If the radius value exceeds huge(0) -1 is returned, else zero (0) is returned if no error occurs.

EXAMPLES

sample program:

   program demo_cartesian_to_polar
   use M_units, only : cartesian_to_polar
   ! basic cardinal directions
      call  printme( +1.0, +0.0)
      call  printme( +0.0, +1.0)
      call  printme( -1.0, +0.0)
      call  printme( +0.0, -1.0)
   ! the 3-4-5 right triangle
      call  printme( +4.0, +3.0)
      call  printme( +3.0, +4.0)
      call  printme( -3.0, +4.0)
      call  printme( -4.0, +3.0)
      call  printme( -4.0, -3.0)
      call  printme( -3.0, -4.0)
      call  printme( +3.0, -4.0)
      call  printme( +4.0, -3.0)
      write(*,’(*(g0))’) ’cases where input is too large:’
      call  printme( huge(0.0),huge(0.0))
      stopit: block
         real :: radius, inclination
         call cartesian_to_polar( huge(0.0), huge(0.0), radius, inclination)
      endblock stopit
   contains
   subroutine printme(x,y)
   real,intent(in):: x,y
   real :: radius,inclination
   integer :: ierr
      call cartesian_to_polar(x,y,radius,inclination,ierr)
      write(*,*)ierr, x,y,radius,inclination,inclination*180/acos(-1.0)
   end subroutine printme
   end program demo_cartesian_to_polar

Results:

  >            0   1.00000000       0.00000000       1.00000000       0.00000000       0.00000000
  >            0   0.00000000       1.00000000       1.00000000       1.57079637       90.0000000
  >            0  -1.00000000       0.00000000       1.00000000       3.14159274       180.000000
  >            0   0.00000000      -1.00000000       1.00000000       4.71238899       270.000000
  >            0   4.00000000       3.00000000       5.00000000      0.643501103       36.8698959
  >            0   3.00000000       4.00000000       5.00000000      0.927295208       53.1301003
  >            0  -3.00000000       4.00000000       5.00000000       2.21429753       126.869896
  >            0  -4.00000000       3.00000000       5.00000000       2.49809170       143.130096
  >            0  -4.00000000      -3.00000000       5.00000000       3.78509378       216.869904
  >            0  -3.00000000      -4.00000000       5.00000000       4.06888771       233.130081
  >            0   3.00000000      -4.00000000       5.00000000       5.35589027       306.869904
  >            0   4.00000000      -3.00000000       5.00000000       5.63968420       323.130096
  > cases where input is too large:
  >            1   3.40282347E+38   3.40282347E+38  -3.40282347E+38  0.785398185       45.0000000
  > STOP <ERROR> *cartesian_to_polar* overflow. radius=0.48123190965235028E+39

AUTHOR

John S. Urban

LICENSE

Public Domain


Nemo Release 3.1 cartesian_to_polar (3) February 23, 2025
Generated by manServer 1.08 from dcc14b4e-49fd-45b8-90b2-ce2ddc577fe5 using man macros.