[Math] Calculate distance in $x,y$ from center based on distance and degrees.

circlesmetric-spaces

I'm terribly sorry if this question is written like a 5-year old..
But that's the level I'm on in terms of math and coordinate calculations.
(Just realized I don't even know what to tag this question with.. angles? metric-spaces? I'm terribly sorry if anyone feels offended by this question..)

TL;DR:

A 5:th grade formula to calculate how many moons one could squeeze around the world (not taking in account the earths size, only the width of the moon in a 2d plane) in the orbit it's currently at.

And secondly, a formula to calculate (on a coordinate based 2d plane), what new $x,y $ cordinates the moon would have if I nudged it $10$ pixels outwards at $180 $ angular degree rotation around the earth. nudge((current$x$, current$y$), $10$ px, $180$ deg)

enter image description here

Longwinded question:

I want to calculate the amount of objects I can squeeze in around a circle-path based on:

  • Distance from center
  • Object on paths width

And I also want to evolve this function or create a second one to calculate a new x,y position based on:

  • angular degrees
  • distance from center

Lets say i want to travel 5 pixels outwards from dead center 180 degrees.

enter image description here

That would give me x=0, y=-5. And so on.
This would help me plot the objects on it's path later on, I would then like to calculate how many objects with a width of 10 pixels i can fit on this path around the center.

I'm not expecting anyone to give me a straight up answer, even tho this is a hobby thing for space exploration and not a school assignment. But I'm so utterly lost I don't even know what to start googling for answers. What does one even call this type of math?

I've tried something like:

rads = math.atan2(dx/dy)
degs = math.degrees(rads)

But that assumes i know the destination positions to begin with, which i don't.
So i found and tried to adapt:

newX = middleX * cos(rotation) - middleY * sin(rotation);
newY = middleX * sin(rotation) + middleY * cos(rotation);

And this got me going, but Idon't know how to squeeze in the distance from the center in order to adapt this to give me the offset/differance between $x$ and new-$x $ so to speak.

I understand the basic concept of sin/cos and atan2, but that's about as far as I can go.

Edit:

I think I got the angle a bit down, at least if I know the position of two points in space.

a_x, a_y = 50,50
b_x, b_y = 60,60

(degrees(atan2(b_y - a_y , b_x - a_x))+180)%360

$+180$ just because the library used to plot things graphically turns things upside down I think..

Best Answer

Solved it with a lot of tinkering.

To calculate the amount of objects i can fit around a certain path.
Where distance between point A (center of circle) and point B (center of outer object) is known. I also knew the objects width i could do:

objCount = (distance*2*pi)/objWidth

This in turn had to be converted into the a actual angle, so objAngle = 360/objCount gave me this information.

To calculate the position of each individual object, I had to user that angle in junction with the distance previously used into a graph function.

new_x = PointA_x + (cos(objAngle)*distance)
new_y = PointA_y + (sin(objAngle)*distance)

I could now do a (remember i'm a programmer, don't know how to express this in math.. but):

for i in range(objectCount):
    ...

and use just take i * objAngle to get the positional angle of each object and plot them into a graph.

Basically it gives a result looking like this (one center object called earth, and two moons):

enter image description here

Now all that remains is to clean up the non-math part of this and make it pretty, with circles and place them nicely around a 360 path instead of bundle them right next to each other if there's less then maximum fitting capacity.

Edit: I will for sure google this math equation in a year or so again. So to myself in the future: here's your code:

def fit_obj_around_path(self, objWidth, distance):
    return int((distance*2*math.pi)/objWidth)

def angle_per_slize(self, numOfObjects):
    return int(360 / numOfObjects)

def radiator(self, angle):
    """ The name is perhaps wrong for this function.
        but it converts angles into radians which
        we use for sin/cos. For some reason my human
        brain likes angles better than radians, so
        we'll meet half way.."""
    return angle*(math.pi/180)

def new_xy_space(self, x, y, angle, distance):
    newX = (math.cos(self.radiator(angle))*distance)+x
    newY = (math.sin(self.radiator(angle))*distance)+y
    return (newX, newY)