68 real(
rp),
intent(in) :: x
69 real(
rp),
intent(in) :: y
70 real(
rp),
intent(in) :: z
71 real(
rp),
intent(out) :: lat
72 real(
rp),
intent(out) :: lon
74 real(
rp) :: length, length_h
77 length = sqrt( x*x + y*y + z*z )
79 if ( length < eps )
then
85 if ( z / length >= 1.0_rp )
then
89 elseif( z / length <= -1.0_rp )
then
94 lat = asin( z / length )
97 length_h = sqrt( x*x + y*y )
99 if ( length_h < eps )
then
104 if ( x / length_h >= 1.0_rp )
then
106 elseif( x / length_h <= -1.0_rp )
then
109 lon = acos( x / length_h )
112 if( y < 0.0_rp ) lon = -lon
127 real(
rp),
intent(in) :: lat
128 real(
rp),
intent(in) :: lon
129 real(
rp),
intent(out) :: x
130 real(
rp),
intent(out) :: y
131 real(
rp),
intent(out) :: z
132 real(
rp),
intent(in) :: radius
135 x = radius * cos(lat) * cos(lon)
136 y = radius * cos(lat) * sin(lon)
137 z = radius * sin(lat)
147 real(
rp),
intent(out) :: nv(3)
148 real(
rp),
intent(in) :: a(3), b(3), c(3), d(3)
151 nv(1) = ( b(2)-a(2) ) * ( d(3)-c(3) ) &
152 - ( b(3)-a(3) ) * ( d(2)-c(2) )
153 nv(2) = ( b(3)-a(3) ) * ( d(1)-c(1) ) &
154 - ( b(1)-a(1) ) * ( d(3)-c(3) )
155 nv(3) = ( b(1)-a(1) ) * ( d(2)-c(2) ) &
156 - ( b(2)-a(2) ) * ( d(1)-c(1) )
166 real(
rp),
intent(out) :: l
167 real(
rp),
intent(in) :: a(3), b(3), c(3), d(3)
171 l = ( b(1)-a(1) ) * ( d(1)-c(1) ) &
172 + ( b(2)-a(2) ) * ( d(2)-c(2) ) &
173 + ( b(3)-a(3) ) * ( d(3)-c(3) )
183 real(
rp),
intent(out) :: l
184 real(
rp),
intent(in) :: a(3)
187 l = a(1)*a(1) + a(2)*a(2) + a(3)*a(3)
198 real(
rp),
intent(out) :: angle
199 real(
rp),
intent(in) :: a(3), b(3), c(3)
201 real(
rp) :: nv(3), nvlens, nvlenc
207 angle = atan2( nvlens, nvlenc )
219 logical,
intent(out) :: ifcross
222 real(
rp),
intent(out) :: p(3)
223 real(
rp),
intent(in) :: a(3), b(3), c(3), d(3)
225 real(
rp),
parameter :: o(3) = 0.0_rp
227 real(
rp) :: oaob(3), ocod(3), cdab(3)
228 real(
rp) :: ip, length
229 real(
rp) :: angle_aop, angle_pob, angle_aob
230 real(
rp) :: angle_cop, angle_pod, angle_cod
240 p(:) = cdab(:) / sign(length,ip)
256 if ( abs(angle_aob-(angle_aop+angle_pob)) < eps &
257 .AND. abs(angle_cod-(angle_cop+angle_pod)) < eps &
258 .AND. abs(angle_aop) > eps &
259 .AND. abs(angle_pob) > eps &
260 .AND. abs(angle_cop) > eps &
261 .AND. abs(angle_pod) > eps )
then
278 integer,
intent(in) :: nvert
279 real(
rp),
intent(inout) :: vertex(nvert,3)
281 real(
rp),
parameter :: o(3) = 0.0_rp
283 real(
rp) :: v1(3), v2(3), v3(3)
284 real(
rp) :: xp(3), ip
285 real(
rp) :: angle1, angle2
296 call vectr_cross( xp(:), v1(:), v2(:), v1(:), v3(:) )
297 call vectr_dot ( ip, o(:), v1(:), o(:), xp(:) )
299 if ( ip < -eps )
then
312 call vectr_cross( xp(:), v1(:), v2(:), v1(:), v3(:) )
313 call vectr_dot ( ip, o(:), v1(:), o(:), xp(:) )
319 .AND. abs(angle2)-abs(angle1) < 0.0_rp )
then
325 v2(:) = vertex(nvert ,:)
326 v3(:) = vertex(nvert-1,:)
328 call vectr_cross( xp(:), v1(:), v2(:), v1(:), v3(:) )
329 call vectr_dot ( ip, o(:), v1(:), o(:), xp(:) )
335 .AND. abs(angle2)-abs(angle1) < 0.0_rp )
then
337 vertex(nvert, :) = v3(:)
338 vertex(nvert-1,:) = v2(:)
357 real(
rp),
intent(in) :: a(3), b(3), c(3)
358 character(len=*),
intent(in) :: polygon_type
359 real(
rp),
intent(in) :: radius
362 real(
rp),
parameter :: o(3) = 0.0_rp
370 real(
rp) :: oaob(3), oaoc(3)
371 real(
rp) :: oboc(3), oboa(3)
372 real(
rp) :: ocoa(3), ocob(3)
373 real(
rp) :: abab, acac
374 real(
rp) :: bcbc, baba
375 real(
rp) :: caca, cbcb
380 if ( polygon_type ==
'ON_PLANE' )
then
388 print *,
"zero length?", a(:)
393 area = prd * r*r * radius*radius
395 elseif( polygon_type ==
'ON_SPHERE' )
then
398 call vectr_cross( oaob(:), o(:), a(:), o(:), b(:) )
399 call vectr_cross( oaoc(:), o(:), a(:), o(:), c(:) )
403 if ( abab < eps .OR. acac < eps )
then
408 call vectr_angle( angle(1), oaob(:), o(:), oaoc(:) )
411 call vectr_cross( oboc(:), o(:), b(:), o(:), c(:) )
416 if ( bcbc < eps .OR. baba < eps )
then
421 call vectr_angle( angle(2), oboc(:), o(:), oboa(:) )
429 if ( caca < eps .OR. cbcb < eps )
then
434 call vectr_angle( angle(3), ocoa(:), o(:), ocob(:) )
437 area = ( angle(1)+angle(2)+angle(3) - pi ) * radius*radius
452 real(
rp),
intent(in) :: a(3), b(3), c(3)
455 real(
rp) :: len_ab, len_ac, prd
462 area = 0.5_rp * sqrt( len_ab * len_ac - prd * prd )
474 real(
rp),
intent(inout) :: a(3)
475 real(
rp),
intent(in) :: angle
476 integer,
intent(in) :: iaxis
478 real(
rp) :: m(3,3), b(3)
493 elseif( iaxis ==
i_yaxis )
then
505 elseif( iaxis ==
i_zaxis )
then
521 b(1) = m(1,1) * a(1) + m(1,2) * a(2) + m(1,3) * a(3)
522 b(2) = m(2,1) * a(1) + m(2,2) * a(2) + m(2,3) * a(3)
523 b(3) = m(3,1) * a(1) + m(3,2) * a(2) + m(3,3) * a(3)
541 real(
rp),
intent(in) :: r
542 real(
rp),
intent(in) :: lon1, lat1
543 real(
rp),
intent(in) :: lon2, lat2
544 real(
rp),
intent(out) :: dist
546 real(
rp) :: gmm, gno_x, gno_y
549 gmm = sin(lat1) * sin(lat2) &
550 + cos(lat1) * cos(lat2) * cos(lon2-lon1)
552 gno_x = ( cos(lat2) * sin(lon2-lon1) )
553 gno_y = ( cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon2-lon1) )
555 dist = r * atan2( sqrt(gno_x*gno_x+gno_y*gno_y), gmm )