From: RKA Date: 2013-02-18T00:52:26+09:00 Subject: Re: finding Collinearity of three points --f46d0402a9f333fbb304d5ed9836 Content-Type: text/plain; charset=ISO-8859-1 Well to find co-linearity of three point in general we can draw a line through any two points and if the line intersects the third point then the points must be co-linear. We can break the problem into a few parts: - Getting the points from the users This is easy; we just use a series of gets. - finding a line that goes through two of them (this involves the point slope formula) We need to take the input and plug it into our point slope formula: y-y1 = m(x-x1) But we need a slope! So before we do that we need to define m = (y2 - y1)/(x2 - x1) We should solve it for y, for reasons that will become apparent soon. So the final formula that we'll be using is this: y = (y2 - y1)/(x2 - x1)(x-x1) - y1 - checking to see if the third point is on the line Now that we have a line, we need to check if the third point is on it. We know that if we plug in the third point's x value, and it's on the same line, it should return the same y value as the possibly co-linear third point. So just compare the two y values, and if they are the same they are co linear! I hope this helps. Is this for a homework assignment? On Sun, Feb 17, 2013 at 5:33 AM, prem c s wrote: > Can someone here explain me the logic and implementation for finding > collinearity of three points in Ruby? > > > > Thanks in advance... > > -- > Posted via http://www.ruby-forum.com/. > > --f46d0402a9f333fbb304d5ed9836 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Well to find=A0co-linearity=A0of three point in general we= can draw a line through any two points and if the line intersects the thir= d point then the points must be co-linear.=A0

We can bre= ak the problem into a few parts:=A0
  • =A0Getting the points from the users
  • This is easy; we just use a series of gets.
    • findin= g a line that goes through two of them (this involves the point slope formu= la)
    We need to take the input and plug it into our point slope formula: y-= y1 =3D m(x-x1)
But we need a slope! So before we do that we= need to define m =3D (y2 - y1)/(x2 - x1)

We should solve it for y, for reasons that will become apparent soon. So th= e final formula that we'll be using is this:
y =3D=A0(y= 2 - y1)/(x2 - x1)(x-x1) - y1
  • checking to see if the = third point is on the line
Now that we have a line, we need to check if the= third point is on it. We know that if we plug in the third point's x v= alue, and it's on the same line, it should return the same y value as t= he possibly co-linear third point. So just compare the two y values, and if= they are the same they are co linear!

I hope this= helps. Is this for a homework assignment?

On Sun, Feb 17, 2013 at 5:33 AM, prem c s <lists@ruby-forum.com= > wrote:
Can someone here explain me the logic and implementation f= or finding
collinearity of three points in Ruby?



Thanks in advance...

--
Posted via http://= www.ruby-forum.com/.


--f46d0402a9f333fbb304d5ed9836--