Log In  

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)



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

function _update()
orbit(point1, point2, .01)

function _draw()
line(point1.x, point1.y, point2.x, point2.y, 7)


P#41377 2017-06-08 03:13 ( Edited 2017-06-08 22:09)

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.

P#41378 2017-06-08 07:01 ( Edited 2017-06-08 11:01)

Excellent, thank you!

P#41381 2017-06-08 10:38 ( Edited 2017-06-08 14:38)

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:

Cart #41382 | 2017-06-08 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

'O' (z) changes the 'mode'

If this was different what you're wanting to do, let me know.

P#41383 2017-06-08 11:11 ( Edited 2017-06-08 15:11)

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.

P#41409 2017-06-08 18:09 ( Edited 2017-06-08 22:11)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-03-25 23:58:58 | 0.058s | Q:21