Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ellipse trouble
#4
my weak ellipse drawing for you if you don't want to use circle.  My pset method is missing something because I do not recall the math in that area where sqr() can't be called. Bplus is better here. The method using draw actually comes out decent enough.

Code: (Select All)
'badellipse
Screen _NewImage(800, 600, 256)
'pset ellipse
ex = 200
ey = 300
a = 160
b = 50
For y = 0 To 100 Step 0.2
    n = (1 - y ^ 2 / b ^ 2) * a ^ 2 'have to calculate outside sqr() to avoid math error
    If n > 0 Then
        x = Sqr(n)
        PSet (x + ex, y + ey), 15
        PSet (ex - x, y + ey), 15
        PSet (ex - x, ey - y), 15
        PSet (x + ex, ey - y), 15
    End If
Next y


'draw ellipse
ex = 600
ey = 300
a = 160
b = 50
Draw "bm" + Str$(ex) + "," + Str$(ey)
For y = 0 To 100 Step 1 'using larger steps than earlier because draw is slower but laying down line segments
    n = (1 - y ^ 2 / b ^ 2) * a ^ 2
    If n > 0 Then
        x = Sqr(n)
        If y < 1 Then Draw "bm" + Str$(x + ex) + "," + Str$(y + ey)
        Draw "m" + Str$(x + ex) + "," + Str$(y + ey)
    End If
Next y
For y = 100 To 0 Step -1
    n = (1 - y ^ 2 / b ^ 2) * a ^ 2
    If n > 0 Then
        x = Sqr(n)
        If y > 99 Then Draw "bm" + Str$(x + ex) + "," + Str$(y + ey)
        Draw "m" + Str$(ex - x) + "," + Str$(y + ey)
    End If
Next y
For y = 0 To 100 Step 1
    n = (1 - y ^ 2 / b ^ 2) * a ^ 2
    If n > 0 Then
        x = Sqr(n)
        If y < 0 Then Draw "bm" + Str$(x + ex) + "," + Str$(y + ey)
        Draw "m" + Str$(ex - x) + "," + Str$(ey - y)
    End If
Next y
For y = 100 To 0 Step -1
    n = (1 - y ^ 2 / b ^ 2) * a ^ 2
    If n > 0 Then
        x = Sqr(n)
        If y > 99 Then Draw "bm" + Str$(x + ex) + "," + Str$(y + ey)
        Draw "m" + Str$(x + ex) + "," + Str$(ey - y)
    End If
Next y
Reply


Messages In This Thread
Ellipse trouble - by james2464 - 08-23-2022, 03:29 PM
RE: Ellipse trouble - by dcromley - 08-23-2022, 04:07 PM
RE: Ellipse trouble - by james2464 - 08-23-2022, 06:37 PM
RE: Ellipse trouble - by bplus - 08-23-2022, 04:54 PM
RE: Ellipse trouble - by james2464 - 08-23-2022, 06:43 PM
RE: Ellipse trouble - by James D Jarvis - 08-23-2022, 05:37 PM
RE: Ellipse trouble - by james2464 - 08-23-2022, 06:48 PM
RE: Ellipse trouble - by bplus - 08-23-2022, 08:51 PM
RE: Ellipse trouble - by james2464 - 08-23-2022, 11:33 PM
RE: Ellipse trouble - by Pete - 08-24-2022, 12:47 AM
RE: Ellipse trouble - by james2464 - 08-24-2022, 01:59 PM
RE: Ellipse trouble - by Pete - 08-25-2022, 02:23 AM
RE: Ellipse trouble - by james2464 - 08-25-2022, 11:38 AM
RE: Ellipse trouble - by Pete - 08-25-2022, 08:58 PM
RE: Ellipse trouble - by james2464 - 08-25-2022, 10:52 PM



Users browsing this thread: 12 Guest(s)