Aktuelle Zeit: 05.05.2024, 12:46

Alle Zeiten sind UTC + 1 Stunde




Ein neues Thema erstellen Auf das Thema antworten  [ 4 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: Komplexe Zahlen [C++]
BeitragVerfasst: 21.08.2007, 16:45 
Offline

Registriert: 08.04.2007, 16:55
Beiträge: 115
Hey, hab grade mal Lust bekommen, nen paar Fraktale zu proggen, und da fing ich mal mit ner Klasse complex number an ;) Und weil das sonnst nur auf eminrer Festplatte vergammelt, stell ich die mal hier rein :lol:
Code:
#include <iostream>
#include <math.h>
class complex
{
      public:
             double r;
             double i;
             
             complex(){i=0;r=0;}
             complex(double R,double I){i=I;r=R;}
             ~complex(){}
             
             complex operator+(complex other)
                     {
                     complex result;
                     result.r=other.r+r;
                     result.i=other.i+i;
                     return(result);
                     }
             
             complex operator-(complex other)
                     {
                     complex result;
                     result.r=other.r-r;
                     result.i=other.i-i;
                     return(result);
                     }
                     
             complex operator*(complex other)
                     {
                     complex result;
                     result.r=r*other.r-i*other.i;
                     result.i=i*other.r+r*other.i;
                     return(result);
                     }
                     
             complex operator/(complex other)
                     {
                     complex result;
                     result.r=(r*other.r+i*other.i)/(other.r*other.r+other.i*other.i);
                     result.i=(i*other.r-r*other.i)/(other.r*other.r+other.i*other.i);
                     return(result);
                     }
             
             complex operator+=(complex other)
                     {

                     r+=other.r;
                     i+=other.i;
                     return((*this));
                     }
             
             complex operator-=(complex other)
                     {
                     r-=other.r;
                     i-=other.i;
                     return((*this));
                     }
                     
             complex operator*=(complex other)
                     {
                     complex result;
                     result.r=r*other.r-i*other.i;
                     result.i=i*other.r+r*other.i;
                     r=result.r;
                     i=result.i;
                     return(result);
                     }
                     
             complex operator/=(complex other)
                     {
                     complex result;
                     result.r=(r*other.r+i*other.i)/(other.r*other.r+other.i*other.i);
                     result.i=(i*other.r-r*other.i)/(other.r*other.r+other.i*other.i);
                     r=result.r;
                     i=result.i;
                     return(result);
                     }
                     
             complex operator=(complex other)
                     {
                     r=other.r;
                     i=other.i;
                     return((*this));
                     }
                     
             bool operator==(complex other)
                     {
                     return(i==other.i && r==other.r);
                     }
                     
             bool operator !=(complex other)
                     {
                     return(!(i==other.i && r==other.r));
                     } 
                     
              double getLengthSQ()
                     {
                     return(r*r+i*i);
                     }       
             
              double getLength()
                     {
                     return(sqrt(r*r+i*i));
                     }   
             
              complex getPolar()
                      {
                      complex result;
                      result.r=getLength();
                      result.i=atan(i/r);
                      return(result);
                      }
                     
             void print()
                  {
                  std::cout<<r<<"+"<<i<<"i"<<std::endl;
                  }   
             
             
};


Nach oben
 Profil  
 
 Betreff des Beitrags: Re: Komplexe Zahlen [C++]
BeitragVerfasst: 21.08.2007, 17:13 
Offline
Benutzeravatar

Registriert: 24.07.2007, 23:11
Beiträge: 283
sorry für die dumme frage aber was bringt das jetzt genau?

_________________
Be Fluffy!
kemomi.de


Nach oben
 Profil  
 
 Betreff des Beitrags: Re: Komplexe Zahlen [C++]
BeitragVerfasst: 21.08.2007, 22:51 
Offline
Moderator
Benutzeravatar

Registriert: 11.03.2007, 20:25
Beiträge: 556
Wohnort: Frankfurt/Main
vereinfacht ein bisschen den umgang mit komplexen zahlen.
ziemlich nützlich.

_________________
yo. life's so bloody short.
Ihr dachtet Schulfernsehn sei die ultimative Folter? Falsch: Fahrstuhlmusik, extra leise.


Nach oben
 Profil  
 
 Betreff des Beitrags: Re: Komplexe Zahlen [C++]
BeitragVerfasst: 05.09.2007, 08:25 
Offline
Benutzeravatar

Registriert: 17.04.2007, 08:42
Beiträge: 460
Wohnort: Willich, NRW
jap finde ich auch. und es nimmt unheimlich schreibnarbeit ab xD. genau so als ich selbst ne vector2 oder vector3 klasse programmiert habe. nicht schwer aber ziiiiiiiiiiiiieht sich so ewig hin. danke also für die arbeit und des veröffentlichens. hast du denn schon ein paar schöne renderings damit gefertigt?

mfg das heck

_________________
Bild

Irrlicht - From Noob To Pro A Guideline

--

Sonstige Projekte, Blog : http://www.rpdev.net


Nach oben
 Profil  
 
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 4 Beiträge ] 

Alle Zeiten sind UTC + 1 Stunde


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 3 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de