What's the best way to plot the intersection of a randomly oriented triaxial ellipsoid with a plane in polar coordinates? The plane runs over a range of longitudes at a given latitude.
The code below should plot the intersection of an array of spheres with a plane with latitude plane_lat. (A sphere has center coordinates: sphere_x,sphere_y,sphere_z; distance away from origin: sphere_dist; and spherical radius: sphere_rad.)
for i in range(len(hole_rad)):
deltaz = (sphere_dist[i]*np.cos(sphere_lat[i]*degtorad))*np.tan(plane_lat*degtorad)-sphere_dist[i]*np.sin(sphere_lat[i]*degtorad)
if np.abs(deltaz)<sphere_radius[i]:
rprime = sphere_rad[i]*np.sin(np.arccos(abs(deltaz)/(sphere_rad[i])));
x = rprime * np.sin(newtheta)+sphere_x[i]*H0
y = rprime * np.cos(newtheta)+sphere_y[i]*H0
z = np.zeros(np.shape(newtheta))
cr,clat,clon=ACD.cartesian_to_spherical(x,y,z)
circles=ax.plot(np.rad2deg(clon),cr,c='blue',linewidth=0.1)
This was my roundabout attempt using python/matplotlib. There's got to be a better way of accomplishing this.
Any ideas on how to do this for ellipsoids (preferably in python)?
Related
Right now I am plotting a streographic projection with a center at the z axis by getting a P vector (Px, Py, Pz) from different directional indices in a unit sphere. The following process converts these to 2d coordinates.
(Python)
x2,y2,z2=P
theta2=np.arccos(abs(z2)/(x2**2+y2**2+z2**2)**.5)
phi2=np.arctan((y2/x2))
xp=theta2*np.cos((phi2))
yp=theta2*np.sin((phi2))
Plot xp,yp
What transformations do I apply in order to change the P vector (or a different aspect of the code) so that the center is on a different direction (x-axis for example)?
Thanks.
I have some surface data given as x_mesh, y_mesh, z_mesh.
x_mesh and y_mesh were generated from steps by longitude and latitude on a geotiff (so, their shapes are equal and regular but steps by x and y are not).
z_mesh is the height from tangential plane to Earth ellipsoid at the center of map.
I can easily plot the surface with matplotlib.pyplot.pcolormesh(x_mesh, y_mesh, z_mesh). It works.
Now I want to set a line by mouse and somehow take a Z profile under this line. I need some interpolator to make xy --> z, but don't know which one to use.
I tried to do this:
scipy.interpolate.interp2d(x_mesh, y_mesh, z_mesh)
But it gives me an error: OverflowError: Too many data points to interpolate
Don't you have any ideas how to interpolate such data?
P.S. The geotiff is not very big, it is 6K x 6K pixels. And I see that pcolormesh somehow interpolates the color value between pixels if I zoom in.
as i know, shapely use only cartesian coordinate system. I have two point on the earth with lat and lon coordinates. I need create buffer with 1km radius around this two points and find polygon, where this buffers intersect.
But construstion
buffer = Point(54.4353,65.87343).buffer(0.001) create simple circle, but in projection on the Earth it becomes ellipse, but i need two real circle with 1 km radius.
I think, i need convert my buffers into new projection and then intersect it, but dont now how correct do it.
You need to do what you say. For that, you will need to use a library that handles projections (pyproj is the choice here). There is a similar question in Geodesic buffering in python
import pyproj
from shapely.geometry import MultiPolygon, Polygon, Point
from shapely.ops import transform as sh_transform
from functools import partial
wgs84_globe = pyproj.Proj(proj='latlong', ellps='WGS84')
def point_buff_on_globe(lat, lon, radius):
#First, you build the Azimuthal Equidistant Projection centered in the
# point given by WGS84 lat, lon coordinates
aeqd = pyproj.Proj(proj='aeqd', ellps='WGS84', datum='WGS84',
lat_0=lat, lon_0=lon)
#You then transform the coordinates of that point in that projection
project_coords = pyproj.transform(wgs84_globe, aeqd, lon, lat)
# Build a shapely point with that coordinates and buffer it in the aeqd projection
aeqd_buffer = Point(project_coords).buffer(radius)
# Transform back to WGS84 each coordinate of the aeqd buffer.
# Notice the clever use of sh_transform with partial functor, this is
# something that I learned here in SO. A plain iteration in the coordinates
# will do the job too.
projected_pol = sh_transform(partial(pyproj.transform, aeqd, wgs84_globe),
aeqd_buffer)
return projected_pol
The function point_buff_on_globe will give you a polygon in lat lon that is the result of buffering the given point in the Azimuthal Equidistant Projection centered in that point (the best you can do with your requirements. Two observations:
I don't remember the units of the radius argument. I think is in meters, so if you need a 10 km buffer, you will need to pass it 10e3. But please, check it!
Beware of using this with radius to wide or points that are to far away from each other. Projections work well when the points are near to the point you are centering the projection.
I will have a 3-d grid of points (defined by Cartesian vectors). For any given coordinate within the grid, I wish to find the 8 grid points making the cuboid which surrounds the given coordinate. I also need the distances between the vertices of the cuboid and the given coordinate. I have found a way of doing this for a meshgrid with regular spacings, but not for irregular spacings. I do not yet have an example of the irregularly spaced grid data, I just know that the algorithm will have to deal with them eventually. My solution for the regularly spaced points is based off of this post, Finding index of nearest point in numpy arrays of x and y coordinates and is as follows:
import scipy as sp
import numpy as np
x, y, z = np.mgrid[0:5, 0:10, 0:20]
# Example 3-d grid of points.
b = np.dstack((x.ravel(), y.ravel(), z.ravel()))[0]
tree = sp.spatial.cKDTree(b)
example_coord = np.array([1.5, 3.5, 5.5])
d, i = tree.query((example_coord), 8)
# i being the indices of the closest grid points, d being their distance from the
# given coordinate, example_coord
b[i[0]], d[0]
# This gives one of the points of the surrounding cuboid and its distance from
# example_coord
I am looking to make this algorithm run as efficiently as possible as it will need to be run a lot. Thanks in advance for your help.
How can i draw a vector/line starting from polar coordinates (magnitude and angle) instead of rectangular coordinates (x, y) in python with matplotlib? I started learning python just a couple days ago.
Translate polar co-ordinates to cartesian co-ordinates by doing the following:
x = magnitude*cos(angle)
y = magnitude*sin(angle)
Note: Double check if you are using degrees or radians. Usually cos and sin expect radians. To translate from angle to radians, multiply by (2*pi)/360. To translate from radians to angle, multiply by 360/(2*pi).