Co-ordinates of point on circle with minimum cos/sin - optimization

A vehicle currently at a point U = (ux, uy) is moving counter-clockwise along a circle of radius R with speed s and direction d (i.e. tangent to the circle makes an angle d with the X-axis.) What position V = (vx, vy) will it be at in time t?
The center of the circle is not specified.
The way I see it, after time t it will travel st or an angle of st/R along the circle. But I am lost trying to compute V from this info.
I can first find the center C of the circle based on (ux, uy), R and d. And then find where vector CV points, and hence V. But that's a whole lot of cosines and sines. I am constrained by CPU, so maybe one sine/cos/tan is acceptable or one or two squares/square roots are acceptable.

This calls for a diagram, but alas I lack the skill.
I assume that the radius speed and time interval are such that the vehicle will not travel more than halfway round the circle in the time available.
Let V be the point the vehicle will be at t seconds after it is at U. Let the centre of the circle (whose coordinates will not be needed) be O. Then the length of the arc from U to V is
A = s*t
and so the angle subtended at O is
a = A/R radians.
The direction from U to V will be the same as the direction of the tangent to the circle at a point midway between U and V, ie
e = d + a/2
The distance from U to V is the length of the chord from U to V. The midpoint of the chord is the vertex of two congruent right angled triangles whose hypoteneuses have length R, and the angle at O is a/2. Therefor the length of the chord is
C = 2*R*sin( a/2)
Finally
V = U + C*(cos(e), sin(e))
You may also want the direction of the tangent at V. This is d+a.
Note that if you store the direction d as a unit vector rather than an angle you can save some sin & cos calls as the direction of the chord is then the direction d rotated through a/2, and the direction at V is d rotated through a.

Related

Numpy Line-Plane intersection

I have two planes in 3D space as shown below.
Point "e" on plane2 represents the intersection of the line which passes from point "P" of plane1 and has the direction vector of "S". Let P be the edge of plane 1.
Which are the "e" point coordinates (xe,ye, 0) with respect to the coordinates system of the plane it belongs (plane2), using Numpy?
I have the following data available:
Coordinates of the centers of each plane with respect of the global coordinate system "C".
x = np.array([x1, x2])
y = np.array([y1, y2])
z = np.array([z1, z2])
Sun direction vector S = np.array([Sz, Sx, Sy])
Point "P" location with respect to the coordinate system of plane1: P(xp,yp,0)
Each plane has the same width and length dimensions: Hw, Hl
Unit vectors normal to the plane surfaces
n = np.array([[n1z, n1x, n1y], [n2z, n2x, n2y]])
Also the azimuthial and elevation angles for both planes with respect to the global coordinate system "c" are known:
alphaH = np.array([alphaH1, alphaH2])
aH = np.array([aH1, aH2])
You have the position vector for c2 and the position vector for e in the global coordinate system then all you need to do is calculate c2-e and this will give you the position vector of e relative to c2.

Finding out Force from Torque and Distance

I have solid object that is spinning with a torque W, and I want to calculate the force F applied on a certain point that's D units away from the center of the object. All these values are represented in Vector3 format (x, y, z)
I know until now that W = D x F, where x is the cross product, so by expanding this I get:
Wx = Dy*Fz - Dz*Fy
Wy = Dz*Fx - Dx*Fz
Wz = Dx*Fy - Dy*Fx
So I have this equation, and I need to find (Fx, Fy, Fz), and I'm thinking of using the Simplex method to solve it.
Since the F vector can also have negative values, I split each F variable into 2 (F = G-H), so the new equation looks like this:
Wx = Dy*Gz - Dy*Hz - Dz*Gy + Dz*Hy
Wy = Dz*Gx - Dz*Hx - Dx*Gz + Dx*Hz
Wz = Dx*Gy - Dx*Hy - Dy*Gx + Dy*Hx
Next, I define the simplex table (we need <= inequalities, so I duplicate each equation and multiply it by -1.
Also, I define the objective function as: minimize (Gx - Hx + Gy - Hy + Gz - Hz).
The table looks like this:
Gx Hx Gy Hy Gz Hz <= RHS
============================================================
0 0 -Dz Dz Dy -Dy <= Wx = Gx
0 0 Dz -Dz -Dy Dy <= -Wx = Hx
Dz -Dz 0 0 Dx -Dx <= Wy = Gy
-Dz Dz 0 0 -Dx Dx <= -Wy = Hy
-Dy Dy Dx -Dx 0 0 <= Wz = Gz
Dy -Dy -Dx Dx 0 0 <= -Wz = Hz
============================================================
1 -1 1 -1 1 -1 0 = Z
The problem is that when I run it through an online solver I get Unbounded solution.
Can anyone please point me to what I'm doing wrong ?
Thanks in advance.
edit: I'm sure I messed up some signs somewhere (for example the Z should be defined as a max), but I'm sure I'm wrong when defining something more important.
There exists no unique solution to the problem as posed. You can only solve for the tangential projection of the force. This comes from the properties of the vector (cross) product - it is zero for collinear vectors and in particular for the vector product of a vector by itself. Therefore, if F is a solution of W = r x F, then F' = F + kr is also a solution for any k:
r x F' = r x (F + kr) = r x F + k (r x r) = r x F
since the r x r term is zero by the definition of vector product. Therefore, there is not a single solution but rather a whole linear space of vectors that are solutions.
If you restrict the solution to forces that have zero projection in the direction of r, then you could simply take the vector product of W and r:
W x r = (r x F) x r = -[r x (r x F)] = -[(r . F)r - (r . r)F] = |r|2F
with the first term of the expansion being zero because the projection of F onto r is zero (the dot denotes scalar (inner) product). Therefore:
F = (W x r) / |r|2
If you are also given the magnitude of F, i.e. |F|, then you can compute the radial component (if any) but there are still two possible solutions with radial components in opposing directions.
Quick dirty derivation...
Given D and F, you get W perpendicular to them. That's what a cross product does.
But you have W and D and need to find F. This is a bad assumption, but let's assume F was perpendicular to D. Call it Fp, since it's not necessarily the same as F. Ignoring magnitudes, WxD should give you the direction of Fp.
This ignoring magnitudes, so fix that with a little arithmetic. Starting with W=DxF applied to Fp:
mag(W) = mag(D)*mag(Fp) (ignoring geometry; using Fp perp to D)
mag(Fp) = mag(W)/mag(D)
Combining the cross product bit for direction with this stuff for magnitude,
Fp = WxD / mag(WxD) * mag(Fp)
Fp = WxD /mag(W) /mag(D) *mag(W) /mag(D)
= WxD / mag(D)^2.
Note that given any solution Fp to W=DxF, you can add any vector proportional to D to Fp to obtain another solution F. That is a totally free parameter to choose as you like.
Note also that if the torque applies to some sort of axle or object constrained to rotate about some axis, and F is applied to some oddball lever sticking out at a funny angle, then vector D points in some funny direction. You want to replace D with just the part perpendicular to the axle/axis, otherwise the "/mag(D)" part will be wrong.
So from your comment is clear that all rotations are spinning around center of gravity
in that case
F=M/r
F force [N]
M torque [N/m]
r scalar distance between center of rotation [m]
this way you know the scalar size of your Force
now you need the direction
it is perpendicular to rotation axis
and it is the tangent of the rotation in that point
dir=r x axis
F = F * dir / |dir|
bolds are vectors rest is scalar
x is cross product
dir is force direction
axis is rotation axis direction
now just change the direction according to rotation direction (signum of actual omega)
also depending on your coordinate system setup
so ether negate F or not
but this is in 3D free rotation very unprobable scenario
the object had to by symmetrical from mass point of view
or initial driving forces was applied in manner to achieve this
also beware that after first hit with any interaction Force this will not be true !!!
so if you want just to compute Force it generate on certain point if collision occurs is this fine
but immediately after this your spinning will change
and for non symmetric objects the spinning will be most likely off the center of gravity !!!
if your object will be disintegrated then you do not need to worry
if not then you have to apply rotation and movement dynamics
Rotation Dynamics
M=alpha*I
M torque [N/m]
alpha angular acceleration
I quadratic mass inertia for actual rotation axis [kg.m^2]
epislon''=omega'=alpha
' means derivation by time
omega angular speed
epsilon angle

finding a minimum distance

I need to find a point or points on the given circle (or curve) which minimizes d0+d1? the radius and center of the curve are (0,0) and 'r' respectively and the coordinates of points A and B are known. Let say A=(x1,y1) and B=(x1,-y1) and r> sqrt(x1^2+y1^2) . C is unknown point of the circle which should minimize the length d0+d1
d0 - the distance between A to C on the circle
d1- the distance between B to C on the circle
point C moves along the circle. I need to find a point or points on the given circle (or curve) which minimizes d0+d1?
If the line AB intersects the circle, then C is that intersection point (note that there can be two intersection points and both give an equal distance d0+d1 !).
If AB does not intersect the circle, then C is the point on the circle intersecting an imaginary line from the point on the line AB closest to the circle center.
There are many articles online about how to find the point on a line closest to another point, and how to find the intersection between two lines, which would solve the second case. For the first case you can google "line circle intersection"
The general case is very complicated, but the special situation
A=(x1,y1) and B=(x1,-y1) and r > sqrt(x1^2+y1^2)
with a circle whose centre is the origin has enough symmetries to make the solution at least in some circumstances accessible. I'm assuming A ≠ B, (equivalently y1 ≠ 0), otherwise the problem is trivial for a circle.
Let dist(P,Q) be the Euclidean distance between the points P and Q. The (closed) line segment connecting A and B is the locus of points P with
dist(P,A) + dist(P,B) = dist(A,B)
For D > dist(A,B), the locus of points with
f(P) = dist(P,A) + dist(P,B) = D
is an ellipse E(D) whose foci are A and B. Let P be a point on the circle and D = f(P).
If the tangents to the circle and to the ellipse E(D) in the point P don't coincide, P is neither a local minimum nor a local maximum of f restricted to the circle.
If the tangents coincide, and the curvature of the circle is larger than the curvature of E(D) in P, then P is an isolated local maximum of f restricted to the circle.
If the tangents coincide, and the curvature of the circle is smaller than the curvature of E(D) in P, then P is an isolated local minimum of f restricted to the circle.
If the tangents coincide and the curvature of the circle is equal to the curvature of E(D) in P, then
P is an isolated local minimum of f restricted to the circle if dist(P,A) = dist(P,B),
P is neither a local maximum nor a local minimum of f restricted to the circle otherwise.
First, if x1 = 0, it is easily seen (in case it is not geometrically obvious) that the points on the circle minimising f are the points with x-coordinate 0, i.e. P1 = (0,r) and P2 = (0,-r). [That would even be true if r² ≤ x1² + y1².]
Now, suppose x1 ≠ 0, without loss of generality x1 > 0. Then it is obvious that a point P = (x,y) on the circle minimising f must have x > x1. By the symmetry of the situation, the point R = (r,0) must either be a local minimum or a local maximum of f restricted to the circle.
Computing the behaviour of f near R, one finds that R is a local minimum if and only if
r ≥ (x1² + y1²) / x1
Since R is a point of smallest curvature of E(f(R)) (and the tangents in R to E(f(R)) and the circle coincide), R is then also the global minimum.
If r < (x1² + y1²) / x1, then R is a local maximum of f restricted to the circle. Then f has two global minima on the circle, with the same x-coordinate. Unfortunately, I don't have a nice formula to compute them, so I can't offer a better way than an iterative search.

How to calculate a longitude and latitude at a given distance along a great circle?

I want to overlay great circle arcs between airports on a map using longitudes and latitudes.
I can already get the distance and bearing from the initial and final coordinates but now I need to produce the points on the curve to plot through.
What I would like is a formula which takes the origin, destination, and a distance, and returns the latitude/longitude of the point that lies at that distance on the path between the origin and the destination.
I'm currently approximating the earth by a sphere and using radians -- eventually I'll add in spheroid corrections.
currlat = oldlat + d * sin (angle)/ (radius);
currlon = oldlon + d * cos (angle)/ (radius * cos(oldlat));
where d is distance travelled and angle is in radians. This is assuming circumference of earth at 40000km both at equator and through the poles. You can convert in radians...
Also it assumes the angle (direction) is with reference to equator line.
Obviously this needs spheroid corrections.
if you go south sin values will turn negative and north it will go positive. If you go west cos will turn negative and east it will turn positive.
d * sin(angle) and d * cos(angle) gives you the change. and you just calculate the new lat/long on that basis scaling up against circumference of earth.

How to calculate the (x or y) coordinate of point on a circumference of a circle?

px and py are the x and y coordinates of a point on a circle's circumference.
Given:
the center of the circle as: cx, cy
the radius of the circle as: r
px
How to calculate the value of py? Thanks!
Given px there are at most two possible values for py.
Look at the pythagorean theorem: (px-cx)^2+(py-cy)^2=r^2.
Let d=r^2-(px-cx)^2
If d>0 then you have two solutions. This gives py=sqrt(d)+cy, where the square root is positive or negative.
If d=0 then you have one solution py=cy, the left or right of the circle, depending on px
If d<0 you have no real points.
Although this is not programming... you know this equation right?
(x - h)^2 + (y - k)^2 = r^2
You have h and k from cx and cy
You have r
you have x from px
then is easy to solve it!