polar_to_cartesian(3f) - [M_pixel:TRIGONOMETRY] convert polar
coordinates to Cartesian coordinates
(LICENSE:PD)
subroutine polar_to_cartesian(radius,inclination,x,y)
real,intent(in) :: radius,inclination
real,intent(out) :: x,y
Convert polar coordinate <radius, inclination > with
angles in radians to cartesian point <X,Y> using the formulas
x=radius*cos(inclination)
y=radius*sin(inclination)
RADIUS The radial distance from the origin (O) to the point (P)
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).
X The distance along the x-axis
Y The distance along the y-axis
examples of usage
program demo_polar_to_cartesian
use M_pixel, only : polar_to_cartesian
implicit none
real :: x,y
real :: r,i
!!integer :: ios
!!INFINITE: do
!! write(*,advance='no')'Enter radius and inclination(in radians):'
!! read(*,*,iostat=ios) r, i
!! if(ios.ne.0)exit INFINITE
call polar_to_cartesian(r,i,x,y)
write(*,*)'x=',x,' y=',y,'radius=',r,'inclination=',i
!!enddo INFINITE
end program demo_polar_to_cartesian
John S. Urban
Public Domain
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real, | intent(in) | :: | radius | |||
real, | intent(in) | :: | inclination | |||
real, | intent(out) | :: | x | |||
real, | intent(out) | :: | y |
subroutine polar_to_cartesian(radius,inclination,x,y)
implicit none
! ident_75="@(#) M_pixel polar_to_cartesian(3f) convert polar coordinates to cartesian coordinates"
real,intent(in) :: radius,inclination
real,intent(out) :: x,y
if(radius.eq.0)then
x=0.0
y=0.0
else
x=radius*cos(inclination)
y=radius*sin(inclination)
endif
end subroutine polar_to_cartesian