Jump to content
  • Advertisement

Archived

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

jasonf

Complex numbers <-> Real Numbers

This topic is 6934 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anyone know how to implement complex numbers in c and then change them back into real numbers when needed?

Share this post


Link to post
Share on other sites
Advertisement
Hmmm... converting complex to real... well I think I understand what you mean... here''s my 2 cents
------------------------------------------
say you had a complex number c = a + bi
you can find the magnitude
/c/ = sqrt(a^2 + b^2)
and the angle
angle = atan2(b,a)
------------------------------------------
or from angle and /c/ (the other way around)
c = /c/*cos(angle) + /c/*sin(angle)i
--------------------------------------------
one way to implement a complex number in C would be
to define a structure
typedef complexnumber
{
int a; // real part
int b; // imaginary part
} complexnumber, *complexnumber_ptr;

complexnumber myfirstcomplexno;

myfirstcomplexno.a = 10;
myfirstcomplexno.b = 3;
---------------------------------------
so the number would be c = a + bi = 10 + 3i
and write functions to convert and perform operations

Hope this helps,

Nick

"... you act as if stupidity were a virtue."
-- Flight of the Phoenix

Share this post


Link to post
Share on other sites
NickGA, ints are no good idea for a and b; they should be real.

typedef complexnumber
{
float a; // real part
float b; // imaginary part
} complexnumber, *complexnumber_ptr;

btw, ln(a+bi) = sqrt(a^2+b^2) + i*arctan(b/a)
logc+di(a+bi) = ln(a+bi)/ln(c+di)
e^(a+bi) = e^a*(cos(b) + i*sin(b))
(c+di)^(a+bi) = e^(ln(c+di)*(a+bi))
sin(a+bi) = sin(a)cosh(b) + i*cos(a)sinh(b)
cos(a+bi) = cos(a)cosh(b) - i*sin(a)sinh(b)
....
all those functions are defined in the complex numbers, but I don''t think you''ll need them *g*

Visit our homepage: www.rarebyte.de.st

GA

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!