I would like to create a function that would move one point in along a circle around another, but lack the math know how.
here's what I have cobbled together from examples elsewhere and a little help, hopefully at least my intentions are clear (the inc=increment would let me fiddle with how fast p2 travels)
point1={}
point1.x=68
point1.y=78
point2={}
point2.x=57
point2.y=43
function orbit(p1, p2, inc)
distance = sqrt((p1.x-p2.x)(p1.x-p2.x) + (p1.y-p2.y)(p1.y-p2.y))
ang= atan2(p2.y, p2.x) - atan2(p1.y, p2.x)
p2.x=(p1.x + distance cos(ang+inc))
p2.y=(p1.y + distance sin(ang+inc))
end
function _update()
orbit(point1, point2, .01)
end
function _draw()
line(point1.x, point1.y, point2.x, point2.y, 7)
end
--
-john


almost there! the angle you need (from p1 to p2) is atan2(p2.x-p1.x, p2.y-p1.y)
also note it's atan2(x,y) in pico8, instead of atan2(y,x) everywhere else.


Hey @xyxzzy I hope this is what you're looking for; your description sounded similar but my math is a lot simpler so I'm not really sure.
I did something to accomplish this here: https://www.lexaloffle.com/bbs/?tid=29405
Since that uses some magic numbers (it was my first time trying to really figure out some of this trig stuff instead of faking it), here's a better demo:
'O' (z) changes the 'mode'
If this was different what you're wanting to do, let me know.


Thanks @enargy, that's a great little demo, very polished.
I think my function does what I need it to now, thanks to @ultrabrite for the tip.
[Please log in to post a comment]