Kreis von 3 Punkten berechnen
Übersicht

![]() |
maximilianBetreff: Kreis von 3 Punkten berechnen |
![]() Antworten mit Zitat ![]() |
---|---|---|
Da es mich doch etwas länger gekostet hat, das auszurechnen, poste ich mal diesen Schnipsel hier. Es wird ein Kreis berechnet, auf dem die Punkte (a,b) (c,d) (e,f) liegen. Zurückgegeben werden die Koordinate (x,y) und der Radius r.
Code: [AUSKLAPPEN] SuperStrict
Graphics 640, 480 Local points:Double[3,2] Local state:Int Local circle:Double[] = [0:Double, 0:Double, 0:Double] While Not KeyHit(KEY_ESCAPE) Cls If MouseHit(1) Then points[state,0] = MouseX() points[state,1] = MouseY() state :+ 1 If state = 3 Then state = 0 circle = CalcCircle(points[0,0], points[0,1], points[1,0], points[1,1], points[2,0], points[2,1]) End If SetColor 255, 255, 255 DrawOval circle[0]-circle[2], circle[1]-circle[2], circle[2]*2, circle[2]*2 SetColor 0, 0, 255 DrawText "x: " + circle[0] + " y: " + circle[1] + " r: " + circle[2], 0, 0 For Local i:Int = 0 Until 3 DrawOval points[i,0]-5, points[i,1]-5, 10, 10 Next Flip Wend Flip WaitKey() Function CalcCircle:Double[](a:Double, b:Double, c:Double, d:Double, e:Double, f:Double) Local x:Double, y:Double, r:Double ' (a - x)^2 + (b - y)^2 = r^2 ' (c - x)^2 + (d - y)^2 = r^2 ' (e - x)^2 + (f - y)^2 = r^2 ' gleichsetzen: ' => (a - x)^2 + (b - y)^2 = (c - x)^2 + (d - y)^2 ' <=> y' = (a^2 - 2*a*x + b^2 - c^2 + 2*c*x - d^2) / (2*b - 2*d) ' ' => (c - x)^2 + (d - y)^2 = (e - x)^2 + (f - y)^2 ' <=> y'' = (c^2 - 2*c*x + d^2 - f^2 + 2*e*x - e^2) / (2*d - 2*f) ' ' y' = y'' ' <=> (a^2 - 2*a*x + b^2 - c^2 + 2*c*x - d^2) / (2*b - 2*d) = (c^2 - 2*c*x + d^2 - f^2 + 2*e*x - e^2) / (2*d - 2*f) ' <=> x = ((-a^2 - b^2 + c^2 + d^2) / (2*b - 2*d) + (c^2 + d^2 - e^2 - f^2) / (2*d - 2*f)) / ((-2*a + 2*c) / (2*b - 2*d) + (2*c - 2*e) / (2*d - 2*f)) x = ((-(a^2) - b^2 + c^2 + d^2) / (2*b - 2*d) + (c^2 + d^2 - e^2 - f^2) / (2*d - 2*f)) / ((-2*a + 2*c) / (2*b - 2*d) + (2*c - 2*e) / (2*d - 2*f)) y = (a^2 - 2*a*x + b^2 - c^2 + 2*c*x - d^2) / (2*b - 2*d) r = Sqr((a - x)*(a - x) + (b - y)*(b - y)) Return [x, y, r] End Function |
||
Variety is the spice of life. One day ignore people, next day annoy them. |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group