Discord
Login
Community
DARK THEME

Help with Trig

Why is the center of the satellite displaced when coordinates 0, 0? Even noticeably when the line is compressed and increased. You can see the offset if you delete screen.clear()

And why does it spin counterclockwise when it’s rot +=1 ?

init = function()
rot = 0
end

update = function()
rot += 0.05
X = 0 + 16 - 8 + 75 * cos(rot)
Y = 0 + 16 - 8 + 75 * sin(rot)

if not keyboard.SPACE then
screen.clear()
end

end

draw = function()
screen.drawText("Press space to check",-75,75,8,"rgb(255,255,255)")
screen.fillRound(center.x,center.y,8,8,"rgb(255,0,85)")
screen.fillRound(X,Y,8,8,"rgb(85,255,142)")
screen.drawLine(center.x,center.y,X,Y,"rgb(0,85,255)")
end

center = object
x = 0
y = 0
end

:embed https://microstudio.io/Stilton/trig/KTZRA6V7/

Hi there :)

The satellite is offset as a result of your X/Y calculations.
The 0 + 16 - 8 part always results in 8 what you add to the 75*... part.
So the virtual center of the satellite is always shifted by X+8 and Y+8.

About the rotation, that is fixed if you swap sine and cosine.

update = function()
rot += 0.05
// X = 0 + 16 - 8 + 75 * cos(rot)
// Y = 0 + 16 - 8 + 75 * sin(rot)
X = 75 * sin(rot)
Y = 75 * cos(rot)

Live Long and Tinker ;)

P.S. if the intend was to create an elliptical path for your satellite you have to force the order of calculations by using brackets. Remember, multiplication is done first in this case :)

X = (8+75) * sin(rot)   // x-radius
Y = 75 * cos(rot)

Thank you so much for your help!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community