I need help creating a function that draws 2D curves. This is all I have so far. It only finds the center sometimes when you move the 2nd point. Maybe I should just restart...
Graphics 800,600,32,2
SetBuffer BackBuffer()
x1=100
y1=100
x2=200
y2=500
x3=300
y3=100
While Not KeyDown(1)
Color 255,255,255
Rect x1,y1,3,3
Rect x2,y2,3,3
Rect x3,y3,3,3
Select togglepoint
Case 0
Text 0,0,"No Point Selected"
Case 1
x1 = MouseX()
y1 = MouseY()
Case 2
Text 0,0,"No Point Selected"
Case 3
x2 = MouseX()
y2 = MouseY()
Case 4
Text 0,0,"No Point Selected"
Case 5
x3 = MouseX()
y3 = MouseY()
Case 6
togglepoint = 0
End Select
If MouseHit(3) Then togglepoint = togglepoint + 1
DrawMidPoint(x1,y1,x2,y2,x3,y3)
Flip
Cls
Wend
Function DrawMidPoint(x1,y1,x2,y2,x3,y3)
sp1 = -((y2-y1)/(x2-x1)) DebugLog sp1
sp2 = -((y3-y2)/(x3-x2)) DebugLog sp2
midx1 = (x1+x2)/2 DebugLog midx1
midy1 = (y1+y2)/2 DebugLog midy1
midx2 = (x3+x2)/2 DebugLog midx2
midy2 = (y3+y2)/2 DebugLog midy2
b1 = -sp1*midx1+midy1 DebugLog b1
b2 = -sp2*midx2+midy2 DebugLog b2
h = (b1+b2)/(sp1-sp2) DebugLog h
k = sp1*x4+b1 DebugLog k
radius = Sqr((h-midx1)^2+(k-midy1)^2) DebugLog radius
Color 255,0,0
Rect h,k,3,3
End Function
|