2017年9月15日金曜日

python module which generates the list of points, which are on an ellipse on the Earth.

Because, interestingly, there is no command which draws ellipse/circle in KML


import geopy
import geopy.point as point
import geopy.distance as distance
import math

#clat, clon: epicenter
#smajax, sminax: major/minor axis length in km
#strike; direction of the major axis from north
#numVer: number of points of ellipse.
def calcEllipse(clat,clon,smajax,sminax,strike,numVer):

   dDeg = 0.1
   rot = -strike * math.pi/180.0
   points = []

# Calc the length per deg around the center [km] / [deg]
   dlat = distance.distance((clat,clon),(clat+dDeg,clon     )).km;
   dlng = distance.distance((clat,clon),(clat     ,clon+dDeg)).km;
   dTheta = (360.0/numVer);

   i = 0.0
   while i <= 360.001:
      y = smajax * math.cos(i * math.pi/180);
      x = sminax * math.sin(i * math.pi/180);
      lng = (x*math.cos(rot)-y*math.sin(rot))/dlat*dDeg; #Recover in deg
      lat = (y*math.cos(rot)+x*math.sin(rot))/dlon*dDeg;
      points.append((clat+lat,clon+lng))
      i = i+dTheta;

   return points

0 件のコメント:

コメントを投稿