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

38 Views Asked by At

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.

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

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}$.