Math question???

Hi All,

I am trying to figure out how many objects can be seen by my camera. From a previous email that I sent out yesterday, a couple of you have pointed me at tutorials on frustum culling (Thank you).

I am still having problems with the math though and I was wondering if someone would help.

What I know:

Given A and B, I can use atan(B/A) to find the angle in radians.
Given C, and the angle, I can find A with (C * cos(angle)) and I can find B with (C * sin(angle)).

what I don’t know is:
Given A, and the angle in radians, How do I find B, and C.

Ex. A = 10, angle in radians = .698132 (through trial and error, I figure out that B = appox. 8.5)

I know C = sqrt( sqr(A) + sqr(B)).

Thanks a lot for any replies,
jpummill

P.S. Sorry for being so long winded… err, long handed

what is A, B and C? is it a right triangle? and where is the angle? between A and C or B and C or is it elsewhere?

http://www.gametutorials.com/Tutorials/OpenGL/OpenGL_Pg4.htm

good frustum culling tutorial with source code (source is only in c or c++ (nearly the same), but well documented)

I don’t remember the proper math terms but A would be a line on the X axis. B is perpendicular to A so it is on the Y axis. So A, and B form a right triangle.

I know A=10, and the angle is 40 degrees between A and C.

I want to find the length of B.

Any suggestions are very appreciated,
jpummill

Also, satan (I’m assuming not the one and only), I appreciate the responses you have given to both this and my previous emails. I did look up frustum culling on the web and in the Red Book. Found a lot of useful information but not an example that matched exactly what I was trying to do (I probably just didn’t understand it correctly.)

I will check out the examples on gametutorials.com and see if they can explain it in simple enough terms that I can understand it (as I am still relearning all the math that I slept through in high school and college).

[This message has been edited by jpummill (edited 04-08-2002).]

I’m assuming you’re talking about the edges of a triangle when you say A, B and C (given the formula CC = AA + B*B you are talking about a right triangle).

c
|
|
±-
a b
triangle abc, angles alpha (=PI/2), beta, gamma, edges ab, ac, bc

IIRC some goniometric formula’s are (PI some well known constant somewhere in the neighbourhood of 3.14 ):

sin(beta) = ac/bc
cos(beta) = ab/bc
tan(beta) = ac/ab --> beta=atan(ac/ab)
sin(gamma) = ab/bc
cos(gamma) = ac/bc
tan(gamma) = ab/ac --> gamma=atan(ab/ac)
alpha + beta + gamma = PI

BTW, I’m not sure how this helps you determining how many objects are visible to your camera…

HTH

Jean-Marc

How are your objects stored internally? I assume you are storing an origin, and the vertices are relative to that. You can do a simple (not precise) test to see if an object is on screen by perspective projecting the origin and testing if its on screen. To perspective project a point in 3d space, you first translate and rotate it relative to the viewpoint, then divide the x and y coordinates by the z coordinate, multiply those values by your field of view, and add half of the screen width to the x component and half of the height to the y component. It sounds complicated, but it’s actually very simple. Look up 3d perspective projection on the internet, or open up a good textbook on 3d graphics. Once you have the origin perspective projected, just see if its within the boundaries of your viewport( i.e. x < 800 && x > 0, y<600 && y>0).

>>BTW, I’m not sure how this helps you determining how many objects are visible to your camera…

What I am really trying to do is draw lines and functions that “grow” across the screen on a frame by frame basis (ie. I don’t want the full line to instantly apear, I want it to take a second or two to grow to its full length.)
Based on the camera position, FOV, and size of my window, I want to figure out how to start the line just off screen so I don’t waste time looping to draw the pieces that are not seen.

By the way, thanks again to everyone for helping with this little problem. I have still not found exactly what I am looking for but with the leads you have given, I am sure I will soon.

jpummill

I have found the basic formula that I needed from the post by JML. Here is is if anyone is interested.

To find the length of a line oposite an angle: