How to calculate velocity on each axis having angles? - c

I have a 3D space where I can move my spaceship right/left and up/down with mouse. I'm able to calculate speed of the spaceship on a plane, having the facing (alfa angle), like:
float cosf = cos(alfa * M_PI/180.0);
float sinf = sin(alfa * M_PI/180.0);
vxm = + cosf*vx - sinf*vz;
vym = vy;
vzm = + sinf*vx + cosf*vz;
However I'm having trouble when adding a Beta angle (the vertical facing of ship), how can I calculate the three velocities on each axis, having Alfa and Beta angle?

If magnitude of velocity is V and Beta is angle between V direction and OXY plane, then
v_z = V * Sin(Beta)
v_x = V * Cos(Beta) * Cos(Alpha)
v_y = V * Cos(Beta) * Sin(Alpha)

Related

Drawing rounded/movable area over image

I would like to draw rounded area and points over a photo.
I decided to do it with a svg which is simplier to make it resizable and movable.
But, from a list of points I do not have an area which go through all points.
I used the Quadratic Bezier CurveTo, but I am not able to find the mathematic formula to give the the "Q parameter" the values to calculate the control point to go from A to C passing by B.
For the moment, when the angle is too high, the line "turn" before the point, but i would like to go touch the point.
There is infinite number of curves through point B.
Let define that B lies on the curve at parameter t=1/2
Quadratic curve with unknown control point Q has equation
P(t) = A*(1-t)^2 + 2*Q*t*(1-t) + C*t^2
Substiting point B and t=1/2, we have
B = A/4 + Q/2 + C/4
Q = 2*B - A/2 - C/2
or in coordinates
Q.x = 2*B.x - A.x/2 - C.x/2
Q.y = 2*B.y - A.y/2 - C.y/2
This very simple method should work well when B is near symmetrical relative to A and C
Q.x = 2*7 - 0 - 20/2 = 4
Q.y = 2*10 - 0 - 0 = 20

Find 3D coordinates of end point of a vector given the distance and the angle

How can I find the coordinates of P ? I've seen other posts in 2D and also in 3D but they say that I need 3 angles for 3D and some say I only need two but I dont understand which ones, I suck at math.
All See this image, I have is those two angles and the distance between B and P
To define a vector in 3D, given its length, you need 2 angles. These 3 coordinates (length + 2 angles) are named "spherical coordinates". There are 3 conventions for defining such angles. The most common one is the radius-elevation-azimuth. In this convention, expression of the cartesian coordinates of the vector, given the radius, elevation angle and azimuth angle are:
x = radius * sin(elevation) * cos(azimuth)
y = radius * sin(elevation) * sin(azimuth)
z = radius * cos(elevation)

How can I draw a circular arc with three points in a StreamGeometry

I'm using a StreamGeometry object to create an complete figure. The figure is a series of lines and arcs. The arcs are all circular defined by a start point, end point, and a middle point that the arc also passes through. How can I convert that into what ArcTo requires. I've been searching for a solution all morning. I will try to work the math out myself.
1) Find radius of circle with plain geometry
Let's A, B, C - three points given (B is middle point of arc), M is middle point of AC chord, then
AM * CM = BM * B'M, where B' is point at another end of circle diameter, due to "intersecting chords theorem".
AM=CM=AC/2, BM+B'M = 2R, so we can find circle radius R
(2R-BM) * BM = AM^2
2R-BM = AM^2/BM
R = (BM^2+AM^2)/(2*BM)
2) Now it is possible to find circle center with vector geometry
O = B + uBM * R, where uBM = BM/|BM| is unit vector
3) size parameter of ArcTo set to (R, R)
4) rotationAngle set to atan2(OA x OC, OA * OC) (crossproduct and scalar product of OA and OC vectors)
5) set the rest of ArcTo parameters as needed

Ansi C re-evaluating of Y coordinates

Im trying to do a graph from evalued math function and this is last think I need to do. I have graph with limit coordinates -250:-250 left down and 250:250 right up. I have Y-limit function, which is defined as -10:10, but it could be user redefined and if it is redefined, I need to calculate new coordinates.
I have now field of y-coordinates with 20000 values and each of is multiply by:
ratioY = 25 / (fabs( up-limit - down-limit ) / 20) which will make coordinates adapt for new Y-limit (if limit is -5:5, graph looks 2x bigger), this works good, but now isnt graph exactly where it should be (see pictures). Simply 25 is multiplied for postscript coordinates and (up-limit - down-limit) / 20 is ratio for "zooming" Y coordinates. This works fine.
Now Im trying to "move coordinates" which will subtracted from revaluated value:
ycoor = (ycoor * ratioY) - move-coorY ;.
Now I have something like this:
move-coorY = 25* ( ( up-limit - down-limit) /2 );
and it doesnt work correctly. I need to do sin(0) start from 0.
This is a correct graph which is -10:10
(source: matematika.cz)
This is a bad graph which is -5:10
(source: matematika.cz)
Maybe its easier not to do this with fixed numbers (like your ratioY) but with two different coordinate systems. Physical coordinates are in your problem domain, i.e. they are the real values of your sine curves. Logical coordinates refer to the device, in your case they are the point values in Postscript, but they might be pixels on a HTML canvas or whatever.
I'll denote the physical coordinates of the first axis with a small x and the corresponding logical coordinate with a capital X. In each coordinate system we have:
Lower bound: x_min, X_max
Upper bound: x_max, X_max
Range: dx = x_max - x_min
dX = X_max - X_min
Then you can calculate your logical coordinates from the physical ones:
X(x) = X_min + (x - x_min) * dX / dx
This also works vice versa, which is not an issue for Postscript files, but max be useful for an intractive canvas where a mouse click should yield the physical coordinates.
x(X) = x_min + (X - X_min) * dx / dX
In your case, the ratio or scale factor is dX / dx, which you can calculate once for each axis. Let's plot the first point with y == 0 in your first graph:
y_min = -10
y_max = 10
dy = 20
Y_min = -250
Y_max = 250
dX = 500
Y(0) = -250 + (0 - (-10)) * 500 / 20
= -250 + 10 * 500 / 20
= 0
In the second graph, the logical coordinates are the same, but:
y_min = -5
y_max = 10
dy = 15
Y(0) = -250 + (0 - (-5)) * 500 / 15
= -250 + 5 * 500 / 15
= -83.3333
If you change the range of your graph, e.g. from (-10, 10) to (-5, 10), just adjust the physical coordinates. If you resize your graph, change the logical coordinates. (Also, calculating the point in the graph is the same as calculating the position of the tick mark for the axis. Strangely, you got the tick marks right, but not your graph. I think your problem was to account for the non-zero lower bound in both graph and curve data.)
Also, it's probably better to re-evaluate the logical coordinates when printing instead of transfroming them from a previous plot. You can do that on the fly, so that you only need to keep the physical data in an array.
(And lastly, I'll admit that I'm not entirely sure these two kinds of cooirdinates are called physical and logical. I know these terms are used, but it may be the other way round or they might even mean sonething different altogether.)
My friend did a well yob for me and programmed this...
double zeroPosition(double startY, double endY){
double range = endY - startY;
double topSize = endY / range;
return 250.0 - 500 * topSize;
}
This will calculate position of zero, which I just add to my Y position with ratio and It works exactly how I need!
But thanks M Oehm ;)

Bearing using two sets of coordinates (Latitude and Longitude) in C

I have began working on an autonomous rc helicopter in c. I need help finding a way to calculate the bearing acuratley. I am using two sets of coordinates (latitude and longitude), one is the current location and the other is the destination point. I have converted the latitude and longitude into decimal format so....
40°58'19.86"N = 40.972183
74°14'52.74"W = 74.247983
Can anyone show me code in c to find the bearing or a formula i can use?
i have looked at: http://www.movable-type.co.uk/scripts/latlong.html and when i transfer it to c, the results make no sense.
This is what i have tried:
double x = Sin(Longitude2 - Longitude1) * Cos(Latitude2);
double y = Cos(Latitude1) * Sin(Latitude2) - Sin(Latitude1) * Cos(Latitude2) * Cos(Longitude2 - Longitude1);
double heading = (Atan2(x, y) % 2 * 3.14159265) (180/3.14159265);
Have you converted your coordinates from degrees to radians before calculations ?
angleRad = 3.14159265 * angleDeg / 180;
And
bearing = Atan2(y, x);
in that website.
The bearing should be converted from rad to deg in turn:
bearing = 180 * bearing / 3.14159265;
and in case of negative value eventually:
bearing = bearing + 360;
I don't know how to write this using the convention above (with "%").
Latitude1 and Longitude1 are coordinates of the observer
Latitude2 and Longitude2 are coordinates of destination point.
Formulas from that website work well.
For the very small area you are considering you can assume the world is flat.
If you also only need this to work locally you can pre-calculate the value of a deg lat/lon on the ground in metres (or ft)
Then simply convert the delta lat/lon into distance and do the normal trig.
To convert distance to lat/lon you can either use google earth to measure it or
How to convert latitude or longitude to meters?

Resources