QB64 Phoenix Edition
Central equation of the ellipse - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Prolific Programmers (https://qb64phoenix.com/forum/forumdisplay.php?fid=26)
+---- Forum: Petr (https://qb64phoenix.com/forum/forumdisplay.php?fid=52)
+---- Thread: Central equation of the ellipse (/showthread.php?tid=2529)



Central equation of the ellipse - Petr - 03-19-2024

Code: (Select All)


Screen _NewImage(1000, 1000, 32)

cx = 500 'center x and center y
cy = 500

m = 200 'X radius
n = 100 'y radius

Dim col As _Unsigned Long

For oy = 250 To 750 'ox, oy points in rectangle. If the point is part of an ellipse, it will be white, otherwise it will be black
    For ox = 250 To 750
        aa = ((ox - cx) ^ 2) / m ^ 2
        bb = ((oy - cy) ^ 2) / n ^ 2
        If aa + bb < 1 Then col = _RGB32(255) Else col = _RGB32(0)
        PSet (ox, oy), col
    Next
Next


I often use point detection in a circle, this can easily be modified to detect a point in an ellipse. Maybe it will be useful for someone.


RE: Central equation of the ellipse - TerryRitchie - 03-19-2024

(03-19-2024, 09:10 PM)Petr Wrote:
Code: (Select All)


Screen _NewImage(1000, 1000, 32)

cx = 500 'center x and center y
cy = 500

m = 200 'X radius
n = 100 'y radius

Dim col As _Unsigned Long

For oy = 250 To 750 'ox, oy points in rectangle. If the point is part of an ellipse, it will be white, otherwise it will be black
    For ox = 250 To 750
        aa = ((ox - cx) ^ 2) / m ^ 2
        bb = ((oy - cy) ^ 2) / n ^ 2
        If aa + bb < 1 Then col = _RGB32(255) Else col = _RGB32(0)
        PSet (ox, oy), col
    Next
Next


I often use point detection in a circle, this can easily be modified to detect a point in an ellipse. Maybe it will be useful for someone.
Very cool and simple. Thank you.


RE: Central equation of the ellipse - Pete - 03-20-2024

Hey, Czech Pete's back!

I was on "walkabout" for about a year, myself. Good to hear from you again.

Pete Smile