Circular Motion [SOLVED]

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Palmar
Prole
Posts: 23
Joined: Thu Dec 13, 2012 3:54 pm

Circular Motion [SOLVED]

Post by Palmar »

Hi everyone!
How to implement circular motion? I really don't know, how to did this on coordinate system.
Thanks in advance.
Last edited by Palmar on Sat Feb 23, 2013 1:32 pm, edited 1 time in total.
User avatar
pakoskyfrog
Citizen
Posts: 62
Joined: Mon Feb 04, 2013 12:54 pm
Location: France

Re: Circular Motion

Post by pakoskyfrog »

Hi !

Depending on what you intend to do, you can use a polar system and convert it in rectangular system :

You can place a point thanks to 2 coordinates, either an angle and a length, or two lengths.
ie : radius and theta or x and y.

Then you make all your calculations with (radius, theta) and convert them with
x = radius * cos(theta)
y = radius * sin(theta)

with a constant radius and a angle theta increasing in time, you will have a circular (anti clockwise) motion !
But since y coords are going down, everything filps horizontally, and the motion should go clockwise.

Code: Select all

local point_r = 20 -- pxl radius
local point_t = 0  -- start angle
function love.update(dt) 
    point_t = point_t + dt -- one radian per second
end
function love.draw()
    local ox = 150 -- center
    local oy = 200
    local x = point_r * math.cos(point_t) + ox
    local y = point_r * math.sin(point_t) + oy
    love.graphics.point(x,y)
end
Palmar
Prole
Posts: 23
Joined: Thu Dec 13, 2012 3:54 pm

Re: Circular Motion

Post by Palmar »

pakoskyfrog wrote:Hi !

Depending on what you intend to do, you can use a polar system and convert it in rectangular system :

You can place a point thanks to 2 coordinates, either an angle and a length, or two lengths.
ie : radius and theta or x and y.

Then you make all your calculations with (radius, theta) and convert them with
x = radius * cos(theta)
y = radius * sin(theta)

with a constant radius and a angle theta increasing in time, you will have a circular (anti clockwise) motion !
But since y coords are going down, everything filps horizontally, and the motion should go clockwise.

Code: Select all

local point_r = 20 -- pxl radius
local point_t = 0  -- start angle
function love.update(dt) 
    point_t = point_t + dt -- one radian per second
end
function love.draw()
    local ox = 150 -- center
    local oy = 200
    local x = point_r * math.cos(point_t) + ox
    local y = point_r * math.sin(point_t) + oy
    love.graphics.point(x,y)
end
Thanks, man, you helped me so much.
Hacdan
Prole
Posts: 1
Joined: Thu Nov 02, 2017 10:11 pm

Re: Circular Motion [SOLVED]

Post by Hacdan »

Hello, how can i change the point style in the version 0.10 of LOVE2D?
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests