I was wondering if anyone could help me with this little problem. What I am actually trying to do is implement 'picking' into a game I'm doing, but I'm actually stuck with some of the maths, thats why this isn't in the game forum.

I'm trying to work out a field of view for a camera. If you look at the picture below, I'm trying to work out angle x while knowing the length of sides a and b.


My brother knows a bit about maths and he said you do it like this:x = Tan-1 (b/a)

Anyone have a clue how to do this in code? I'm not familliar at all with math functions so it would be a great help.

Attachments triangle.jpg 7.1 KB

I was wondering if anyone could help me with this little problem. What I am actually trying to do is implement 'picking' into a game I'm doing, but I'm actually stuck with some of the maths, thats why this isn't in the game forum.

I'm trying to work out a field of view for a camera. If you look at the picture below, I'm trying to work out angle x while knowing the length of sides a and b.

[ATTACH]5573[/ATTACH]

My brother knows a bit about maths and he said you do it like this:

a = Tan-1 (b/a)

Anyone have a clue how to do this in code? I'm not familliar at all with math functions so it would be a great help.

Close, but not quite. The formula is this:

tan(x) = b/a

Which leads to this:

x = arctan (b/a), not this:
a = arctan (b/a)

atan or atan2 from the cmath library will probably be your best bets here:
http://www.cplusplus.com/reference/clibrary/cmath/

This article has been dead for over six months. Start a new discussion instead.