Page 1 of 1

Any sneaky way to draw an elliptical arc?

Posted: Tue May 11, 2021 6:30 pm
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.

Re: Any sneaky way to draw an elliptical arc?

Posted: Tue May 11, 2021 7:21 pm
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

Re: Any sneaky way to draw an elliptical arc?

Posted: Tue May 11, 2021 8:07 pm
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!