Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Central equation of the ellipse
#1
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.


Reply
#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
#3
Hey, Czech Pete's back!

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

Pete Smile
Reply




Users browsing this thread: 1 Guest(s)