How to calculate xy difference? - c++

I know this might be silly but excuse me. I have a gps module that I converted the latitude and longitude to xy and I have another point for example: 33.12, 55.12.
What I need it to know is how could I know the difference between the 2 points and if I have the speed of my gps, could I be able to know when I will reach it.
Thank you in advance!

On short distances you can ignore the earth's curvature and go with Pythagorean theorem.
On larger scale you need to remember that earth is a sphere.
Theory and examples with some java here:
http://www.movable-type.co.uk/scripts/latlong.html

Related

Perspective projection based on 4 points in 2D

I'm writing to ask about homography and perspective projection.
I'm trying to write a piece of code, that will "warp" my image so that its corners align with 4 reference points that are in the 3D space - however, the game engine that I'm running it in, already allows me to get the screen position of them, so I already have their screen-space coordinates of both xi,yi and ui,vi, normalized to values between 0 and 1.
I have to mention that I don't have a degree in mathematics, which seems to be a requirement in the posts I've seen on this topic so far, but I'm hoping there is actually a solution to this problem that one can comprehend. I never had a chance to take classes in Computer Vision.
The reason I came here is that in all the posts I've seen online, the simple explanation that I came across is that each point must be put into a 1x3 matrix and multiplied by a 3x3 homography, which consists of 9 components h1,h2,h3...h9, and this transformation matrix will transform each point to the correct perspective. And that's where I'm hitting a brick wall - how do I calculate the transformation matrix? It feels like it should be a relatively simple algebraic task, but apparently it's not.
At this point I spent days reading on the topic, and the solutions I've come across are either based on matlab (which have a ton of mathematical functions built into them), or include elaborations and discussions that don't really explain much; sometimes they suggest tons of different parameters and simplifications, but rarely explain why and what's their purpose, or they are referencing books and studies that have been since removed from the web, and I found myself more confused than I was in the beginning. Most of the resources I managed to find online are also made in a different context - image stitching and 3d engine development.
I also want to mention that I need to run this code each frame on the CPU, and I'm fairly concerned about the effect of having to run too many matrix transformations and solving a ton of linear algebra equations.
I apologize for not asking about any specific code, but my general question is - can anyone point me in the right direction with this issue?
Limit the problem you deal with.
For example, if you always warp the entire rectangular image, you can treat that the coordinates of the image corners are {(0,0), (1,0), (0,1), (1,1)}.
This can simplify the equation, and you'll be able to solve the equation by yourself.
So you'll be able to implement the answer.
Note : Homograpy is scale invariant. So you can decrease the freedom to 8. (e.g. you can solve the equation under h9=1).
Best advice I can give: read a good book on the subject. For example, "Multiple View Geometry" by Hartley and Zisserman

Have distance from A to B, C, D - How to get latitude and longitude?

I am not a geographer or the like, so please excuse if I should know better. But my question is: Is it possible to get the latitude and longitude of certain places from distance data?
More precisely, I have the great-circle distance in kilometers from various places to Berlin. Can I somehow decompose this distance data into latitude and longitude?
(FYI I am an economic historian and I work with the software package Stata.)
Yep, but the answer depends on how accurate you want to be.
Quick and easy, but not exact: just assume the earth is a sphere, treat the lat/lon as spherical coordinates (using a fixed 6373km radius), perform the translation using normal 3D euclidean geometry techniques, and convert back to lat/lon at the end. A good summary of the calculations necessary is here, but in summary:
Oh dear, no Latex on this site! Screenshots from the math subsite is best I could do sorry.
If you already have arc length, then rearrange the equation to solve for your unknown. You'll also need to know the angle of your arc to solve for two unknowns, lat and long.
If you need to be exact, you'll need to take into account the non-spherical Earth. That means the length in meters of a degree latitude depends on the latitude.
As described here:
Work with those equations and perhaps ask another more specific question if you get stuck. This current site is best if you have a programming question and the https://math.stackexchange.com site is best if you have a maths question.

Get the "pan" of the sound in 3d space

I am currently writing a simple 3d sound system, but I got stuck.
The problem is:
I have a point in the space, where the sound comes from, and of course I have the listener, with his point and orientation.
The distance was not the problem, it works perfectly, but when I want to calculate the pan of the sound (how much left/right), well it is a total disaster.
I have searched it on the internet, but I can't find any usable solution, and then I tried to calculate it by myself with triangles and stuff, but you don't want to know what the result was.
I won't show code, because I have written it three times, and each version was unusable.
I don't want you to necessarily give me code, I will happy if I get a mathematical solution for that. I would like to get if the sound is how much left or right from the camera.
I work in c++ 11 and the sound library is Audiere.
Edit:
Thanks to willywonkadailyblah I figured out some solution. You can watch it here:
Get x position of sound from camera
with the dot product I can get the cos alpha of the triangle then with a simple pitagoras theorem I can get the distance (A).
And in the end I divide the pandistance with the heardistance and multiply with the sound distance.
You could calculate the dot product of the camera direction and the vector joining the camera and the sound source. This gives the cosine of the angle between the vectors. If the dot product is closer to zero than one, the sound source is more "to the side" than "in front".

Collision between a mass and a line attached to two masses

I'm currently in the making of a small c++ simulation program and, as I am very new to physics, I am struggling with what seems to be a simple 2D collision handling problem. I spent quite some time thinking about it and looking at tutorials but I just don't really get it. Here is my problem :
One point (P) is colliding a (weightless) line attached to two other points (A and B).
P, A and B each have a specific velocity (Vp, Va, Vb) at the time of the collision and they have their own weight (Wp, Wa, Wb).
I know the exact coordinates of the collision (C) and all I want to know is how I need to modify the velocity for each of these 3 points. At the moment, I try to consider the impact point as a ball (I compute its velocity as Vc=Va*(1-||AC||/||AB||)+ Vb*(||AC||/||AB||) but I'm not sure if that is a correct approach and then I'm stuck at computing its mass).
Any help, hint or resource would be greatly appreciated. Here is a small diagram I made for explaining the problem.

Curving from one point to another

I have tiles that are in random spots, and they wind up at x',y' (to make a nice 2d array) by doing :
Xt = (((X′-X)/T)*t)+X ,
Yt = (((Y′-Y)/T)*t)+Y
This works well, but it is linear. I'm looking for something curvier. A little bit like a parabola works. Basically instead of getting to X' in a straight line, I'm looking for an algorithm that will curve out and end up at X' and the amount of curvature is base on a variable.
Thanks
*EDIT
I think Bezier curve look to be what I want, but I'm not sure how to implement it. Could someone please explain the quadratic bezier formula. I'm also unsure what the 'E' - like symbol does. I think it relates to a range but I'm not sure, Thanks
You're looking for Bezier Curves, or some other similar parametric curve. These are programatically quite easy to code and have the advantage of being intuitively straightforward to manipulate. The best treatise I know of is in the classic book Mathematical Elements of Computer Graphics, but any textbook on computer graphics will probably include a basic introduction.
What you're looking for is a Catmul-Rom spline, it's a type of Hermite spline that passes though the control points. Bezier curves are not the way to go, they are difficult to control in this situation.
Have a look at this page about Perlin Noise, in particular the "Interpolation" section. The general idea is that instead of a linear transfer function over t in [0, 1], you can apply something to result in smoother curves. The "smoothest" noise is a cos(t) function, but cubic or quintic polynomials can be used to approximate a cosine.