Vector/line from polar coordinates - python

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).

Related

get 16 equidistant points along the circumference of ellipse

I am trying to get the 16 equidistant point on ellipse (equal arc length along the ellipse).
Using some research, I am able to get the angle from which I can get those point by drawing a straight line and getting the intersection point but unable to find the length of line to be drawn from the center. I have also explored https://math.stackexchange.com/questions/172766/calculating-equidistant-points-around-an-ellipse-arc but getting confused in formula
What is the value of φ here?
Can anyone please help me there on getting the points. Thanks
We can define (axis-aligned) ellipse parametrization as
x = a * cos(φ)
y = b * sin(φ)
where parameter φ has range 0..2*Pi.
Resulting point (x,y) is situated at angle θ relative to the ellipse center. Your linked post shows formula for θ/φ transformation.
Note - θ is real angle, φ is not!, it is just parameter.
You perhaps don't need θ here. To solve the problem, you have to find ellipse circumference length L using elliptic integral for φ = 2*Pi (numerically).
Then find φ values corresponding to arc length L/16, 2*L/16...15*L/16 - numerically again, and calculate corresponding point coordinates from the parametrization equations.

Plotting robot path and orientation using python +/- matplotlib

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.

How to change the center of a stereographic projection?

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.

Python program to rotate a line not working

I am trying to figure out direction vectors of the arrowheads of an arrow. Basically I'm given a normalized direction vector (u,v,w) and I need the normalized direction vectors of the its two arrow heads which make a 15 degree angle.
My plan is to first start off with a simple normalized vector (0,0,1). The direction vectors of its arrow heads are (-sin(15), 0, -cos(15)) and (sin(15), 0, -cos(15)), and then rotate (0,0,1) so its parallel to the given (u,v,w). I do this by projecting (u,v,w) on its x-axis, and getting its angle relative to (0,0,1), then projecting on the y-axis, and getting its angle relative to (0,0,1), then I use the 3d rotation matrices to use those found angles to rotate the arrow head direction vector.
I have this code below, but its not working properly. Does anyone see whats wrong?
Thanks
ra = 15
ca = math.cos(ra)
sa = math.sin(ra)
px = (0,v,w)
if u!=1:
px = [i/float(math.sqrt(v**2 + w**2)) for i in px]
py = (u,0,w)
if v!=1:
py = [i/float(math.sqrt(u**2 + w**2)) for i in py]
pxangle = math.acos(px[2])
pyangle = math.acos(py[2])
cpx = math.cos(pxangle)
spx = math.sin(pxangle)
cpy = math.cos(pyangle)
spy = math.sin(pyangle)
def rotatefunction(ah):
xr = (ah[0], -spx*ah[2], cpx*ah[2])
return (cpy*xr[0]+spy*xr[2], xr[1], -spy*xr[0]+cpy*xr[2])
lah = rotatefunction((-sa, 0, -ca))
rah = rotatefunction((sa, 0, -ca))
First of all, you need to convert degrees into radians (= degree * (pi / 180)) before passing to math.cos, math.sin, etc.
Suppose the normalized direction vector of the arrow is given by
The unit vector parallel to the z-axis is given by
The orthonormal vector perpendicular to both the unit vectors are given by the cross product
and the angle between the two vector is given by the scalar product
Basically the rotation is about this u (uhat) axis by angle theta. The corresponding rotation matrix is given by
so this is the matrix you need to multiply the arrowhead vectors with.

Plotting intersection of triaxial ellipsoid with a plane in matplotlib

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)?

Categories

Resources