algorithmic modeling for Rhino
Hi All,
I have a list of latitude / longitude coordinates, formatted as columns in an excel doc. I'd like to be able to bring these in to GH and use to construct xyz points. For now, they don't actually have to be referenced to anything other than each other. I've taken a quick look at previous posts, which all seem to point to Elk, but Elk seems to be tied specifically to OSM data, which is not what I'm working with. Any suggestions on how best to approach this task? Does anyone know of a formula for translating latitude / longitude values into xyz coordinates (forgive my lackluster geography knowledge here...)?
Excel doc with sample values attached...
Thanks!
Tags:
Hi Petras,
Thanks for your reply - and I apologize, I realize that I was not at all clear in my initial question! I know how to bring the data in - and would be doing pretty much exactly what you've outlined nicely in your suggestion. My issue is that I believe there needs to be some kind of formula in order to get from lat / long coords to xyz space. When I try plotting as the lat / long coords directly, the geometry looks really off, so I feel like I'm probably missing something? Any geographers out there able to weigh in?
just google this stuff how to convert latitude longitude to cartesian coordinates:
Because your coordinates are on sphere, while you are mapping to 2D space.
and then smb can say that
You are assuming the earth is a sphere, while WGS-84 assumes an ellipsoid
Copy paste:
Just to make the definition complete, in the Cartesian coordinate system:
The conversion is:
x = R * cos(lat) * cos(lon) y = R * cos(lat) * sin(lon) z = R *sin(lat)
Where R is the approximate radius of earth (e.g. 6371KM).
If your trigonometric functions expect radians (which they probably do), you will need to convert your longitude and latitude to radians first. You obviously need a decimal representation, not degrees\minutes\seconds (see e.g. here about conversion).
The formula for back conversion:
lat = asin(z / R) lon = atan2(y, x)
asin is of course arc sine. read about atan2 in wikipedia. Don’t forget to convert back from radians to degrees.
So it boils down to:
var earthRadius = 6367; //radius in km
public Point3d convertSphericalToCartesian(latlong)
{
var lat = DegtoRad (latlong.Latitude);
var lon = DegtoRad (latlong.Longitude);
var x = earthRadius * Math.cos(lat)*Math.cos(lon);
var y = earthRadius * Math.cos(lat)*Math.sin(lon);
var z = earthRadius * Math.sin(lat);
return new Point3d(x,y,z);
}
Hi Petras,
This is great! Thanks so much for all the info - I really didn't know where to start, but this gives me a lot to work with. I'll dig into it and see how it goes...
The last reply is literally math functions achievable though grasshopper component, just read line by line and recreate.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by