67 real(RP),
intent(in) :: x
68 real(RP),
intent(in) :: y
69 real(RP),
intent(in) :: z
70 real(RP),
intent(out) :: lat
71 real(RP),
intent(out) :: lon
73 real(RP) :: length, length_h
76 length = sqrt( x*x + y*y + z*z )
78 if ( length < eps )
then 84 if ( z / length >= 1.0_rp )
then 88 elseif( z / length <= -1.0_rp )
then 93 lat = asin( z / length )
96 length_h = sqrt( x*x + y*y )
98 if ( length_h < eps )
then 103 if ( x / length_h >= 1.0_rp )
then 105 elseif( x / length_h <= -1.0_rp )
then 108 lon = acos( x / length_h )
111 if( y < 0.0_rp ) lon = -lon
126 real(RP),
intent(in) :: lat
127 real(RP),
intent(in) :: lon
128 real(RP),
intent(out) :: x
129 real(RP),
intent(out) :: y
130 real(RP),
intent(out) :: z
131 real(RP),
intent(in) :: radius
134 x = radius * cos(lat) * cos(lon)
135 y = radius * cos(lat) * sin(lon)
136 z = radius * sin(lat)
146 real(RP),
intent(out) :: nv(3)
147 real(RP),
intent(in) :: a(3), b(3), c(3), d(3)
150 nv(1) = ( b(2)-a(2) ) * ( d(3)-c(3) ) &
151 - ( b(3)-a(3) ) * ( d(2)-c(2) )
152 nv(2) = ( b(3)-a(3) ) * ( d(1)-c(1) ) &
153 - ( b(1)-a(1) ) * ( d(3)-c(3) )
154 nv(3) = ( b(1)-a(1) ) * ( d(2)-c(2) ) &
155 - ( b(2)-a(2) ) * ( d(1)-c(1) )
165 real(RP),
intent(out) :: l
166 real(RP),
intent(in) :: a(3), b(3), c(3), d(3)
170 l = ( b(1)-a(1) ) * ( d(1)-c(1) ) &
171 + ( b(2)-a(2) ) * ( d(2)-c(2) ) &
172 + ( b(3)-a(3) ) * ( d(3)-c(3) )
182 real(RP),
intent(out) :: l
183 real(RP),
intent(in) :: a(3)
186 l = a(1)*a(1) + a(2)*a(2) + a(3)*a(3)
197 real(RP),
intent(out) :: angle
198 real(RP),
intent(in) :: a(3), b(3), c(3)
200 real(RP) :: nv(3), nvlens, nvlenc
206 angle = atan2( nvlens, nvlenc )
218 logical,
intent(out) :: ifcross
221 real(RP),
intent(out) :: p(3)
222 real(RP),
intent(in) :: a(3), b(3), c(3), d(3)
224 real(RP),
parameter :: o(3) = 0.0_rp
226 real(RP) :: oaob(3), ocod(3), cdab(3)
227 real(RP) :: ip, length
228 real(RP) :: angle_aop, angle_pob, angle_aob
229 real(RP) :: angle_cop, angle_pod, angle_cod
239 p(:) = cdab(:) / sign(length,ip)
255 if ( abs(angle_aob-(angle_aop+angle_pob)) < eps &
256 .AND. abs(angle_cod-(angle_cop+angle_pod)) < eps &
257 .AND. abs(angle_aop) > eps &
258 .AND. abs(angle_pob) > eps &
259 .AND. abs(angle_cop) > eps &
260 .AND. abs(angle_pod) > eps )
then 277 integer,
intent(in) :: nvert
278 real(RP),
intent(inout) :: vertex(nvert,3)
280 real(RP),
parameter :: o(3) = 0.0_rp
282 real(RP) :: v1(3), v2(3), v3(3)
283 real(RP) :: xp(3), ip
284 real(RP) :: angle1, angle2
295 call vectr_cross( xp(:), v1(:), v2(:), v1(:), v3(:) )
296 call vectr_dot ( ip, o(:), v1(:), o(:), xp(:) )
298 if ( ip < -eps )
then 311 call vectr_cross( xp(:), v1(:), v2(:), v1(:), v3(:) )
312 call vectr_dot ( ip, o(:), v1(:), o(:), xp(:) )
318 .AND. abs(angle2)-abs(angle1) < 0.0_rp )
then 324 v2(:) = vertex(nvert ,:)
325 v3(:) = vertex(nvert-1,:)
327 call vectr_cross( xp(:), v1(:), v2(:), v1(:), v3(:) )
328 call vectr_dot ( ip, o(:), v1(:), o(:), xp(:) )
334 .AND. abs(angle2)-abs(angle1) < 0.0_rp )
then 336 vertex(nvert, :) = v3(:)
337 vertex(nvert-1,:) = v2(:)
356 real(RP),
intent(in) :: a(3), b(3), c(3)
357 character(len=*),
intent(in) :: polygon_type
358 real(RP),
intent(in) :: radius
361 real(RP),
parameter :: o(3) = 0.0_rp
369 real(RP) :: oaob(3), oaoc(3)
370 real(RP) :: oboc(3), oboa(3)
371 real(RP) :: ocoa(3), ocob(3)
372 real(RP) :: abab, acac
373 real(RP) :: bcbc, baba
374 real(RP) :: caca, cbcb
379 if ( polygon_type ==
'ON_PLANE' )
then 387 print *,
"zero length?", a(:)
392 area = prd * r*r * radius*radius
394 elseif( polygon_type ==
'ON_SPHERE' )
then 397 call vectr_cross( oaob(:), o(:), a(:), o(:), b(:) )
398 call vectr_cross( oaoc(:), o(:), a(:), o(:), c(:) )
402 if ( abab < eps .OR. acac < eps )
then 407 call vectr_angle( angle(1), oaob(:), o(:), oaoc(:) )
410 call vectr_cross( oboc(:), o(:), b(:), o(:), c(:) )
415 if ( bcbc < eps .OR. baba < eps )
then 420 call vectr_angle( angle(2), oboc(:), o(:), oboa(:) )
428 if ( caca < eps .OR. cbcb < eps )
then 433 call vectr_angle( angle(3), ocoa(:), o(:), ocob(:) )
436 area = ( angle(1)+angle(2)+angle(3) - pi ) * radius*radius
451 real(RP),
intent(in) :: a(3), b(3), c(3)
454 real(RP) :: len_ab, len_ac, prd
461 area = 0.5_rp * sqrt( len_ab * len_ac - prd * prd )
473 real(RP),
intent(inout) :: a(3)
474 real(RP),
intent(in) :: angle
475 integer,
intent(in) :: iaxis
477 real(RP) :: m(3,3), b(3)
492 elseif( iaxis ==
i_yaxis )
then 504 elseif( iaxis ==
i_zaxis )
then 520 b(1) = m(1,1) * a(1) + m(1,2) * a(2) + m(1,3) * a(3)
521 b(2) = m(2,1) * a(1) + m(2,2) * a(2) + m(2,3) * a(3)
522 b(3) = m(3,1) * a(1) + m(3,2) * a(2) + m(3,3) * a(3)
540 real(RP),
intent(in) :: r
541 real(RP),
intent(in) :: lon1, lat1
542 real(RP),
intent(in) :: lon2, lat2
543 real(RP),
intent(out) :: dist
545 real(RP) :: gmm, gno_x, gno_y
548 gmm = sin(lat1) * sin(lat2) &
549 + cos(lat1) * cos(lat2) * cos(lon2-lon1)
551 gno_x = gmm * ( cos(lat2) * sin(lon2-lon1) )
552 gno_y = gmm * ( cos(lat1) * sin(lat2) &
553 - sin(lat1) * cos(lat2) * cos(lon2-lon1) )
555 dist = r * atan2( sqrt(gno_x*gno_x+gno_y*gno_y), gmm )
subroutine, public vectr_dot(l, a, b, c, d)
interior product of vector a->b and c->d
integer, parameter, public i_zaxis
subroutine, public vectr_anticlockwise(vertex, nvert)
bubble sort anticlockwise by angle
subroutine, public vectr_rotation(a, angle, iaxis)
Apply rotation matrix.
integer, parameter, public i_xaxis
real(rp) function, public vectr_triangle_plane(a, b, c)
calc triangle area on plane
integer, parameter, public i_yaxis
real(rp) function, public vectr_triangle(a, b, c, polygon_type, radius)
calc triangle area
subroutine, public vectr_abs(l, a)
length of vector o->a
subroutine, public vectr_distance(r, lon1, lat1, lon2, lat2, dist)
Get horizontal distance on the sphere.
subroutine, public vectr_cross(nv, a, b, c, d)
exterior product of vector a->b and c->d
subroutine, public vectr_xyz2latlon(x, y, z, lat, lon)
real(rp), public const_eps
small number
subroutine, public vectr_intersec(ifcross, p, a, b, c, d)
judge intersection of two vector
subroutine, public vectr_angle(angle, a, b, c)
calc angle between two vector(b->a,b->c)
real(rp), public const_pi
pi
subroutine, public vectr_latlon2xyz(lat, lon, x, y, z, radius)