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.

what do you want exactly to find a relationship for x:
if you so

x = tan-1(b/a)

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/

cheers man, great help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.