Direction of resultant vector - vector

in this question- a motorboat is racing towards north at 25 km/hr and the water current in that region is 10 km/hr in a direction 60 degrees east of south. find the resultant velocity and direction of resultant velocity of the boat.
For getting the velocity i just used the cosin formula and got 22 km/hr approx but i cant seem to understand how to calculate the direction when the angle between the vectors is 120. it is easy when the angle is less that or equal to 90 when we just find tan theta where theta is the angle between the vectors. but how do we go about doing this?

The velocity is as actually a vector with a direction. If you sketch this you will have a vector addition (build a parallelogram) of The boats speed vector and the water flows speed vector. The directions of the vectors you can extract from the given direction. For example take north as (1,0) direction and draw an arrow in the correct length (speed).
v_boat = 25 * (1,0)
v_flow = 10 * ...
v_sum = v_boat + v_flow
v_sum_magnitude = magnitude of v_sum
For the background:
Velocity is working with the principle of superposition.

Related

Calculate bearing from lateral and longitudinal speeds

How can I calculate the bearing from an relative "origin" by lateral and longitudinal speeds?
For example if the lateral speed was 0 meters a second and the longitudinal speed is positive, that would mean the bearing would be 0 degrees of "origin" but if the longitudinal speed was negative that would indicate the bearing is 180 degrees of "origin". This scenario is simple. (I think, laughs at self).
Now lets make things interesting. The longitudinal speed is still positive, say 30.0 meters a second and my lateral speed is -0.05 meters a second. That would indicate my bearing would be angled ever so slightly "left of origin". But specifically what degree?
Is there a formula to calculate the bearing from two speeds?
Thanks!
After digging into the trigonometry trenches. I found a solution.
Given a lon/lat speeds create a 90 degree triangle. In this scenario the hypotenuse doesn't matter.
It boils down to (in python for folks)...
fraction = a / b # sides of the projection that form the 90 degree angle
if b < 0:
fraction = b / a
bearing = 360 - (90 + math.atan(fraction))
Using that bearing. If you have a distance you can project a point.

Rotate matrix +/- radian / degree

Here is a matrix:
A = reshape(collect(1:81), (9, 9))
How may I rotate this matrix in +/- radians/degrees?
Lets say I wish to do a 45 degree rotation
I guess imagine all the 1's in the middle lining up at a 45 degree angle...
Any packages to recommend?

Formula / math calculations for moving a player forward based on direction facing

Im quite bad at maths, and need help moving the player forward for a tool im working on for a game, but the only information i have is what direction the player is facing, and i need to translate that into x and y coordinate increments or decrements.
So if we say M is the direction the player is facing and M goes from 0.00000 to 5.9999999 and then wraps back to 0.000, with the following being correct:
0 = North
1.5 = West
3 = South
4.5 = East
If i want to move the player north, i would do y + amount, south would be y - amount, and if i want to move the player east, i would do x - amount, and west would be x + amount.
So moving the player forward is easy when they are facing an absolute direction, e.g M is 0 so i just add say 5 to the y coordinate. But if the player is facing say 1.2 which is nearly west, what would i add to X and Y to move them forwards exactly, presumably i would add say 5 to x, and some percentage of 5 to y.
Looking for the help of anyone with a knack for this kind of stuff and any help is greatly appreciated. Psuedo code and help of any kind is appreciated, thank you all!
If x and y are the current coordinates, dir is the current direction in your 1-6 units, and amount is the distance to move, your new coordinates would be
angle = dir * pi / 3
newx = x + amount * sin(angle)
newy = y + amount * cos(angle)
If you truly just want the decrements, just remove the x and the y from the formulas.
Note that this uses trigonometry. Most computer languages need the angle to be in radians, so the first line converts the given direction angle to radians.
Also note that your directions for the direction angle values and for your directions for increasing x and y coordinates are non-standard. Therefore those who know trig may be confused at using cos with the x-coordinate and sin for the y-coordinate, since these are not standard. But that is what is needed in your case. As #HighPerformanceMark just pointed out in a comment, you should consider changing your direction angles and your x- and y-coordinates to something more standard. The one that he suggests, 0 degrees for north and 90 degrees for east, is standard in navigation. Another standard, used in trigonometry, is 0 degrees or radians for east and pi/2 radians or 90 degrees for north.

Trying to find lat lon given original lat lon + 3 meters

I have this problem I have to solve.
I am given a coordinate lat/lon, and I need to find a random point within 3 meters of this original point. Approximations are good, but all I could find was this https://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latitude-longitude-by-some-amount-of-meters that has a 10 meter error. Thank you.
Not sure what "find" and "random" mean in this question.
The earth is about 10 million meters from equator to either pole (that's actually how they defined the size of the meter, at first; it's been modified slightly since). The width of latitude lines doesn't vary, so one meter north or south is always is one ten-millionth of 90 degrees, or 9e-6 degrees, so just multiply that by the north-south displacement in meters of your desired point from the initial point and you'll get the number to add to the initial point in degrees: delta_lat = y_meters * 9e-6.
The width of longitude lines does vary, but it works out as simply east-west displacement in meters * 9e-6 = delta_lon * cos(lat), which means you can use the distance from your initial point to figure the east-west difference in degrees: delta_lon = x_meters * 9e-6/cos(lat).
You'll have to be careful with that last part around the poles, because cos(lat) will approach zero. Navigational systems use quaternions to do these things because they don't have singularities in spherical coordinates.

Calculate 3d Vector perpendicular to plane described by a Point and True North Heading

I have a Point on the surface of the earth which I am converting to a Vector from Earth Center.
I have a True North Heading in degrees describing the path the point will travel on the surface of the earth.
I need to calculate a Vector which is perpendicular to the plane created by the path of this point along the earths surface.
I have tried calculating an arbitrary point along the path using the method described here
and then taking the cross product of the two vectors however it does not seem to be quite accurate enough and seems like more overhead than is necessary.
This is related to my other post ray-polygon-intersection-point-on-the-surface-of-a-sphere.
I'm assuming you're trying to compute a vector lying in the plane of the path, not perpendicular to it (since you've already got one - namely the vector from the origin to your point).
You first need to compute vectors lying in that plane that point due north and due east. To do this, let's call P your point, O the origin, and N = (0, 0, R) is the point at the top of your sphere. Then
e = cross(N - P, P - O)
is a vector that points due east, and is tangent to the sphere because it's perpendicular to P - O, a radius of the sphere.
For similar reasons
n = cross(e, P - O)
will point due north, and will be tangent to the sphere.
Now normalize n and e, and you've got an orthonormal basis for the tangent space at your point. To find a vector in a direction theta (say, counterclockwise from the positive east axis, to simplify the math), just take a little of e and a little of n:
v = cos(theta) * e + sin(theta) * n
Here's my understanding of your problem:
You have a point on the Earth's surface, specified as latitude/longitude coordinates
The direction "true north" is the direction that a person at that point would travel to reach the (geographic) North Pole by the most direct possible route. That is, the "true north vector" is tangent to the Earth's surface at your chosen point and points directly north, parallel to a line of longitude.
The direction of the point's motion will be (initially) tangent to the Earth's surface at your chosen point.
You have an angle in degrees from true north which specifies the heading at which this point is going to move.
This angle is the angle between the "true north vector" and the direction of motion of the point.
You want to calculate a vector that is tangent to the Earth's surface at that point but perpendicular to the direction of motion of the point.
If I've understood all that correctly, you can do it as follows:
The "true north vector" at latitude lat, longitude lng is given by [-sin(lat) * cos(lng), -sin(lat) * sin(lng), cos(lat)]
A vector perpendicular to the "true north vector" which points along a line of latitude (to the east) is given by [-sin(lng), cos(lng), 0]
Since these two vectors identify the plane tangent to the Earth's surface, and the vector specifying the direction of motion of your point is also in that plane, your motion vector is a linear combination of the previous two: [
-(sin(lat) * cos(lng) * cos(th) + sin(lng) * sin(th))
-(sin(lat) * sin(lng) * cos(th) - cos(lng) * sin(th))
cos(lat) * cos(th)
] where th is your heading angle.
To find a vector perpendicular to that motion vector, you can just take the cross product of the radius vector (that is, the vector pointing from the center of the Earth to your point,[cos(lat) * cos(lng), cos(lat) * sin(lng), sin(lat)] with the motion vector. (That math would be messy, best to let the computer handle it)
You already have 2 vectors:
N = (0,0,1) points straight up from the origin.
P = (a,b,c) points from the origin to your point.
Calculate the unit vector to your point
U = P/|P|
Calculate a unit vector perpendicular to U and N
E = U X N
Calculate a unit vector perpendicular to U and E (this will be tangent to the sphere)
T = U X E
T could be pointing either North or South, so
if T.z < 0, multiply T by -1.
T now points due north, and is parallel to the plane tangent to the sphere at P.
You now have enough information to construct a rotation matrix (R), so you can rotate T around U. You can find how to make a matrix for rotation around any axis on wikipedia:
Using R, you can calculate a vector pointing in the direction of travel.
A = RT
A is the answer you are looking for.

Resources