dafero
dafero

Reputation: 1107

How to know the line joining two points?

I have two points and I want to know the line which is joining them. I don't want to draw the line.

I want to create a matrix with all the points which formed the line.

In the future, I want to solve if two points belong or not to a shape. And this is the first part.

EDIT: Thanks to everyone!! I've solved my doubts! I have to apply the equation of the straight line!

Thanks again!

Upvotes: 1

Views: 7914

Answers (6)

Chathuranga Chandrasekara
Chathuranga Chandrasekara

Reputation: 20946

You have an infinite given that the line is not necessarily to be straight.

If you are talking about a straight line then it is a line f(x) = mx + c type and it is pure maths. This article contains all the things you require..

you may need to use the following to get your "matrix"

alt text
(source: mathsisgoodforyou.com)

Upvotes: 1

vaitrafra
vaitrafra

Reputation: 662

In the Cartesian coordinate system, a straight line is defined by the formula y=mx.

Call your two points A and B.

Their coordinates are (xA, yA) and (xB, yB), respectively.

The straight line that passes through A and B can be calculated using:

y - yA      x - xA
------- = ---------
yB - yA    xB - xA

Upvotes: 1

learner135
learner135

Reputation: 357

Equation of a line joining two points(x1,y1) (x2,y2) is:

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

So,any point that satisfies (x,y) in the equation will be on the line.

Upvotes: 3

stacker
stacker

Reputation: 68982

See the Two point form of linear equation if you calc the slope you can iterate from x1,y1 to x2,y2 with the required precsision to find all points between (Using point-slope form).

Upvotes: 1

Peter Tillemans
Peter Tillemans

Reputation: 35341

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

with the usual caveats for avoiding division by 0

Upvotes: 5

merin
merin

Reputation: 333

you must have a function y=f(x). Take your point and calc the function. p(x1,y1) and function must y1 = f(x1).

Upvotes: 1

Related Questions