Archived

This topic is now archived and is closed to further replies.

Hybrid

aargh! What am I doing wrong?

Recommended Posts

This is the equation I have... I need to rearrange it so I just have k = .... max_angle = tan(k)*2; Am I missing something stupid, because I get... k = tan^-1 (max_angle * 2); where tan^-1 is the inverse. It doesn''t seem to be working as I expected in my program, and figured this simple thing must be the problem. perhaps I am calculating the inverse tan wrong in C... Am I right in thinking inverse tan is atan in the math.h library? Maybe I''m right and the answer lies somewhere else. ugh! Thanks for any help.

Share this post


Link to post
Share on other sites
quote:
Original post by Hybrid
oops, I messed up the multiply/divide by 2 bit... but it''s still not working as expected.


In that case, perhaps you''d like to share with us what exactly you''re trying to do. We''re assuming for your sake that you''re converting to radians if your k is in degrees here.

Share this post


Link to post
Share on other sites
Why is the variable called max_angle? You shouldn''t get an angle out of a tangent function. It should be the triangle height/width. Also, the arctan function will probably only return an angle between -pi/2 and +pi/2, so depending on what you are doing, you may have to adjust the value.

Share this post


Link to post
Share on other sites
Thanks for the replies. Yeah, I am converting to radians...

This is for a cone particle emitter. It uses some code I found on the net. ''k'' determines the spread of the cone (the angle, though its more of a coefficient than an angle), and that max_angle = tan(k) * 2 gives you the maximum cone angle given a k value, and I''m trying to work out the k value need to set the max_angle to what I want. So I can define my cone emitter using an angle rather than some k value which makes no sense when looking at it.

You''ll find the maths on this page... with the max_angle =... if you scroll down a bit...

http://www.hut.fi/~vhelin/particles.txt

Thanks

Share this post


Link to post
Share on other sites
In C++, if you want angle k to be in degrees when you solve for it, this would be the equation to use (assuming max_angle is also in degrees):


k = atan( (max_angle / 2) * (pi/180.0f) );


If you want k in radians (assuming max_angle is in radians):

k = atan( max_angle / 2);


The function atan() obtains the arctan of a given angle (in radians), which is equivalent to tan^(-1).

If you want a more accurate result, use atanf() instead.

NOTE: pi = 3.14159265358979 (double)

Share this post


Link to post
Share on other sites