Any sneaky way to draw an elliptical arc?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
JJSax
Prole
Posts: 47
Joined: Fri Apr 04, 2014 3:59 am

Any sneaky way to draw an elliptical arc?

Post by JJSax »

I am trying to challenge myself to make a circle/ellipse be a series of arcs so it doesn't draw anything outside of an area. (like the screen for example) I'm noticing that the love.graphics.arc doesn't have an x/y radius option.

I could probably use a stencil, but that probably wouldn't help it be faster, possibly slower.
I could also make my own. But I'm curious if there is something that I'm missing that could make this easier.
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: Any sneaky way to draw an elliptical arc?

Post by pgimeno »

The obvious answer is to use trigonometry, but note that angles get deformed and don't work as one expects.

Code: Select all

function ellipticArc(x, y, rx, ry, angle1, angle2, segments)
  local points = {}
  local range = angle2 - angle1
  for i = 0, segments do
    local angle = angle1 + range * (i / segments)
    points[i + i + 1] = cos(angle) * rx + x
    points[i + i + 2] = sin(angle) * ry + y
  end
  love.graphics.line(points)
end
JJSax
Prole
Posts: 47
Joined: Fri Apr 04, 2014 3:59 am

Re: Any sneaky way to draw an elliptical arc?

Post by JJSax »

pgimeno wrote: Tue May 11, 2021 7:21 pm The obvious answer is to use trigonometry, but note that angles get deformed and don't work as one expects.
That's fair. I just didn't know if there was anything pre-built in Love2d that I could use. Thanks for the help!
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests