PinkElephantsOnParade
PinkElephantsOnParade

Reputation: 6592

Processing: Library for Complex numbers?

I've just started learning Processing and I'm curious if there is a library for modeling complex numbers of the form a + bi. Particularly one that can handle multiplication of complex numbers numbers like:

(a + bi)(a + bi)


Upvotes: 2

Views: 3410

Answers (2)

King-Ink
King-Ink

Reputation: 2096

The Qscript library handles complex numbers add, subtract, powers the shebang. You can add it from the GUI add library function

Upvotes: 0

Majlik
Majlik

Reputation: 1082

You can write your own class in java or be inspired by this class. Also you can import classic java libraries like common-math.

If you need only multiplication just add this class to your sketch:

class Complex {
    double real;   // the real part
    double img;   // the imaginary part

    public Complex(double real, double img) {
        this.real = real;
        this.img = img;
    }

    public Complex multi(Complex b) {
        double real = this.real * b.real - this.img * b.img;
        double img = this.real * b.img + this.img * b.real;
        return new Complex(real, img);
    }
}

And then simple use for you example:

Complex first = new Complex(a, b);
complex result =  first.multi(first);

Upvotes: 7

Related Questions