You are not logged in.

- Topics: Active | Unanswered

**jjones****Guest**

i have and origin and a destination of a line stored as co ords of a grid (x,y)

i need to calculate if another random point is on the path of that line

any 1 know how?

**ganesh****Moderator**- Registered: 2005-06-28
- Posts: 19,182

Le the point denoted by (x,y) have coordinates (a,b).

The segment has one end at the origin ( 0,0 ) and the other end at (a,b).

Therefore, the equation of the straight line is

(y-y1)/(y2-y1) = (x-x1)/(x2-x1)

(x1,y1) = ( 0,0 ), (x2,y2) = (a,b)

Thus, yb=ax

or yb-ax=0 is the equation of the segment.

We know the point (a,b). It could be (1,4) or (5,8) or (-1,4) etc.

Thus, an equation in two variables of degree 1(a linear equation) is obtained.

If the random point is a solution for the equation of the segment, then the point lies on the segment. Otherwise, it does not.

It is no good to try to stop knowledge from going forward. Ignorance is never better than knowledge - Enrico Fermi.

Nothing is better than reading and gaining more and more knowledge - Stephen William Hawking.

Offline

**jjones****Guest**

thanks for you reply but i am still a little unclear is there anyway u could show me with an example e.g

start of line = (5,5)

end of line = (20,20)

point = (10,10)

would the point be on the line?

**jjones****Guest**

my understandign would be that

where x and y is the point

with x1,y1 the start of the line and x2,y2 the end of the line

(x2-x1) * X - (y2-y1) * y = 0

**ganesh****Moderator**- Registered: 2005-06-28
- Posts: 19,182

The starting and ending point you have given is (5,5) and (20,20).

Let (x1,y1) be (5,5) and (x2,y2) be (20,20).

The equation of the segment would be

(y-5)/(15) = (x-5)/(15)

y-5 = x-5

y-x=0.

The point (10,10) satisifies this equation.

Therefore, the point (10,10) lies on the segment.

It is no good to try to stop knowledge from going forward. Ignorance is never better than knowledge - Enrico Fermi.

Nothing is better than reading and gaining more and more knowledge - Stephen William Hawking.

Offline