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

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)
1

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 ▽ | License: CC4-BY-NC-SA
1

'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)