# Thread: Connect the dots using Mathematics?

1. Hi,

I have random points (Xn,Yn coordinates)

I want to connect them, and then put a bandwidth around them. (So the result is a broad line connecting all the points)

How do you write something like that?

I want to write it "dynamically" so that no matter what Xn and Yn coordinates I put into it, the formula automatically computes the line and bandwith.

Thanks for any pointers

2.

3. Originally Posted by calimero
Hi,

I have random points (Xn,Yn coordinates)

I want to connect them, and then put a bandwidth around them. (So the result is a broad line connecting all the points)

How do you write something like that?

I want to write it "dynamically" so that no matter what Xn and Yn coordinates I put into it, the formula automatically computes the line and bandwith.

Thanks for any pointers
You have not clearly stated what you want to do.

A conventional approach would be a least squares fit to a straight line (rather than "connecting the dots") and then error bars based on some number of standard deviations that you select -- typically between 2 and 3.

No, that's not what I'd like to do:

I have a series of points (X1, Y1 .... Xn, Yn) I want to connect them with a line (the line starts at X1, Y1, goes to X2, Y2 exactly and ends at Xn, Yn).

After that I want to put a bandwidth around them (of, say, 1).

(It's probably a very easy question. My maths is just a bit hazy.)

5. The real world problem I want to solve: I have a number of addresses on a map (that have x,y coordinates). I want to draw a line (along roads) that has a bandwidth. I want to see which of the addresses have x,y coordinates that lie within this bandwidth. (And then do something.)

(I'm now reading up on linear equations.)

6. Okay,

So now I think I've clarified the problem a bit:

I'd like to draw a line that has different line segments.

I'd like to get a formula that describes a line segment. There's one here: Wikipedia: line segment

But I don't understand the equation (as the terms are not explained within the article)
If V\,\! is a vector space over \mathbb{R} or \mathbb{C}, and L\,\! is a subset of V,\,\! then L\,\! is a line segment if L\,\! can be parameterized as

L = \{ \mathbf{u}+t\mathbf{v} \mid t\in[0,1]\}

for some vectors \mathbf{u}, \mathbf{v} \in V\,\!, in which case the vectors \mathbf{u} and \mathbf{u+v} are called the end points of L.\,\!
After I I understand this equation (if it's correct), I'd like to convert the line segment to a rectangle that has the line at its center.

(Found another one: http://www.xamuel.com/line-segment-equation/ this looks easier.)

7. What you're trying to do sounds like a job for some GIS software such as ArcMap, if your x,y coordinates are in some geographic coordinate system like latitude/longitude or UTM. If you're trying to do anything big with this it would probably be worth checking it out so that the software can do the math for you.

8. Originally Posted by AlexP
What you're trying to do sounds like a job for some GIS software such as ArcMap, if your x,y coordinates are in some geographic coordinate system like latitude/longitude or UTM. If you're trying to do anything big with this it would probably be worth checking it out so that the software can do the math for you.
After your suggestion I checked the prices of that. It's too expensive for me

I was thinking I could just input the data and function into excel and let it compute it for me.

I've thought about it again. Now I'm thinking:

1. Use an equation that describes the roads (line segments) I want to follow
2. Perform the method of least squares (with a predefined bandwith) to find the points that lie within the prescribed distance from that line (thanks DrRocket ).
3. Arrange the points, so that 1 corresponds to the point that is closest to the start of the line, and n, the point that is closest to the end of it.

1 and 2 seem solvable. I'm still thinking about 3. I could try to perform another least squares fitting to arrange the points according to their distance from the various road intersections, maybe ...

9. Now I'm thinking calculating the distance from a point to a line is maybe better than the least squares method (which I guess is a way to plot a line, not to calculate the distance between a point and a line).

The equations I found only work on simple x1,y2 - x2,y2 lines though. How would you convert them to work on x1,y1 - x2,y2 - xn,yn problems?

10. if you are working in slope intercept form on a 2-d grid, then the distance from a point (x,y) to a line y=mx+b can be found by finding the line perpendicular to the original line that runs through the point (x,y) and taking the distance formula from the point (x,y) and the intersection of the lines.

The general distance formula for 3 dimensions is and in 2 dimensions you just get rid of the z, so it would be . think Pythagorean Theorem.

Every point needs to be dealt with separately.

Originally Posted by Arcane_Mathematician
if you are working in slope intercept form on a 2-d grid, then the distance from a point (x,y) to a line y=mx+b can be found by finding the line perpendicular to the original line that runs through the point (x,y) and taking the distance formula from the point (x,y) and the intersection of the lines.
No, I'm not. I'm working on an erratic line that is composed of multiple line segments

To simplify the problem I could say I was just working on ONE line segment and ONE point.

I could then ask two questions:

1. What would the distance between the line segment and the point be if the line segment was a line (and use this equation, not yours, I think)
2. But it isn't a line, it's a line segment. Maybe you could say that if the distance from the line segment to the point was SMALLER than the distance of the point to either end of the line, the equation I just linked to is relevant, otherwise it isn't.

Maybe I can then give a maximum value of this distance in excel

Thinking out loud here ...

12. Alright then... not sure at all what you want anymore...

I'm still thinking on how to define the problem so it can be easily solved. That's why my writing is confused.

My original question was: I have a zigzag line (x1,y1 - x2,y2 - xn,yn) and a lot of points (xa,ya/xb,yb/.....) How do you calculate the distance from the line to the individual points (and then select only those points that lie close to the line).

(I was thinking I could write a loooooong equation to describe the line)

Now I'm thinking it's probably easier to calculate the distance of each individual point to the different line segments.

So my question becomes "How to calculate the distance of a point to a line segment"

I've looked for explanations on how to do this, but haven't yet found one I understand.

Your equation y=mx+b describes a line, not a line segment. I think it could be used, but only if you also calculate the distance of the point to the endpoints of the line segment.

14. A few tips:

- Use the equation (with ) to represent your lines. Its advantage is that it can represent lines in any direction (including vertical), and computing the distance of any point from the line is simpler.

- Define lines and perpendicular to each segment and passing through its ends. Again, represent those lines as (with different A, B and C of course).

For any point in the plane, the sign of identifies which side of the line the point is on. So you can easily find how the point is positioned relative to and .

If it's between them, the distance you are looking for is the distance from the straight line containing the segment.

If it's "on the outside", you should compute the distance from one of the endpoints.

If it's on or , you can do either.

Hope this helps,
Leszek.

 Bookmarks
##### Bookmarks
 Posting Permissions
 You may not post new threads You may not post replies You may not post attachments You may not edit your posts   BB code is On Smilies are On [IMG] code is On [VIDEO] code is On HTML code is Off Trackbacks are Off Pingbacks are Off Refbacks are On Terms of Use Agreement