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.
Related
I need to create a 3D Spline (or NURBS, both would be possible as I can convert these internally) based on two 2D Splines (or NURBS). The two base Splines are on orthogonal planes in a 3D space.
Let's say, for simplicity, spline A is on the XY-Plane, spline B on the YZ-Plane.
Both splines start and end on the same Y coordinate but do not share any points in between.
Image above: Two 2D Splines; Black on XY, blue on YZ. Shared Y coordinate for start and end point, different control points
How can I calculate the resulting 3D spline that is a merge of the two 2D splines?
Purple spline is the resulting 3D Spline.
If allways two spline control points of the 2D splines share the same Y coordinate, it is simple, the new point is the compound of the two old points, where
the new X cooridnate is the XY-Plane's spline X coordinate
the new Y cooridnate is any Y coordinate as they are the same
the new Z coordinate is the YZ-Plane's spline Z coordinate
If the spline control points do not share a common Y coordinate, it seems more difficult. Is there a library I can use to achieve that?
Hope I made my problem somewhat clear.
I have a 1000 x 3 numpy array of coordinates that consist of an (x, y, theta in radians) pose for a moving robot at various times (from time = 0 to time = 1000). Is it possible to graph this position and orientation information using python so that at each point (x,y) there is a small arrow that points in the theta direction? Perhaps a matplotlib type graph would be possible for this?
Have you tried the arrow function in matplotlib (documentation)?
Assuming that theta is angle in radians from the x axis, perhaps something like the following for each point will do it.
arrow(x, y, cos(theta), sin(theta))
The above code will draw an arrow from (x,y) to (x+dx, y+dy).
Another option is matplotlib.pyplot.quiverdocumentation. The quiver function allows us to control the length of the arrow in many ways.
r = np.linspace(0.1,1,11)
theta = np.linspace(-alpha,alpha,11)
radius_matrix, theta_matrix = np.meshgrid(r,theta)
u_radial = -q*(1/radius_matrix)*u_sol[0]
u_theta = theta_matrix*[0 for x in range(len(u_sol[0]))]
ax = plt.subplot(111, polar=True)
ax.plot(theta_matrix, radius_matrix, u_radial, u_theta) #color='r',
ls='none', marker='.'
plt.show()
I am trying to make a plot of a velocity field (same as vector field) using numpys quiver function. The velocity field is written
where q is just an arbitrary constant and r is the distance to the origin. Now, to plot this in a polar coordinate system I create two meshgrids radius_matrix and theta_matrix, as seen in my code (line three). Together these meshgrids form a polar coordinate plane, with r on the horizontal axis and theta on the vertical axis (at least I think) and each point should have a vector arrow corresponding to the equation above.
So for that to happen I define u_radial and u_theta, which are the vector components in radial and angluar direction, resp.. The variable u_sol[0] contains f(theta) (as seen in the equation) for 11 different theta points, and I thought that this would give the correct vectorcomponent, but it doesnt. Why not?
I am expecting something like this, that the arrow shrinks when I get close to the edge for a single value of r. I just want this but for more values of r. This is the data of my u_sol[0] vector:
u_sol[0] = [4.68520269e-26 1.54380741e+00 2.74550730e+00 3.60503630e+00
4.12217780e+00 4.29651250e+00 4.12741184e+00 3.61407419e+00
2.75560427e+00 1.55113610e+00 3.84028608e-18]
When I plot this, I get something worse, see the figure below. What happend to the arrows? And why are there colors all of a sudden?
Best regards SimpleP.
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.
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)?