**1**

# Geometry triangle problem

###
#1
Members - Reputation: **152**

Posted 10 March 2012 - 07:24 PM

The object is centered at A. B is the original camera location and D is the rotated camera location after orbiting. C is the point on the surface of the object. The original observed angle is ABC = atan( r/d). However, I can't figure out how to calculate Theta2 = angle ADC.

###
#2
Crossbones+ - Reputation: **2134**

Posted 10 March 2012 - 08:26 PM

I would approach this problem by first converting the points into a set of vectors where,

A = (0,0)

B = (-d,0)

C = (0,r)

The dot product is related to the cosine of the angle between two vectors so what I want is to calculate the dot product of the vector AD and CD. That means I need to calculate D. D is a rotation of B about A so multiplying B by the appropriate rotation matrix gives

D = (-d*cos(theta1), d*sin(theta1))

The dot product between AD and CD is,

(C - D).(A - D) = |C - D||A - D| cos(theta2)

Therefore,

theta2 = acos((C - D).(A - D)/(|C - D||A - D|)).

-Josh

--www.physicaluncertainty.com

--linkedin

--irc.freenode.net#gdnet

###
#3
Moderators - Reputation: **10712**

Posted 10 March 2012 - 09:17 PM

c^2 = a^2 + b^2 - 2ab*cos(theta)

In this case, the distance between D and C is

**a**and the distance between A and D is

**b**. The distance between A and C is

**c**. Re-arranging the above equation gets you:

cos(theta)=(a^2+b^2-c^2)/2ab

Thus, the angle ADC would be calculated as:

ADC=acos( ( (AD)^2+(CD)^2-(CA)^2 ) / 2*(AD)*(CD) )

###
#4
Members - Reputation: **152**

Posted 10 March 2012 - 09:32 PM

I was hoping to rearrange the solution in order to be able to compute the necessary value of Theta1 in order to achieve a given value of Theta2. However that is not possible via these solution methods. Do you think there is a closed form solution for the reverse problem?

###
#5
Members - Reputation: **1377**

Posted 10 March 2012 - 11:19 PM

EDIT: Ok, after looking at the problem, I think I managed to find a single "formula" that will solve everything in pretty much one step, although you should take precaution dealing with various things like diving by zero and the fact that the formula uses fairly inefficient means to calculate the angle (square roots, sin, arccos, etc). Also, do take into consideration that arccos is only defined on a certain interval, that interval being [-1, 1]. If the ratio is outside of that, then you'll run into trouble, although I think the only real cause of that is if the triangle is impossible (which I think may actually happen so do be careful).

So, the end result isn't all that straightforward either. I don't really know how to put it in fancy image form, so I'll have to convey it via good ol' textual means:

theta2 = arccos( (d - r*sin(theta1))/sqrt(r^2 + d^2 - 2*a*d*sin(theta1)) )

Also, I have not tested this on anything. I wrote a proof to make sure I wasn't doing something wrong and it all seems to be OK. Again, I don't know how to make fancy diagrams so relied on caveman technology. Here is the writing:

http://img525.imageshack.us/img525/1002/lawofcosineproof.jpg

I apologize for the handwriting

My personal links

- Khan Academy - For all your math needs

- Java API Documentation - For all your Java info needs

- C++ Standard Library Reference - For some of your C++ needs ^.^

###
#6
Moderators - Reputation: **10712**

Posted 11 March 2012 - 04:11 AM

###
#7
Members - Reputation: **1377**

Posted 11 March 2012 - 08:57 AM

My personal links

- Khan Academy - For all your math needs

- Java API Documentation - For all your Java info needs

- C++ Standard Library Reference - For some of your C++ needs ^.^