I have a current position: Latitude and Longitude values in degrees (Point A), and the same for the final position (Point B).
I need to calculate the course (also in degrees) between the two points and than with given speed (in km/s) and timespan (in seconds) to calculate the new position.
Example (Pseudo code):
PointA.Lat = x.xxxx;
PointA.Lng = x.xxxx;
PointB.Lat = x.xxxx;
PointB.Lng = x.xxxx;
Speed = 3;
TimeSpan = 0.1;
Course = GetCourse(PointA, PointB);
NewPoint = CalculatePoint(PointA, Course, Speed, TimeSpan);
I thought of using the GeoCoordinate class, but I'm not sure how ad I have to implement myself all the calculations. (I don't have a GPS - this is only a simulation and those are fake points).
Can someone help me with the math or with some package that can do it free and can easly be intagrated to my code?
BTW I'm using C#.
Thanks.
I'd have made this a comment but I don't have the required rep.
What you're looking for is a geodesy library that gives you the “geodetic inverse” and “geodetic direct” calculations. I don't know of any myself, but try searching for “c# geodesy library”
The former gives the bearing and distance between two geographical coordinates, the latter gives a new coordinate at a given bearing and distance from the first.
So for your problem:
Use the inverse to get the bearing between PointA and PointB
Calculate a destination distance from the time and speed,
Plug the bearing and distance into the direct to get the desired destination NewCoord.
Coding these calculations from 1st principles will be quite substantial and require the parameters of (presumably) the WGS84 ellipsoid. This, however, is the starting point.
Hope this helps.
Related
Let's suppose I have the following data points on Earth:
var startPoint = [51.263969,-0.527153]
var endPoint = [51.258813,-0.505876]
var vector = [startPoint,endPoint]
var metres = 100
So the startPoint and endPoint represent a vector along the globe. What I need to do is find a new point which represents a point 100 metres away from endPoint in the direction of the vector.
How can I do this?
I've found some algorithms to move a lat/long by a number of metres, but they don't take into account an angle. I've also had a look through C# libraries such as DotSpatial but can't find anything to do this.
Bonus points for a C# library which can do this! But I'm happy to implement this myself if necessary.
Note: This should be calculated on a 3D spherical plane, example: Earth
As the title suggests, I am trying to generate a coordinate based on another coordinate that is within an x mile (or whichever unit is most convenient) radius of the inputted one.
As an example:
I am given a geographic coordinate (lat, lon) of 39.083056, -94.820200.
I want to be returned another set of coordinates that is within a x
miles radius of that coordinate, such as 39.110998, -94.799668.
The x mile radius isn't as important as the fact that the returned
coordinates are within that x mile radius.
I have searched and searched, but I must be searching the wrong thing because all the posts that I have been able to find seem like they get very close to what I am trying to do but aren't quite hitting the nail on the head.
I'm sorry you're being downvoted to oblivion. I understand it can be frustrating trying to search for something without knowing what exactly to search for.
You may be interested in Orthodromic Lines/Distances: wiki. If this answer doesn't fulfil your needs, at least you have a new term to google and hopefully will lead you to one that does suit.
You could try using the Geo library. Its documentation is on the sparse side, but it does contain a method that could be useful to you: CalculateOrthodromicLine(startPoint, heading, distance)
A pseudocode would be something as simple as this:
var startPoint = new Coordinate(lat, long);
var heading = Random between 0 and 360 degrees
var distance = Random between 0 and X metres
var endPoint = //<-- et voila!
GeoContext.Current.GeodeticCalculator
.CalculateOrthodromicLine(startPoint, heading, distance)
.Coordinate2;
Edit: As mentioned in the wiki, the Earth is not a perfect sphere, but a spheroid instead. The library's GeoContext.Current by default uses its Spheroid calculations, so you should be okay.
Good luck!
Lets assume we have a bezier curve with a start p0 of (0, 0) and an end p4 of (100, 0). Right now it would basically be a line with no curve yet. Now lets assume I want to calculate the two missing control points (p1 p2) based on a given angle. What is the best way to achieve this?
Lets assume I wanted something like this:
https://1.bp.blogspot.com/_W3ZUYKgeEpk/SDcAerq1xkI/AAAAAAAAAAc/W9OnovkzgPI/s400/RectanglularControlPoly.jpg
I mean depending on the position of the control points it forms a triangle of some sort, that is why I was wondering if its possible.
Controls points that go through a Bezier point with a given angle, lie on the tangent with that angle.
The resulting bending will be the softer the farther away the control point is chosen, so there are many different solutions with the same angle and different curvature..
To find control points with equally soft curvatures for two Bezier points simply find the crossing of the two tangents! Use the crossing as the common control point for both segments, i.e. have C1 = C2.
For any sort of symmetrical curve you need to keep the deviations from the crossing symmetrical, i.e. 50%, 10% etc..
Note that for optimizing the overall shape one also needs to look at the neighbouring points; in general the provided GDI function does a good job; so it is worth considering simply adding more Bezier points for controlling the shape; but of course using the perfect set of control points is the most economic solution.
Update: I have added an example of how well a circle (orange) gets approximated by the math in this interesting post.
Short version: An exact solution isn't really possible but the best fit for a quarter circle is to move the control point to ~0.55% of the crossing point. (d=r*4*(sqrt(2)-1)/3). Sometimes instead of using a 4 segment solution an 8 segment solution is used for even closer approximation..
private void button_Click(object sender, EventArgs e)
{
int w = Math.Abs(P2.Left - P1.Left);
int h = Math.Abs(P2.Top - P1.Top);
C2.Left = (int) (P2.Left + w * 0.5523f);
C2.Top = P2.Top;
C1.Left = P1.Left;
C1.Top = (int) (P1.Top + h * 0.5523f);
C1.Parent.Invalidate();
}
The code uses Labels for the points and control points..
Btw: Adding ellipses/circles to a GraphicsPath will create bezier curves that seem to be approximated just like that.
I am trying to minimize the difference between sets of square markers in 3d space with a set of unknown parameters.
I have a model set of these square markers (represented by 3d position and rotation) which should at the end of optimization match up with a set of observed square markers.
I am using Levenberg–Marquardt to optimize the set of unknown parameters, these parameters will alter the position and rotation of the model 3d markers until they match (more or less) with the observed 3d marker positions.
The observed 3d markers come from a computer vision marker detection algorithm. It gives the id of the markers seen in each frame and the transformation from the camera of each marker (using Coplanar posit). Each 'frame' would only be able to see a small number of markers in the total set of markers, there will also be inaccuracies in the transformation.
I have thought of how to construct my minimization function and I thought to try to compare the relative rotations and minimize the difference between the rotations in each iteration of the LM optimisation.
Essentially:
foreach (Marker m1 in markers)
{
foreach (Marker m2 in markers)
{
Vector3 eulerRotation = getRotation(m1, m2);
ObservedMarker observed1 = getMatchingObserved(m1);
ObservedMarker observed2 = getMatchingObserved(m2);
Vector3 eulerRotationObserved = getRotation(observed1, observed2);
double diffX = Math.Abs(eulerRotation.X - eulerRotationObserved.X);
double diffY = Math.Abs(eulerRotation.Y - eulerRotationObserved.Y);
double diffZ = Math.Abs(eulerRotation.Z - eulerRotationObserved.Z);
}
}
Where diffX, diffY and diffZ are the values to be minimized.
I am using the following to calculate the angles:
Vector3 axis = Vector3.Cross(getNormal(m1), getNormal(m2));
axis.Normalize();
double angle = Math.Acos(Vector3.Dot(getNormal(m1), getNormal(m2)));
Vector3 modelRotation = calculateEulerAngle(axis, angle);
getNormal(Marker m) calculates the normal to the plane that the square marker lies on.
I am sure I am doing something wrong here though. Throwing this all into the LM optimiser (I am using ALGLib) doesn't seem to do anything, it goes through 1 iteration and finishes without changing any of the unknown parameters (initially all 0).
I am thinking that something is wrong with the function I am trying to minimize over. It seems sometimes the angle calculated (3rd line) returns NaN (I am currently setting this case to return diffX, diffY, diffZ as 0). Is it even valid to compare the euler angles as above?
Any help would be greatly appreciated.
Further information:
Program is written in C#, I am using XNA as well.
The model markers are represented by its four corners in 3D coords
All the model markers are in the same coordinate space.
Observed markers are the four corners as translations from the camera position in camera coordinate space
If m1 and m2 markers are the same marker id or if either m1 or m2 is not observed, I set all the diffs to 0 (no difference).
At first I thought this might be a typo, but then I realized that this could be a bug, having been a victim of similar cases myself in the past.
Shouldn't diffY and diffZ be:
double diffY = Math.Abs(eulerRotation.Y - eulerRotationObserved.Y);
double diffZ = Math.Abs(eulerRotation.Z - eulerRotationObserved.Z);
I don't have enough reputation to post this as a comment, hence posting it as an answer!
Any luck with this? Is it correct to assume that you want to minimize the "sum" of all diffs over all marker combinations? I think if you want to use LM you should not use Math.Abs.
One alternative would be to formulate your objective function manually and use another optimizer. I have recently ported two non-linear optimizers to C# which do not even require you to compute derivatives:
COBYLA2, supports non-linear constraints but require more iterations.
BOBYQA, limited to variable bounds constraints, but provides a considerable more efficient iteration scheme.
I'm doing a project on radar simulation and i have to detect how fast a plane is flying using c#.
Is there a formula which I can use to calculate the distance and the speed?
See the picture, R is the radar, P1 is the plane position at time 0, P2 is the plane position after time t. Since we know the speed of the radar wave in the air, we can calculate RP1 and RP2 easily. Also the angle P1RP2 is known, we can get length of P1P2 by trigonometric function. so the speed of the plane is P1P2/t.
There are different ways to determine the speed via radar. the one already mentioned, but also the change of frequency.
you might wanne check this out:
http://en.wikipedia.org/wiki/Doppler_radar
the distance between plane and radar is a result of the time used between transmitting and receiving.
d = c*t/2
If you have two know two points where the plane has been, and the time difference between these references, then it is very possible.
Speed it easy, calculate the distance usin g pythagorus:
float dist = sqrt( sqr(x2-x1) + sqr(y2-y1) );
Direction is trickier, and requires some trig. Try searching the internet for the formula for direction between two points.