61 real(RP),
intent(in) :: x
62 real(RP),
intent(in) :: y
63 real(RP),
intent(in) :: z
64 real(RP),
intent(out) :: lat
65 real(RP),
intent(out) :: lon
67 real(RP) :: length, length_h
70 length = sqrt( x*x + y*y + z*z )
78 if ( z / length >= 1.0_rp )
then 82 elseif( z / length <= -1.0_rp )
then 87 lat = asin( z / length )
90 length_h = sqrt( x*x + y*y )
97 if ( x / length_h >= 1.0_rp )
then 99 elseif( x / length_h <= -1.0_rp )
then 102 lon = acos( x / length_h )
105 if( y < 0.0_rp ) lon = -lon
120 real(RP),
intent(in) :: lat
121 real(RP),
intent(in) :: lon
122 real(RP),
intent(out) :: x
123 real(RP),
intent(out) :: y
124 real(RP),
intent(out) :: z
125 real(RP),
intent(in) :: radius
128 x = radius * cos(lat) * cos(lon)
129 y = radius * cos(lat) * sin(lon)
130 z = radius * sin(lat)
140 real(RP),
intent(out) :: nv(3)
141 real(RP),
intent(in ) :: a(3), b(3), c(3), d(3)
144 nv(1) = ( b(2)-a(2) ) * ( d(3)-c(3) ) &
145 - ( b(3)-a(3) ) * ( d(2)-c(2) )
146 nv(2) = ( b(3)-a(3) ) * ( d(1)-c(1) ) &
147 - ( b(1)-a(1) ) * ( d(3)-c(3) )
148 nv(3) = ( b(1)-a(1) ) * ( d(2)-c(2) ) &
149 - ( b(2)-a(2) ) * ( d(1)-c(1) )
159 real(RP),
intent(out) :: l
160 real(RP),
intent(in ) :: a(3), b(3), c(3), d(3)
164 l = ( b(1)-a(1) ) * ( d(1)-c(1) ) &
165 + ( b(2)-a(2) ) * ( d(2)-c(2) ) &
166 + ( b(3)-a(3) ) * ( d(3)-c(3) )
176 real(RP),
intent(out) :: l
177 real(RP),
intent(in ) :: a(3)
180 l = a(1)*a(1) + a(2)*a(2) + a(3)*a(3)
191 real(RP),
intent(out) :: angle
192 real(RP),
intent(in ) :: a(3), b(3), c(3)
194 real(RP) :: nv(3), nvlenS, nvlenC
200 angle = atan2( nvlens, nvlenc )
210 logical,
intent(out) :: ifcross
213 real(RP),
intent(out) :: p(3)
214 real(RP),
intent(in ) :: a(3), b(3), c(3), d(3)
216 real(RP),
parameter :: o(3) = 0.0_rp
218 real(RP) :: oaob(3), ocod(3), cdab(3)
219 real(RP) :: ip, length
220 real(RP) :: angle_aop, angle_pob, angle_aob
221 real(RP) :: angle_cop, angle_pod, angle_cod
223 real(RP),
parameter :: eps = 1.e-12_rp
233 p(:) = cdab(:) / sign(length,ip)
249 if ( abs(angle_aob-(angle_aop+angle_pob)) < eps &
250 .AND. abs(angle_cod-(angle_cop+angle_pod)) < eps &
251 .AND. abs(angle_aop) > eps &
252 .AND. abs(angle_pob) > eps &
253 .AND. abs(angle_cop) > eps &
254 .AND. abs(angle_pod) > eps )
then 269 integer,
intent(in) :: nvert
270 real(RP),
intent(inout) :: vertex(nvert,3)
272 real(RP),
parameter :: o(3) = 0.0_rp
273 real(RP) :: v1(3), v2(3), v3(3)
274 real(RP) :: xp(3), ip
275 real(RP) :: angle1, angle2
277 real(RP),
parameter :: eps = 1.e-12_rp
288 call vectr_cross( xp(:), v1(:), v2(:), v1(:), v3(:) )
289 call vectr_dot ( ip, o(:), v1(:), o(:), xp(:) )
291 if ( ip < -eps )
then 304 call vectr_cross( xp(:), v1(:), v2(:), v1(:), v3(:) )
305 call vectr_dot ( ip, o(:), v1(:), o(:), xp(:) )
311 .AND. abs(angle2)-abs(angle1) < 0.0_rp )
then 317 v2(:) = vertex(nvert ,:)
318 v3(:) = vertex(nvert-1,:)
320 call vectr_cross( xp(:), v1(:), v2(:), v1(:), v3(:) )
321 call vectr_dot ( ip, o(:), v1(:), o(:), xp(:) )
327 .AND. abs(angle2)-abs(angle1) < 0.0_rp )
then 329 vertex(nvert, :) = v3(:)
330 vertex(nvert-1,:) = v2(:)
338 a, b, c, & !--- IN : three point vectors on a sphere.
339 polygon_type, & !--- IN : sphere triangle or plane one?
347 real(RP),
intent(in) :: a(3), b(3), c(3)
348 character(len=*),
intent(in) :: polygon_type
349 real(RP),
intent(in) :: radius
352 real(RP),
parameter :: o(3) = 0.0_rp
360 real(RP) :: oaob(3), oaoc(3)
361 real(RP) :: oboc(3), oboa(3)
362 real(RP) :: ocoa(3), ocob(3)
363 real(RP) :: abab, acac
364 real(RP) :: bcbc, baba
365 real(RP) :: caca, cbcb
370 if ( polygon_type ==
'ON_PLANE' )
then 378 print *,
"zero length?", a(:)
383 area = prd * r*r * radius*radius
385 elseif( polygon_type ==
'ON_SPHERE' )
then 388 call vectr_cross( oaob(:), o(:), a(:), o(:), b(:) )
389 call vectr_cross( oaoc(:), o(:), a(:), o(:), c(:) )
398 call vectr_angle( angle(1), oaob(:), o(:), oaoc(:) )
401 call vectr_cross( oboc(:), o(:), b(:), o(:), c(:) )
411 call vectr_angle( angle(2), oboc(:), o(:), oboa(:) )
424 call vectr_angle( angle(3), ocoa(:), o(:), ocob(:) )
427 area = ( angle(1)+angle(2)+angle(3) -
const_pi ) * radius*radius
445 real(RP),
intent(in) :: r
446 real(RP),
intent(in) :: lon1, lat1
447 real(RP),
intent(in) :: lon2, lat2
448 real(RP),
intent(out) :: dist
450 real(RP) :: gmm, gno_x, gno_y
453 gmm = sin(lat1) * sin(lat2) &
454 + cos(lat1) * cos(lat2) * cos(lon2-lon1)
456 gno_x = gmm * ( cos(lat2) * sin(lon2-lon1) )
457 gno_y = gmm * ( cos(lat1) * sin(lat2) &
458 - sin(lat1) * cos(lat2) * cos(lon2-lon1) )
460 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
subroutine, public vectr_anticlockwise(vertex, nvert)
bubble sort anticlockwise by angle
real(rp) function, public vectr_triangle(a, b, c, polygon_type, radius)
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)