Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drawing an ellipse
#25
LOL you know those dreams you have this brilliant idea and then awake you realize the folly and say, "What was I thinking?"

I can do the ellipse without trig but I need the trig in Point rotation for tilt:
Code: (Select All)
_Title "Experiment with Ellipse" 'b+ 2023-07-04
Type xy
    As Single x, y
End Type
Screen _NewImage(800, 600, 32)
_ScreenMove 250, 60

For tilt = 0 To 360 Step .25
    Line (0, 0)-(_Width, _Height), &H05000000, BF
    drawTiltedEllipse 400, 300, 250, 150, tilt, &HFFFFFF00
    _Limit 30
Next
Sub drawTiltedEllipse (xc, yc, xRadius, yRadius, Tilt, clr~&)
    ReDim a(xRadius * 4) As xy
    r2 = xRadius * xRadius
    fit = yRadius / xRadius
    For x = xRadius To -xRadius Step -1
        y = fit * Sqr(r2 - x ^ 2)
        a(i).x = xc + x
        a(i).y = yc + y
        'PSet (a(i).x, a(i).y), clr~&
        i = i + 1
    Next
    For x = -xRadius + 1 To xRadius
        y = fit * Sqr(r2 - x ^ 2)
        a(i).x = xc + x
        a(i).y = yc - y
        'PSet (a(i).x, a(i).y), clr~&
        i = i + 1
    Next
    ReDim _Preserve a(i - 1) As xy
    Dim temp As xy
    Rotate 400, 300, a(0).x, a(0).y, Tilt, temp
    PSet (temp.x, temp.y), &HFF0000FF
    For i = LBound(a) + 1 To UBound(a)
        Rotate 400, 300, a(i).x, a(i).y, Tilt, temp
        Line -(temp.x, temp.y), &HFF0000FF
    Next
End Sub
Sub Rotate (cx, cy, x, y, degAng, a As xy)
    'cx, cy is center of rotation
    'x, y the point to rotate
    'degAng the angle in degrees to rotate
    ' output a.X, a.Y ' our point of rotation
    d = _Hypot(cx - x, cy - y) ' distance between xc and x
    ang = _Atan2(y - cy, x - cx)
    a.x = cx + d * Cos(ang + _D2R(degAng))
    a.y = cy + d * Sin(ang + _D2R(degAng))
End Sub
b = b + ...
Reply


Messages In This Thread
Drawing an ellipse - by PhilOfPerth - 07-01-2023, 08:14 AM
RE: Drawing an ellipse - by bplus - 07-01-2023, 10:04 AM
RE: Drawing an ellipse - by PhilOfPerth - 07-01-2023, 11:34 AM
RE: Drawing an ellipse - by OldMoses - 07-01-2023, 05:23 PM
RE: Drawing an ellipse - by bplus - 07-01-2023, 05:34 PM
RE: Drawing an ellipse - by PhilOfPerth - 07-01-2023, 11:26 PM
RE: Drawing an ellipse - by mnrvovrfc - 07-02-2023, 01:07 AM
RE: Drawing an ellipse - by PhilOfPerth - 07-02-2023, 01:21 AM
RE: Drawing an ellipse - by OldMoses - 07-02-2023, 02:12 AM
RE: Drawing an ellipse - by PhilOfPerth - 07-03-2023, 12:35 AM
RE: Drawing an ellipse - by mnrvovrfc - 07-03-2023, 01:40 AM
RE: Drawing an ellipse - by OldMoses - 07-03-2023, 03:52 AM
RE: Drawing an ellipse - by PhilOfPerth - 07-03-2023, 06:12 AM
RE: Drawing an ellipse - by SMcNeill - 07-03-2023, 06:16 AM
RE: Drawing an ellipse - by PhilOfPerth - 07-03-2023, 06:19 AM
RE: Drawing an ellipse - by SMcNeill - 07-03-2023, 06:24 AM
RE: Drawing an ellipse - by PhilOfPerth - 07-03-2023, 07:04 AM
RE: Drawing an ellipse - by mnrvovrfc - 07-03-2023, 06:34 AM
RE: Drawing an ellipse - by johnno56 - 07-03-2023, 07:06 AM
RE: Drawing an ellipse - by SMcNeill - 07-03-2023, 07:18 AM
RE: Drawing an ellipse - by bplus - 07-03-2023, 12:13 PM
RE: Drawing an ellipse - by OldMoses - 07-04-2023, 06:18 PM
RE: Drawing an ellipse - by bplus - 07-04-2023, 11:31 PM
RE: Drawing an ellipse - by PhilOfPerth - 07-05-2023, 01:58 AM
RE: Drawing an ellipse - by bplus - 07-05-2023, 02:28 AM
RE: Drawing an ellipse - by PhilOfPerth - 07-05-2023, 02:47 AM
RE: Drawing an ellipse - by OldMoses - 07-06-2023, 09:30 PM



Users browsing this thread: 26 Guest(s)