Whats the best way to to solve two equations simultaneouly? The method i use at the minute is to store each of the coeficients separatly. Then work on them. One equation is linear the other isn't.
Rich
Printable View
Whats the best way to to solve two equations simultaneouly? The method i use at the minute is to store each of the coeficients separatly. Then work on them. One equation is linear the other isn't.
Rich
If one of the equations is linear, it seems to me substitution would work. What are the 2 equations?
y=X+1 and (X-3)^2+(Y-4)^2 = 4
Yeah substitution works fine but the code sucks, i was wondering if there was a better way than substitution.
Rich
You can graph both solutions then look for where they intersect, but i don't recomend that :)
Hmmmm, it's not clear what you are trying to do. No code is needed. This can readily be solved with algebra. The 2nd equation is a circle and the first is a line, so there are either no solutions (i.e. the line doesn't touch or cross the circle), one solution (i.e. line is tangent to the circle at one point), or 2 solutions (line crosses the circle at 2 points). In this case, there are 2 solutions. Using substitution, you get (x-3)^2 = 2, which yields x = 3 + sqrt(2) and x = 3 - sqrt(2).
What are you trying to do in code? Maybe you can post it? :sick:
This is my function, works splendind, but is there a better way to do it?
VB Code:
Public Function chordCircleIntersection(chordPoint1 As POINT, chordPoint2 As POINT, radius As Long, center As POINT) As ROOT Dim units2 As Long, m As Long, units As Long, Xco As Long, xSqrco As Long m = (chordPoint2.Y - chordPoint1.Y) / (chordPoint2.X - chordPoint1.X) units = -chordPoint1.X * m + (chordPoint1.Y) xSqrco = (m ^ 2) + 1 Xco = (-chordPoint1.X * 2) + ((-chordPoint1.Y + units) * 2) units2 = (chordPoint1.X ^ 2) + (((-chordPoint1.Y) + units) ^ 2) + (-radius ^ 2) Dim discriminant As Long, root1 As Double, root2 As Double, minusB As Long minusB = Xco * -1 discriminant = (Xco ^ 2) - (4 * xSqrco * units2) If discriminant >= 0 Then chordCircleIntersection.root1.X = (minusB + (discriminant ^ 0.5)) / (xSqrco * 2) chordCircleIntersection.root2.X = (minusB - (discriminant ^ 0.5)) / (xSqrco * 2) 'caculate the Y coords chordCircleIntersection.root1.Y = (chordCircleIntersection.root1.X * m) + units chordCircleIntersection.root2.Y = (chordCircleIntersection.root2.X * m) + units Else MsgBox "The Chord Doesn't Pass through the circle" & vbNewLine & "chordCircleIntersection", vbCritical, "Organic Molecule" End If End Function
Rich
What sucks about it? Your function is a generalized one to find the intersection of a line and a circle. From the standpoint of the mathematical approach, I think what you have is about as simple as it gets. Quite frankly, I can't think of any other way to do it, except maybe some sort of iterative technique.Quote:
Originally Posted by Rich2189
If you are looking for a critique of coding style/elegance/efficiency (e.g. using UDT's as return values, etc.), other (more experienced coders) would need to reply.
Thanks that was what i was looking for, i just supposed their must be a better way to find those points :) Aparently not. :thumb:. the thing that sucks is simulating the algebra, boggles the mind and very hard to debug.Quote:
Originally Posted by VBAhack