Lua 如何";轮换;椭圆?

Lua 如何";轮换;椭圆?,lua,ellipse,love2d,Lua,Ellipse,Love2d,使用此选项: local W, H = 100, 50 function love.draw() love.graphics.translate(love.graphics.getWidth()/2,love.graphics.getHeight()/2) for i = 1, 360 do local I = math.rad(i) local x,y = math.cos(I)*W, math.sin(I)*H love.graphics.line(0, 0

使用此选项:

local W, H = 100, 50

function love.draw()
  love.graphics.translate(love.graphics.getWidth()/2,love.graphics.getHeight()/2)
  for i = 1, 360 do
    local I = math.rad(i)
    local x,y = math.cos(I)*W, math.sin(I)*H
    love.graphics.line(0, 0, x, y)
  end
end

我可以将一条线连接到椭圆的中心(长度
W
和高度
H
)和边缘。如何使用参数
R
围绕椭圆中心“旋转”椭圆?我知道你可以用
love.graphics.ellipse
love.graphics.rotate
来计算旋转椭圆上点的坐标吗?

这是一个三角学问题,下面是基本的二维旋转的工作原理。假设一个点位于(x,y)。如果要将该点围绕原点(在您的示例中为0,0)旋转角度θ,则使用以下变换将新点的坐标定位在(x1,y1)处

x1=xcosθ− 赖氨酸θ
y1=ycosθ+xsinθ

在您的示例中,我在旋转后添加了一个新的椭圆

function love.draw()
    love.graphics.translate(love.graphics.getWidth()/2,love.graphics.getHeight()/2)
    for i = 1, 360, 5 do
        local I = math.rad(i)
        local x,y = math.cos(I)*W, math.sin(I)*H
        love.graphics.setColor(0xff, 0, 0) -- red
        love.graphics.line(0, 0, x, y)
    end

  -- rotate by angle r = 90 degree
    local r = math.rad(90)
    for i = 1, 360, 5 do
        local I  = math.rad(i)
        -- original coordinates
        local x  = math.cos(I) * W 
        local y  = math.sin(I) * H
        -- transform coordinates
        local x1 = x * math.cos(r) - y * math.sin(r) 
        local y1 = y * math.cos(r) + x * math.sin(r) 
        love.graphics.setColor(0, 0, 0xff) -- blue
        love.graphics.line(0, 0, x1, y1)
    end
end