# plotting crossing lines

This topic is 4100 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi I have a small problem. I have 2 coordinates (x1,y1 and x2,y2). From these I was going to calculate the length between the points. This by itself is not problem. The problem is this: The distance between the points form a line of a given length. Along this line I want to calculate 10 (equally aligned) crossing lines that are 10 units long in each direction from the base line with a 90 degree angle. The lines are of no importance by themselves, but the x,y coordinates at both ends are. Can anyone help me out in the right direction here? Take a look in the following drawing: http://home.online.no/~bj-bakke/lines.png I am using this information in order to create a small utility to help he analyze images for use in biometric authentication (non-profit research project).

##### Share on other sites
To calculate the equally spaced points on the line, you can use linear interpolation. The formula is (x,y) = (x1,y1)(1 - t) + (x2,y2)(t), and you choose values for 't' in-between [0,1], inclusively. t = 0 is the first endpoint, and t = 1 is the second endpoint. So for 10 points, you could choose t = 0.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75. 0.85, 0.95.

To determine the direction perpendicular to the line, you take the 2D cross-product (not surprisingly called 'perp') of the line's direction. This vector is (x2,y2)-(x1,y1), and the 'perp' operator is defined as perp(x,y) = (-y,x). You then normalize this vector and multiply it by the length you want in each direction (10 in this case). Then just add/subtract it onto each point you calculated in the first step (adding gives you the first line endpoint, subtracting gives you the second line endpoint).

##### Share on other sites
Here's how I'd do it. First, determine the distance between points, which you said yourself is trivial. Obtain the slope of the line between the points (y1 - y0) / (x1 - x0). Now, the slope of the new crossing lines is just the negative reciprocal of the slope you just calculated, since they are perpendicular.

Now we are going to need the point on the original line where the new one crosses (let's say we're doing the one closest to (x1,y1)) Just make the difference of the points a vector, scale it to 1/10 length, and add to the first point. You now know the point on the original line.

With m being the slope, the general equation for a line is y - y1 = m(x - x1) where the x1 and y1 is the point on the line just calculated. Repeat this for the rest of the crossing lines using an appropriate vector scale each time and you have all the lines.

To calculate the end points of the line segments that go out 10 units, we again use the point on the original line and the slope of the crossing line. Multiply the slope by the distance 10. The slope is the change in y / change in x. So just add this to the point on the line to go in one direction, and subtract it from the point on the line to go in the other. That should do it.

1. 1
2. 2
Rutin
18
3. 3
khawk
15
4. 4
A4L
14
5. 5

• 9
• 13
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013665
×