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 = gmm * ( cos(lat2) * sin(lon2-lon1) )
553 gno_y = gmm * ( cos(lat1) * sin(lat2) &
554 - sin(lat1) * cos(lat2) * cos(lon2-lon1) )
556 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)