# How to get the exact position of the element based on 2 dynamic angles?

I have an object that can rotate 360deg. Attached to that object I have a second object that can spin ±30deg. I want to find the top outer position of the small object.

Based on the following example, I am trying to define a formula:

• Base object angle: 0
• Small object starting angle: -90 ( or 270 )

Based on these angles the right position will be:

• x: 0
• y: 10

Another example:

• Base object angle: 0
• Small object starting angle: -90 ( or 270 ) + 30

Based on these angles the right position will be:

• x: 20
• y: 8.66

Based on the examples that I gave I found the following formula which works perfectly:

• x = cos(angles_sum) * 40
• y = sin(angles_sum) * 10

But this actually only works when the base angle is 0 / 180.

I'm really stuck with this one :(

Edit: I'm adding an image to explain even more

• base object: green
• small attached object: blue
• angles & distances: red

Again. I need to find the position of the exterior point of the small blue object, considering that the height of the blue object is 10 and it can spin 30deg in each direction. • Are $x$ and $y$ the positions of the end of the blue object? Is the coordinate system centred at the center of the green object? Mar 31, 2020 at 22:00
• Yes, you got that right. I need to find the position of the end of that blue object. The coordinate system is quite flexible. I can calculate from the beginning of blue object. Mar 31, 2020 at 22:02
• Okay I'll try to answer. Mar 31, 2020 at 22:03
• If the blue rectangle is only 10 units long, then if it is rotated by 30 degrees it will only go 5 units each way, not 20. Mar 31, 2020 at 22:11
• True! Let's go with that Mar 31, 2020 at 22:19

The problem can be rephrased in terms of vector addition.

We have two vectors we need to add:

• The vector from centre of the green square to the base of the blue rectangle
• The vector from the base of the blue rectangle to the tip of it

Let's call the angle of rotation of the square $$\alpha$$ and that of the little square $$\beta$$. Moreover, the radius of the big rectangle can be $$a$$, and the length of the little rectangle can be $$b$$.

Since we're measuring against the y-axis and not the x-axis, the second vector has a horizontal component ($$x$$) of $$b\sin{\beta}$$ and a vertical component ($$y$$) of $$b\cos{\beta}$$.

Likewise, the horizontal component the first vector is is $$a\sin{\alpha}$$ and the vertical component is $$a\cos{\alpha}$$.

All we need to do to find the sum of these, is add the horizontal components, and add the vertical components:

So the resultant horizontal component is $$b\sin{\beta} + a\sin{\alpha}$$ and the vertical component is $$b\cos{\beta} + a\cos{\alpha}$$.