#### Archived

This topic is now archived and is closed to further replies.

# Lines

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

## Recommended Posts

If i have a line, defined with X1,X2,Y1,Y2...is there any mathematical formula to find other points on the line, say, 10 points equal distances apart in the line? Thanks Alcohol & calculus dont mix. Never drink & derive.

##### Share on other sites
you need a parametric representation of your line...
something like:

x = x1 + t * (x2 - x1)
y = y1 + t * (y2 - y1)

and to get your 10 points, you just have to make a loop like this:

x2 -= x1;
y2 -= y1;
for (i = 0.0f; i < 1.0f; i += 0.1f)
{
p->x = x1 + i * x2;
(p++)->y = y1 + i * y2;
}

##### Share on other sites
Another solution is to find the length of the line and the unit vector in the direction of your line, aka pointing from x1, y1 to x2, y2. Then you divide your the lenght by the number of points you need and multipy the result by your unit vector. Then its simply a matter of putting the vectors together, starting at the point x1, y1.

##### Share on other sites
#define HOPS 10.0double deltaX = (p2x - p1x)/HOPS;double deltaY = (p2y - p1y)/HOPS;double newX, newY;newX = p1x;newY = p1y;for(int i = 1; i <= HOPS; i++){  newX = p1x + deltaX * i;  newY = p1y + deltaY * i;}

Why nobody else gives a plain english code dump is beyond me. Outside of that though, I agree with sBibi. Parametrics are much easier and quicker for just about everything, to work with.

[edited by - haro on July 10, 2003 5:03:51 AM]

##### Share on other sites
Needless to say, newX/newY would be reals. So add 0.5 and cast them to integers and you would have rounded screen coordinates.

##### Share on other sites
rounded screen coordinates?
yes, and loose any kind of subpixel accuracy... :/

StormArmageddon> the method you describe is just another way to see a parametric representation

##### Share on other sites
quote:
Original post by sBibi
rounded screen coordinates?
yes, and loose any kind of subpixel accuracy... :/

Bah, writing a blender takes about 2 seconds and isn''t even really required for decent looks.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 28
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631772
• Total Posts
3002260
×