# Math Help - Position of an observer of a square

1. ## Position of an observer of a square

Hi all,
during some hobby research I encountered a geometrical problem I can't solve for my knowledge. I hope you can give me some help:

I have a square which I know the edge length (1); then I have a point, outside of it, and segments that connect it to each square's vertex. I know the angles between each segment and the next.
I need to know the length of at least two segments, and/or the coordinates of the observer if we place all them in a Cartesian plane.

This is needed for me for a sort of "perspective identification": i need to know the observer's orientation (yaw/pitch/roll) and distance w.r.t. to the reference square. Only when the above problem is solved, I think I can easily adapt it into 3D. But if you have good solution for this "bigger" problem too, feel free to inform me

Many many many thanks!!! and greetings from Italy!

Enrico

2. Originally Posted by ris8_allo_zen0
Hi all,
during some hobby research I encountered a geometrical problem I can't solve for my knowledge. I hope you can give me some help:

I have a square which I know the edge length (1); then I have a point, outside of it, and segments that connect it to each square's vertex. I know the angles between each segment and the next.
I need to know the length of at least two segments, and/or the coordinates of the observer if we place all them in a Cartesian plane.

This is needed for me for a sort of "perspective identification": i need to know the observer's orientation (yaw/pitch/roll) and distance w.r.t. to the reference square. Only when the above problem is solved, I think I can easily adapt it into 3D. But if you have good solution for this "bigger" problem too, feel free to inform me

Many many many thanks!!! and greetings from Italy!

Enrico
Do you know the coordinates of the point outside of the square?

3. Originally Posted by ris8_allo_zen0
Hi all,
during some hobby research I encountered a geometrical problem I can't solve for my knowledge. I hope you can give me some help:

I have a square which I know the edge length (1); then I have a point, outside of it, and segments that connect it to each square's vertex. I know the angles between each segment and the next.
I need to know the length of at least two segments, and/or the coordinates of the observer if we place all them in a Cartesian plane.

This is needed for me for a sort of "perspective identification": i need to know the observer's orientation (yaw/pitch/roll) and distance w.r.t. to the reference square. Only when the above problem is solved, I think I can easily adapt it into 3D. But if you have good solution for this "bigger" problem too, feel free to inform me

Many many many thanks!!! and greetings from Italy!

Enrico
If you don't know the coordinates of the point outside of the square, then one solution is to draw the four different triangles formed by two segments and a side of the square. In each triangle you know the length of a side (edge length of square = 1) and the angle between the two unknown sides (the angle between two segments). You can then use the cosine rule to write down four equations, each equation will have the length of two segments in it.

Four equations (cosine rule applied to each triangle) and four unknowns (four segments). Solve simultaneously.

4. Originally Posted by mr fantastic
If you don't know the coordinates of the point outside of the square, then one solution is to draw the four different triangles formed by two segments and a side of the square. In each triangle you know the length of a side (edge length of square = 1) and the angle between the two unknown sides (the angle between two segments). You can then use the cosine rule to write down four equations, each equation will have the length of two segments in it.

Four equations (cosine rule applied to each triangle) and four unknowns (four segments). Solve simultaneously.
Thank you for the help. Do you think the same would be done with a "half-square" triangle? (e.g. two edges and the diagonal, and just three unknown segments)

Enrico

5. Originally Posted by ris8_allo_zen0
Thank you for the help. Do you think the same would be done with a "half-square" triangle? (e.g. two edges and the diagonal, and just three unknown segments)

Enrico
Yes. But first use Pythagoras' Theorem on the triangle to get its hypotenuse. Now lengths of all sides of the triangle are known and you can use the method previously outlined.

6. So I have a system of three quadratic equations. Let's say c1, c2, c3 are the cosines of my known angles, and x,y,z the unknown length of segments.
It looks like this:
x^2+y^2+2*x*y*c1=1
z^2+y^2+2*z*y*c2=1
x^2+z^2+2*x*z*c3=2

Is that right? If so, the problem is now how to solve systems of quadratic equations. Which is the best method? I tried with substitution but I get square roots into square roots so I don't think it's the right way. The other methods I know are valid only for linear systems, not quadratic... any clue?

Thanks again!

7. Originally Posted by ris8_allo_zen0
So I have a system of three quadratic equations. Let's say c1, c2, c3 are the cosines of my known angles, and x,y,z the unknown length of segments.
It looks like this:
x^2+y^2+2*x*y*c1=1
z^2+y^2+2*z*y*c2=1
x^2+z^2+2*x*z*c3=2

Is that right? If so, the problem is now how to solve systems of quadratic equations. Which is the best method? I tried with substitution but I get square roots into square roots so I don't think it's the right way. The other methods I know are valid only for linear systems, not quadratic... any clue?

Thanks again!
I haven't checked the equations, but I wasn't expecting thay you'd want exact solutions - approximate solutions using a numerical method are good enough?

8. Originally Posted by mr fantastic
I haven't checked the equations, but I wasn't expecting thay you'd want exact solutions - approximate solutions using a numerical method are good enough?
I know very little about numerical solving, so I didn't even thought about such a method. An approximate solution is OK for me, but i have some time constraints - the output should be updated at least 50 times at second in a Core 2 processor using Python.

9. Ok, I think I'm on the right way now.

Let's call $\alpha_1$ the angle between x and y, and $\alpha_2$ the one between y and z.
x and z join the "external" corners with the observer, and y joins the one which is farthest from the obs. Thus, y is between the two and is shared between $\alpha_1$ and $\alpha_2$.
$\gamma_1$ and $\gamma_2$ are the angles opposite to x and z, respectively. Since we're working on a half-square, their sum is $\frac{\pi}{2}$.

These are the calculations to be done, exploting theorems of sines and cosines:
$\gamma_1=\arcsin(x \sin(\alpha_1))$
$y=\sqrt{x^2+1-2x \cos(\pi-\alpha_1-\gamma_1)}$
$\gamma_2=\frac{\pi}{2}-\gamma_1$
$z=\sqrt{y^2+1-2y \cos(\gamma_2)}$
$\alpha_2=\arcsin \left( \frac{\sin \left( \gamma_2 \right) }{z} \right)$

(am I correct until here?)

So the the computer's mission is to find an x value such as the calculated $\alpha_2$ is near enough to the given $\alpha_2$. This can be done in a way I'll investigate soon

Thanks mr fantastic to pointing me to the right direction!!!