I used Points to Path tool to convert these points into storm tracks ( See fig 1) using ID as order field and StormID 1 as Group field.But at the end all other information dissolved and I left with StormID1 , Start and End Columns ( See fig 2). I know this is what QGIS do based upon Order by and Group by field.
But I am interested in getting at least Windspeed information along the storm tracks after each points. I mean if possible to get values of point 2104 along the line till point 2105 and then point 2105 values till point 2106. If not all possible at least one column let say windspeed. ( see fig 3 for visual help).
In this case, explode the line. You will get separate line features for each segment. Than you can use these lines to join with the point attributes as you already did for the dissolved line. But this time, you have a separate line for each point.
I am new to working with geo-coordinates, and from what I have learnt, segments are called great circles on the Earth's surface. This site gives a clear formula for calculating what I would like (which is I think called the cross-track distance). However it seems an overkill for what I want to do. Firstly, I am interested in shorter distances only, maximum a few hundred kilometers (say 700 km). Second, I can do with an approximate value (say maximum 2-3% error). Third, I want the calculation as quick as possible, and the exact formula contains around 20 trig calculations.
Is there a way to generalize the above formula for point-segment distances? Or, alternatively, is there a handy approximation to find out the distance of a point and a great circle for small-to-mid distances with reasonable accuracy?
For example, say you have vertex "A" and vertex "B" constructing the edge, point "C" representing the player origin and "D" being the closest point from "C" to the edge. How would one go about calculating this? I understand that by getting the cross product of (b - a) and (c - a) can help with edge alignment, however I need to get the coordinate in 3D Cartesian space, not a comparison.
I need a basic function to find the shortest distance between a point and a line segment. Feel free to write the solution in any language you want; I can translate it into what I'm using (Javascript).
EDIT: My line segment is defined by two endpoints. So my line segment AB is defined by the two points A (x1,y1) and B (x2,y2). I'm trying to find the distance between this line segment and a point C (x3,y3). My geometry skills are rusty, so the examples I've seen are confusing, I'm sorry to admit.
Eli, the code you've settled on is incorrect. A point near the line on which the segment lies but far off one end of the segment would be incorrectly judged near the segment. Update: The incorrect answer mentioned is no longer the accepted one.
Here, in the function parameters, is the point in question and the line segment has the endpoints and . The function dist_sq (which is assumed to exist) finds the square of the distance between two points.
In my own question thread how to calculate shortest 2D distance between a point and a line segment in all cases in C, C# / .NET 2.0 or Java? I was asked to put a C# answer here when I find one: so here it is, modified from =tutorials&d2=geometry1&module=Static :
The vector d points from a to b along the line segment. The dot product of d/s with c-a gives the parameter of the point of closest approach between the infinite line and the point c. The min and max function are used to clamp this parameter to the range 0..s so that the point lies between a and b. Finally, the length of a+p-c is the distance from c to the closest point on the line segment.
It uses a parametric description of the segment, and projects the point into the line defined by the segment. As the parameter goes from 0 to 1 in the segment, if the projection is outside this bounds, we compute the distance to the corresponding enpoint, instead of the straight line normal to the segment.
Consider this modification to Grumdrig's answer above. Many times you'll find that floating point imprecision can cause problems. I'm using doubles in the version below, but you can easily change to floats. The important part is that it uses an epsilon to handle the "slop". In addition, you'll many times want to know WHERE the intersection happened, or if it happened at all. If the returned t is < 0.0 or > 1.0, no collision occurred. However, even if no collision occurred, many times you'll want to know where the closest point on the segment to P is, and thus I use qx and qy to return this location.
I'm assuming you want to find the shortest distance between the point and a line segment; to do this, you need to find the line (lineA) which is perpendicular to your line segment (lineB) which goes through your point, determine the intersection between that line (lineA) and your line which goes through your line segment (lineB); if that point is between the two points of your line segment, then the distance is the distance between your point and the point you just found which is the intersection of lineA and lineB; if the point is not between the two points of your line segment, you need to get the distance between your point and the closer of two ends of the line segment; this can be done easily by taking the square distance (to avoid a square root) between the point and the two points of the line segment; whichever is closer, take the square root of that one.
In the above expression, d is the length of the segment AB, and u, v are respectivey the scalar product and (modulus of the) cross product of AB/d (unit vector in the direction of AB) and AC. Hence vectorially,
The red point is A, the green point is B, and the point C is blue.You can drag the points in the graph to see the values change.On the left, the value 's' is the parameter of the line segment (i.e. s = 0 means the point A, and s = 1 means the point B).The value 'd' is the distance from the third point to the line through A and B.
I am currently in the middle of an algorithm that uses Eigen, and I don't want to copy my points again and again in a loop to a Boost geometry construct to check for this.This is what I currently do and it works. But it adds a dependency.
I suggest checking the distance of the point and its projection onto the line against an epsilon. Plus a check against the distance from origin, plus a check (via a dot product) that the point lies in the correct direction from the origin.
If V1==(-V2) then the point p is on the line, but preceding A, & therefore not in the segment.If V1==V2 the point p is on the line. Get the length of (p-A) and check if this is less-or-equal to length of (B-A), if so the point is on the segment, else it is past B.
Just a thought...by chance was anything brought in from AutoCad file. I know when I have worked between Layout to AutoCad to PCB Editor and had a square drawn translating to AutoCad it would add a dot at the end point of each line. Could this be the problem
I have a line segment defined by two end points. And I have another randomly chosen third point and I want to find out if the third point is on the line segment or not. By "On the line segment", I mean that exactly on the line segment, not intersecting the line segment and end up on the other side of the line segment. I hope I explained the issue. Some mathematical explanation along with reasonings/reference to the reasonings are eagerly requested.
Let the endpoints of your segment be $(x_1, y_1)$ and $(x_2, y_2)$; we want to figure out whether a point $(x,y)$ lies on the segment connecting these two points. This point $(x,y)$ will lie on the line segment if and only if all three of the conditions below are true:
$x \in [x_1, x_2]$ (or $x \in [x_2, x_1]$ if $x_2 < x_1$.) This basically states that if the $x$-coordinate of the point is outside the range of $x$-coordinates spanned by the line segment, there is no chance that it lies on the line segment.
This assumes that everything is in 2-D. The first two conditions generalize pretty straightforwardly to higher dimensions, while the last one is best written as$$\fracx - x_1x_2 - x_1 = \fracy - y_1y_2 - y_1 = \fracz - z_1z_2 - z_1 = \dots$$When written in this form, you can simply ignore the conditions that lead to quantities of the form $0/0$ (i.e., when the endpoints have one or equal coordinates); only the quantities that are well-defined need to be equal.
Imagine your points as vectors where point A is at the origin (0,0) and all other points are referenced from it (you can easily transform your points to this reference frame by subtracting point A from every point).
Here is another python implementation without using a for loop. It works for any number of points and any number of line segments. Given p_array as a set of points, and x_array , y_array as continues line segments or a polyline.
Just have a loop passing through all the points in your AB segment, "draw a segment" to C from them, get the distance from C to D and from A to D, and apply pithagoras theorem. If AD^2 + CD^2 = AC^2, then you've found your point.
Here is a python implementation based on Corey Ogburn's answer from this thread.
It projects the point q onto the line segment defined by p1 and p2 resulting in the point r.
It will return null if r falls outside of line segment:
Check if the cross product of b-a and c-a is0: that means all the points are collinear. If they are, check if c's coordinates are between a's and b's. Use either the x or the y coordinates, as long as a and b are separate on that axis (or they're the same on both).
(This is coded for exact arithmetic with integers or rationals; if you pass in floating-point numbers instead, there will be problems with round-off errors. I'm not even sure what's a good way to define betweenness of 2-d points in float coordinates.)
dd2b598166