11 posts
• Page **1** of **2** • **1**, 2

Well, if A.x and A.y are the coordinates for point A, and same logic for B

with let's say course being a variable between 0 and 1

you have lerp(A.X, B.X, course) returning an X value

lerp(A.Y, B.Y, course) will return the Y value on the same line corresponding to that X, as long as course is between 0 and 1, the point will be between them.

EDIT: if you prefer the actual equation of the line (AB), you can have it:

Y=(A.Y-B.Y)/(A.X-B.X)*X+ init

Init being found with

A.Y=(A.Y-B.Y)/(A.X-B.X)*A.X+ init

init= A.Y-A.X*(A.Y-B.Y)/(A.X-B.X)

In the end, If I am correct,

Y=(A.Y-B.Y)/(A.X-B.X)*X+A.Y-A.X*(A.Y-B.Y)/(A.X-B.X)

or Y= (X-A.X)*(A.Y-B.Y)/(A.X-B.X) + A.Y

Depends on what you want to do exactly after that...if it is verifying if a point C is between A and B, you just verify that A.X<C.X<B.X

and that C.Y= (C.X-A.X)*(A.Y-B.Y)/(A.X-B.X) + A.Y

with let's say course being a variable between 0 and 1

you have lerp(A.X, B.X, course) returning an X value

lerp(A.Y, B.Y, course) will return the Y value on the same line corresponding to that X, as long as course is between 0 and 1, the point will be between them.

EDIT: if you prefer the actual equation of the line (AB), you can have it:

Y=(A.Y-B.Y)/(A.X-B.X)*X+ init

Init being found with

A.Y=(A.Y-B.Y)/(A.X-B.X)*A.X+ init

init= A.Y-A.X*(A.Y-B.Y)/(A.X-B.X)

In the end, If I am correct,

Y=(A.Y-B.Y)/(A.X-B.X)*X+A.Y-A.X*(A.Y-B.Y)/(A.X-B.X)

or Y= (X-A.X)*(A.Y-B.Y)/(A.X-B.X) + A.Y

Depends on what you want to do exactly after that...if it is verifying if a point C is between A and B, you just verify that A.X<C.X<B.X

and that C.Y= (C.X-A.X)*(A.Y-B.Y)/(A.X-B.X) + A.Y

Game design is all about decomposing the core of your game so it becomes simple instructions.

**Posts:**2,122**Reputation:**17,123

B

53
S

22
G

18
Would this help?

Just copied this, but you can find a lot of various methods. But this looked pretty good.

Find the slope m=(x1-x2)/(y1-y1) and make a loop of x where y=mx+c (c=0). now get

(x,y) for a range of x.

Your two points: (x1, y1) (x2, y2):

m = (y1 - y2) / (x1-x2);

c = y1 - x1 * m;

Then, for any given x:

y = mx + c;

This looks interesting(a little complicated)

If it is on a straight line, can't you find midpoint then midpoint between point a and midpoint, and midpoint and point b, and repeat etc?

Just copied this, but you can find a lot of various methods. But this looked pretty good.

Find the slope m=(x1-x2)/(y1-y1) and make a loop of x where y=mx+c (c=0). now get

(x,y) for a range of x.

Your two points: (x1, y1) (x2, y2):

m = (y1 - y2) / (x1-x2);

c = y1 - x1 * m;

Then, for any given x:

y = mx + c;

This looks interesting(a little complicated)

If it is on a straight line, can't you find midpoint then midpoint between point a and midpoint, and midpoint and point b, and repeat etc?

**Posts:**1,429**Reputation:**12,718

B

65
S

16
G

9
newt wrote:I've used lerp before with distance(). It seemed a little overly complicated, but then again so does this.

Like I don't know what init means, and I'm not sure how to get the x component out of that.

Or should I say overly simplified?

I may have over complicated it, it is the same as dutoit ( init was a value, which dutoit calls c)

Game design is all about decomposing the core of your game so it becomes simple instructions.

**Posts:**2,122**Reputation:**17,123

B

53
S

22
G

18
linear Bézier curve is what you need

dx = (1-t) * x1 + t * x2;

dy = (1-t) * y1 + t * y2;

t - is a coef. from 0 to 1.

http://commons.wikimedia.org/wiki/File: ... _1_big.gif

dx = (1-t) * x1 + t * x2;

dy = (1-t) * y1 + t * y2;

t - is a coef. from 0 to 1.

http://commons.wikimedia.org/wiki/File: ... _1_big.gif

**Posts:**191**Reputation:**9,626

B

57
S

19
G

10
@R0J0hound

Say for example I wanted to place tiles between the two points. Snapped accordingly.

I'm not terribly worried about picking objects between the points, theres a system command to do that. I think that would work.

@Kurz

Thanks, thats pretty much the same as the lerp way.

@DUTOIT

In y=mx+c (c=0) its m*(x+c)?

Say for example I wanted to place tiles between the two points. Snapped accordingly.

I'm not terribly worried about picking objects between the points, theres a system command to do that. I think that would work.

@Kurz

Thanks, thats pretty much the same as the lerp way.

@DUTOIT

In y=mx+c (c=0) its m*(x+c)?

**Posts:**8,322**Reputation:**110,788

B

169
S

50
G

174
For that you could use Bresenham's line algorithm for a nice result. But it isn't simple.

You could use lerp to do it like this:

https://dl.dropboxusercontent.com/u/542 ... _step.capx

but you'll have to handle the case when deltay is more than deltax and do the loop in that direction.

Edit: actually this would do it:

variable delta= max(abs(x1-x0), abs(y1-y0))/32

repeat delta times

--- create sprite at (round(lerp(x0, x1, loopindex/delta)/32)*32), round(lerp(y0, y1, loopindex/delta)/32)*32)

You could use lerp to do it like this:

https://dl.dropboxusercontent.com/u/542 ... _step.capx

but you'll have to handle the case when deltay is more than deltax and do the loop in that direction.

Edit: actually this would do it:

variable delta= max(abs(x1-x0), abs(y1-y0))/32

repeat delta times

--- create sprite at (round(lerp(x0, x1, loopindex/delta)/32)*32), round(lerp(y0, y1, loopindex/delta)/32)*32)

**Posts:**5,291**Reputation:**70,993

B

92
S

32
G

109
11 posts
• Page **1** of **2** • **1**, 2

## Who is online |

Users browsing this forum: No registered users and 14 guests |