Ok, tried everywhere else...

# Thread: Ok, tried everywhere else...

1. Senior Member
Join Date
Dec 1969
Posts
16,931

## Ok, tried everywhere else...

I&#039;m doing a 3D flash game. I need to solve this algebraic problem before I can move forward. Can anyone help? I think I&#039;ve got it right, but it just doesn&#039;t seem to produce the right co-ordinates in the game...<BR><BR>PROBLEM:<BR> Find the intercepts between a line and a circle.<BR> Line will always go through the centre point of the circle (a,b),<BR> so there will always be two intercepts.<BR><BR>KNOWN "GOOD" EQUATIONS:<BR> General equation of a line: y = mx + c<BR> General equation of a circle: r^2 = (x-a)^2 + (y-b)^2 (Where centre is at (a,b) and radius of r)<BR><BR>MY SOLUTION:<BR> If you feel brave, try it yourself, otherwise play spot the deliberate mistake:<BR> LET gen. equation of a line be #1.<BR> LET gen. equation of a circ be #2.<BR> REARRANGE #2:<BR> r^2 = (x - a)^2 + (y - b)^2<BR> (expand brackets)<BR> =&#062; r^2 = (x^2 - 2ax + a^2) + (y^2 - 2by + b^2)<BR> (re-arrange bits)<BR> =&#062; x^2 + y^2 - 2ax - 2by + a^2 + b^2 - r^2 = 0<BR> LET above equation be #3.<BR> As at intercepts, equations are equal:<BR> PLACE #1 into #3:<BR> =&#062; x^2 + (mx + c)^2 - 2ax - 2b(mx + c) + a^2 + b^2 - r^2 = 0<BR> (expand brackets again)<BR> =&#062; x^2 + ((mx)^2 + 2cmx + c^2) - 2ax - 2bmx - 2bc + a^2 + b^2 - r^2 = 0<BR> (group like terms)<BR> =&#062; x^2 + (mx)^2 + 2cmx - 2ax - 2bmx -2bc + a^2 + b^2 - r^2 + c^2 = 0<BR> LET above equation be #4<BR> Above equation is of the form Ax^2 + Bx + C = 0, therefore quadratic..<BR> Find values for A, B and C:<BR> A = (1 + m^2)<BR> B = (2cm - 2a - 2bm)<BR> C = (-2bc + a^2 + b^2 - r^2 + c^2)<BR> Quadratic equation formula states that:<BR> x = (-B +- sqrt(B^2 - 4AC)) / (2A)<BR> The DETERMINANT of a quadratic equation is given by:<BR> d = B^2 - 4AC<BR> If the determinant is less than zero, there are no roots to the equation in the real plane,<BR> (only complex roots). This should never be the case, because our line goes through the centre point.<BR> If the determinant equals zero, there is one real root (a tangent). This should never happen either.<BR> If the determinant is greater than zero, there are TWO real roots (one where the square root is positive,<BR> one where the square root is negative). This is what we&#039;re after.<BR> <BR> Now, this is fine. At this point, I&#039;ve got an equation which I can use.<BR> When I code it into flash, though, I keep getting "no real roots" appear on screen, which is obviously wrong.<BR> I can&#039;t see where I&#039;ve mis-typed the equation into Flash, so I figure it MUST be my maths...<BR><BR>Any ideas?<BR><BR>Craig.

2. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Ok, tried everywhere else...

Just thought of something. The distance between the centre (known) point and the intercepts will always be "r" (the radius). By definition.<BR><BR>Maybe that&#039;ll get me somewhere...<BR><BR>Ugh, got a Uni lecture on Web Site Management tonight. "FORMS" tonight. Yippee. Maybe I can sit there and do this.<BR><BR>Craig.

3. Senior Member
Join Date
Dec 1969
Posts
2,930

## i can show you...

i&#039;ll email you... email me at jasontconnell theAtSign hotmail theDot com . i have to draw some lines and circles.. i just did a problem like that here in work. well, not exactly, but it dealt with circles, so the math is still fresh in my head... i know exactly how to do it though. math is my golden ticket :-)<BR><BR>Jason<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
16,931

## Cheers man

Email&#039;s winging it&#039;s way.<BR><BR>Hoping to get it before I go to uni - gives me something to read through while the lecturer whines on and on...<BR><BR>:-)<BR><BR>Craig.

5. Senior Member
Join Date
Dec 1969
Posts
2,930

## doh

just got invited to lunch.... it would take me a little while to write, anyway... may be in time for tomorrow :-) but, fear not, the answer is coming :-)<BR><BR>Jason

6. Senior Member
Join Date
Dec 1969
Posts
16,931

## Hehe, ok, cheers.

Well, it&#039;s 5:20 so I&#039;m off in a minute.<BR><BR>Cheers man. This has been p*ssing me right off for a couple of days now, so any light you can shed would be great.<BR><BR>Craig.

7. Senior Member
Join Date
Dec 1969
Posts
16,931

## Thanks KLOOJ.

Still not exactly sure why my way doesn&#039;t work, but thanks - I&#039;ve coded your method and the intercepts appear correctly marked on my little debug diagram.<BR><BR>Now to re-write the drawing functions and see what I end up with! :-)<BR><BR>Craig.

8. Senior Member
Join Date
Dec 1969
Posts
2,930

## no problem

like i said... all the trig was still fresh in my head from 2 weeks ago when i did something cool here in work... it&#039;s amazing when you went into computer science because you thought it had a lot to do with math, then you remember the 2 times in 6 months that you actually used math at your work... i need a new job...<BR><BR>anyway, in most math problems, there is always a way to make it shorter... i remember using newton&#039;s method in college to figure out the roots of equations up to the 5th degree... that was fun. a lot shorter than conventional methods. just like in english, you can say "i feel there is something attacking my immune system and it&#039;s making me feel not right" can all be replaced with "i&#039;m sick." hehe. there&#039;s got to be an equation that gets both points in fewer steps... you know? anyway, if anyone besides craig is reading this, you can check out my answer here:<BR><BR>http://www.jasontconnell.com/source/trig/circletrig.html<BR><BR>email me any questions or possible enhancements.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•