The Daily Click ::. Forums ::. Klik Coding Help ::. Equation of a line
 

Post Reply  Post Oekaki 
 

Posted By Message

Peblo

Custom ratings must be 50 characters or less

Registered
  05/07/2002
Points
  185

Game of the Week WinnerVIP MemberI'm on a Boat360 OwnerAttention GetterThe Cake is a LieCardboard BoxHero of TimePS3 OwnerIt's-a me, Mario!
I'm a Storm TrooperSonic SpeedStrawberryI like Aliens!Wii OwnerMushroomGhostbuster!
20th November, 2005 at 17:23:26 -

I'm building another application, and I have run in need of an extension, or example or something. Basically, I need something where you put in a few X and Y coordinates, and it tells you the equation of the line. Anything like this exist?

 
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
20th November, 2005 at 17:48:28 -

y - y1 = m(x - x1)

thats the equation for a straightline where y1 is a y co-ordinate and x1 is a corresponding x co-ordinate and m is the gradient

EG 2 points, A(0,0) and B(1,3)

to find m :
(y2 - y1)/(x2-x1) = (3-0)/(1-0) = 3

then

Y - Y1 = m(X- X1) or Y - 3 = 3(x-1)
which = Y = 3x

simple

 
My signature is never too big!!!

RapidFlash

Savior of the Universe

Registered
  14/05/2002
Points
  2712
20th November, 2005 at 17:51:29 -

If you also need the y-intercept
y-intercept = y1 - (m * x1)

 
http://www.klik-me.com

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th November, 2005 at 19:38:45 -

well im guessing you dont have a clue about linear functions cause lines are the easiest. have it do this. X2-X1=X3, Y2-Y1=Y3; Y3/X3 equals your slope

(12,6),(4,2)

4-12 = -8 ; 2-6 = -4

(-8,-4) -4/-8 = .5 <<--your slope

then you need to put it back into place.

y+6=.5(X+12)

friendly format y=.5(x+12)-6

now when you get into 3 or more sets of x,y coordinates at a time your gonna get into regressions and i know how to make a calculator do em but unless they are all linear i cant give you a methid of how to do it

 
n/a

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
20th November, 2005 at 19:42:02 -

i already said all that legend

 
My signature is never too big!!!

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th November, 2005 at 19:49:05 -

but i said it in a longer paragraph and much more mathematical gibberish..ish....ish. by the way, do YOU know how to solve regressions without a calculator. id like to know if you did.

 
n/a

Peblo

Custom ratings must be 50 characters or less

Registered
  05/07/2002
Points
  185

Game of the Week WinnerVIP MemberI'm on a Boat360 OwnerAttention GetterThe Cake is a LieCardboard BoxHero of TimePS3 OwnerIt's-a me, Mario!
I'm a Storm TrooperSonic SpeedStrawberryI like Aliens!Wii OwnerMushroomGhostbuster!
20th November, 2005 at 19:53:38 -

I know how to do straight lines, I meant about parabola's(sp?) and stuff, for like 3 or more XY coordinates.

 
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th November, 2005 at 20:15:39 -

basic parabola is y=x^2 (smiley parabola) y=-x^2 (frowny parabola)
quadratic formula stuff and using systems.ill post it later when i can write something good down and explain it well. unless someone else nails it before i do.
---------------------------------------------

ok here it goes.
this only works for 3 coordinates as far as i know. and you have to have knowledge of matrice multiplication.

say i have these points. (1,4);(12,4);(6,2)

you put them into a system like so

{x^2a + xb + c = y

so my system for these coordinates are

{1a + 1b + 1c = 4
{144a + 12b + 1c = 4
{36a + 6b + 1c = 2

now we use the matrice multiplication of [A]^-1 * [C] ;(^-1 = inverse of [A]not [A] raised to the negative one)

____[ 1 1 1 ]
[A]=[ 144 12 1 ]
____[ 36 6 1 ]

____[ 4 ]
[C]=[ 4 ]
____[ 2 ]
_____________________[ .0666666667 ] = a
so [A]^-1 * [C] gives us [ -.8666666667 ] = b
_____________________[ 4.9 ] = c

so our equation for the parabola through these points is
y = .0666666667X^2 + -.8666666667X + 4.9 (y = ax^2 + bx + c)
--------------------------------------------

note: if your thinking your gonna be able to connect the dots of a random scatter plot your best bet would be to go with linear functions connected by piecewise models.

Image Edited by the Author.

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
22nd November, 2005 at 00:43:21 -

so im guessing since you arent responding this doesnt help you...too complicated?

 
n/a

Peblo

Custom ratings must be 50 characters or less

Registered
  05/07/2002
Points
  185

Game of the Week WinnerVIP MemberI'm on a Boat360 OwnerAttention GetterThe Cake is a LieCardboard BoxHero of TimePS3 OwnerIt's-a me, Mario!
I'm a Storm TrooperSonic SpeedStrawberryI like Aliens!Wii OwnerMushroomGhostbuster!
22nd November, 2005 at 01:39:30 -

Uhh, actually I forgot all about this topic.

Anyways, I understand most of it, except matrice multiplication and implementing it. The thing I need this for is this: the user holds down the mouse button, and if they move the mouse (variable) pixels, it creates a point. When they let go of the mouse button, about 5 points will exist. I need something that will take those X and Y coordinates and make them an equation, which will be matched against 8 hardcoded possibilities. Whichever equation matches the user input the closest will execute some code.

Basically, I need something that takes (var)XY points, and puts them in a string that can be compared to a database of sorts.

Edit: Sorry, I think I mean expression instead of equation in anything I said. I think so anyways.

Image Edited by the Author.

 
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
22nd November, 2005 at 14:30:07 -

equation and expression are pretty much the same thing. i think but like i said your probably looking at using something like piecewise functions. They are a string of functions that pretty much play connect the dots, but like i said before your prolly not gonna be able to use a function or an equation to make a single equation to connect all these points.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click