Rotate a sphere from coord1 to coord2, where will

2019-08-08 03:56发布

I have three coordinates (lat,lon) on a sphere. If you would rotate the whole sphere from coord1 to coord2, where will coord3 now be located?

I've been trying this out in Python using Great Circle (http://www.koders.com/python/fid0A930D7924AE856342437CA1F5A9A3EC0CAEACE2.aspx?s=coastline) but I create strange results as the newly calculated points all group together at the equator. That must have something to do with the azimuth calculation I assume?

Does anyone maybe know how to calculate this correctly?

Thanks in advance!

EDIT

I found the following: http://www.uwgb.edu/dutchs/mathalgo/sphere0.htm

I guess I now need to calculate the rotation axis and the rotation angle from the two points in cartesian coords (and 0,0,0)? I guess this must be very simple, something to do with defining a plane and determining the normal line? Does someone maybe know where I can find the needed equations?

EDIT 2

Coord1 and coord2 make a great circle. Is there an easy way to find the location of the great circle normal axis on the sphere?

EDIT 3

Looks like I was able to solve it ;) http://articles.adsabs.harvard.edu//full/1953Metic...1...39L/0000039.000.html did the trick.

2条回答
Emotional °昔
2楼-- · 2019-08-08 04:39

Using Visual Python I think I now have solved it:

# Rotation first described for geo purposes: http://www.uwgb.edu/dutchs/mathalgo/sphere0.htm
# http://stackoverflow.com/questions/6802577/python-rotation-of-3d-vector
# http://vpython.org/
from visual import *
from math import *
import sys

def ll2cart(lon,lat):
    # http://rbrundritt.wordpress.com/2008/10/14/conversion-between-spherical-and-cartesian-coordinates-systems/
    x = cos(lat) * cos(lon)
    y = cos(lat) * sin(lon)
    z = sin(lat)
    return x,y,z

def cart2ll(x,y,z):
    # http://rbrundritt.wordpress.com/2008/10/14/conversion-between-spherical-and-cartesian-coordinates-systems/
    r = sqrt((x**2) + (y**2) + (z**2))
    lat = asin(z/r)
    lon = atan2(y, x)
    return lon, lat

def distance(lon1, lat1, lon2, lat2):
    # http://code.activestate.com/recipes/576779-calculating-distance-between-two-geographic-points/
    # http://en.wikipedia.org/wiki/Haversine_formula
    dlat = lat2 - lat1
    dlon = lon2 - lon1
    q = sin(dlat/2)**2 + (cos(lat1) * cos(lat2) * (sin(dlon/2)**2))
    return 2 * atan2(sqrt(q), sqrt(1-q))

if len(sys.argv) == 1:
    sys.exit()
else:
    csv = sys.argv[1]

    # Points A and B defining the rotation:
    LonA = radians(float(sys.argv[2]))
    LatA = radians(float(sys.argv[3]))
    LonB = radians(float(sys.argv[4]))
    LatB = radians(float(sys.argv[5]))

# A and B are both vectors
# The crossproduct AxB is the rotation pole vector P:
Ax, Ay, Az = ll2cart(LonA, LatA)
Bx, By, Bz = ll2cart(LonB, LatB)
A = vector(Ax,Ay,Az)
B = vector(Bx,By,Bz)
P = cross(A,B)
Px,Py,Pz = P
LonP, LatP = cart2ll(Px,Py,Pz)

# The Rotation Angle in radians:
# http://code.activestate.com/recipes/576779-calculating-distance-between-two-geographic-points/
# http://en.wikipedia.org/wiki/Haversine_formula
RotAngle = distance(LonA,LatA,LonB,LatB)

f = open(csv,"r")
o = open(csv[:-4] + "_translated.csv","w")
o.write(f.readline())
for line in f:
    (lon, lat) = line.strip().split(",")

    # Point C which will be translated:
    LonC = radians(float(lon))
    LatC = radians(float(lat))

    # Point C in Cartesian coordinates:
    Cx,Cy,Cz = ll2cart(LonC,LatC)
    C = vector(Cx,Cy,Cz)

    # C rotated to D:
    D = rotate(C,RotAngle,P)
    Dx,Dy,Dz = D
    LonD,LatD = cart2ll(Dx,Dy,Dz)

    o.write(str(degrees(LonD)) + "," + str(degrees(LatD)) + "\n")
查看更多
The star\"
3楼-- · 2019-08-08 04:53

Ok I don't know the exactly formula, I believe it would be a simple matrix multiplication but here's how you can figure out without it.

  1. Transform coordinates so that the poles of the rotation are at 90,0 and -90,0 respectively and so that the line along your rotation from coord1 to coord2 is then on the "equator" (this should be simply delta lat, delta long)

  2. then the rotation is just change in longitude and you can apply the same delta long to any coord3, then simply transform back to the original coordinates (via negative delta lat and negative delta long)

1 & 2 are pretty much what your matrix would do - if you can figure out the matrices for each step, you can just multiply them and get the final matrix

查看更多
登录 后发表回答