Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Central equation of the ellipse
#2
(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.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


Messages In This Thread
Central equation of the ellipse - by Petr - 03-19-2024, 09:10 PM
RE: Central equation of the ellipse - by TerryRitchie - 03-19-2024, 10:13 PM
RE: Central equation of the ellipse - by Pete - 03-20-2024, 03:14 AM



Users browsing this thread: 1 Guest(s)