aargh! What am I doing wrong?

Started by
8 comments, last by Hybrid 20 years, 11 months ago
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.
Advertisement
yes
Actually, the equation I get is...

k = tan^-1 (max_angle / 2);

oops, I messed up the multiply/divide by 2 bit... but it''s still not working as expected.
k = arctan(max_angle / 2)
atan(max_angle / 2)
Uhh, if Y = 2tan(X), wouldn't X = tan-1(Y/2)?

[edited by - zealouselixir on May 3, 2003 7:32:55 PM]

[twitter]warrenm[/twitter]

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.

[twitter]warrenm[/twitter]

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.
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
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)

Eleventy

This topic is closed to new replies.

Advertisement