Drawing an ellipse
#13
(07-03-2023, 03:52 AM)OldMoses Wrote: If I understand correctly, is this the sort of thing you're looking for? It now subjects each point to a transformation matrix operation. That's somewhat more trig work than before. Now it creates the plot (x, y) relative to a (0, 0) origin, performs the rotation (in radians), and THEN centers it in the screen after it's properly plotted and rotated. If you prefer degrees then just; rotate! = _D2R(degrees)

Code: (Select All)
'de La Hire's method of ellipse
'geometric construction of two concentric circles
'the outermost diameter equals the desired ellipse's
'semi major axis, while the inner circle matches the
'semi minor axis.
'a full 360ø rotation is executed and the positions
'are plotted using a COS function of the outer circle's
'resulting X position and SIN function of the inner
'circle's Y position.

SCREEN _NEWIMAGE(1024, 512, 32)
cen_x% = 512 '                             screen center x
cen_y% = 256 '                             screen center y
semi_maj% = 200 '                          Semi major axis of ellipse i.e. outer circle
semi_min% = 105 '                          Semi minor axis of ellipse i.e. inner circle
rotate! = .75 '                            radian rotation of ellipse

cursx% = semi_maj% * COS(rotate!)
cursy% = semi_maj% * SIN(rotate!)
PSET (cursx% + cen_x%, cursy% + cen_y%) '  pre-position graphics cursor

FOR ang = 0 TO 2 * _PI STEP .01 '          granularity of 1/100 radian
    x% = semi_maj% * COS(ang) '            x position a COS function of the outer circle
    y% = semi_min% * SIN(ang) '            y position a SIN function of the inner circle
    xr% = x% * COS(rotate!) - y% * SIN(rotate!) + cen_x%
    yr% = x% * SIN(rotate!) + y% * COS(rotate!) + cen_y%
    LINE STEP(0, 0)-(xr%, yr%) '           line from previous cursor position
NEXT ang

Beautiful! Thank you; I was able to rotate by adding a couple of lines, giving this:
(the color lines make it blink occasionally, I don't know why yet).
Code: (Select All)
Screen _NewImage(1024, 512, 32)
cen_x% = 512 '                             screen center x
cen_y% = 256 '                             screen center y
semi_maj% = 200 '                          Semi major axis of ellipse i.e. outer circle
semi_min% = 105 '                          Semi minor axis of ellipse i.e. inner circle
Do
    For rotate = 0 To 2* _pi Step .1 '                            radian rotation of ellipse now increases from 0 to 6
        Cls
        cursx% = semi_maj% * Cos(rotate!)
        cursy% = semi_maj% * Sin(rotate!)
        PSet (cursx% + cen_x%, cursy% + cen_y%) '  pre-position graphics cursor

        For ang = 0 To 2 * _Pi Step .01 '          granularity of 1/100 radian
            x% = semi_maj% * Cos(ang) '            x position a COS function of the outer circle
            y% = semi_min% * Sin(ang) '            y position a SIN function of the inner circle
            xr% = x% * Cos(rotate!) - y% * Sin(rotate!) + cen_x%
            yr% = x% * Sin(rotate!) + y% * Cos(rotate!) + cen_y%
            Line Step(0, 0)-(xr%, yr%) '           line from previous cursor position
        Next ang
        Color _RGB(255, 0, 255)
        Paint (512, 256)
        _Delay .1 '                                                                                       allows view of each iteration
    Next rotate
Loop
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
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: 8 Guest(s)