Example usage for org.apache.commons.math.complex Complex Complex

List of usage examples for org.apache.commons.math.complex Complex Complex

Introduction

In this page you can find the example usage for org.apache.commons.math.complex Complex Complex.

Prototype

public Complex(double real, double imaginary) 

Source Link

Document

Create a complex number given the real and imaginary parts.

Usage

From source file:BackEnd.E_calculation.java

private FazorVektor calc_DE(double tau_real, double tau_image, DPoint Rp, DPoint R0, DPoint R0m, DPoint deltaL)
        throws DelaunayError {
    DPoint R_0 = new DPoint(R0.getX(), R0.getY(), R0.getZ());
    DPoint R_0m = new DPoint(R0.getX(), R0.getY(), R0.getZ());
    R_0.setY(R0.getY() + R0_bundleY); //  bundle korektura pre jeden druhy SMER 
    R_0.setZ(R0.getZ() + Math.cos(beta) * R0_bundleZ); // priemety
    R_0.setX(R0.getX() + Math.sin(beta) * R0_bundleZ);

    R_0m.setY(R0m.getY() - R0_bundleY); //  bundle korektura pre jeden druhy SMER 
    R_0m.setZ(R0m.getZ() + Math.cos(beta) * R0_bundleZ); // priemety
    R_0m.setX(R0m.getX() + Math.sin(beta) * R0_bundleZ);

    //  System.out.println( "R_0= " + R_0 );
    //  System.out.println( "Rp= " + Rp );
    // System.out.println( "deltal= " + deltaL );
    double K = 1 / (4 * Math.PI * constants.getEpsi0() * constants.getEpsi1()); // kontanta

    DPoint R_r = help.substract(Rp, R_0); // rozdiel vektorov Rp a RO
    DPoint R_m = help.substract(Rp, R_0m); // rozdiel vektorov RP a RO mirror
    DPoint R_r_unit = new DPoint(R_r);
    DPoint R_m_unit = new DPoint(R_m);

    R_r_unit.setX(R_r_unit.getX() / get_ABS(R_r));
    R_r_unit.setY(R_r_unit.getY() / get_ABS(R_r));
    R_r_unit.setZ(R_r_unit.getZ() / get_ABS(R_r));

    R_m_unit.setX(R_m_unit.getX() / get_ABS(R_m));
    R_m_unit.setY(R_m_unit.getY() / get_ABS(R_m));
    R_m_unit.setZ(R_m_unit.getZ() / get_ABS(R_m));

    double menovatel_r = Math.pow(get_ABS(R_r), 2);
    double menovatel_m = Math.pow(get_ABS(R_m), 2);
    double DELTA_l = get_ABS(deltaL);
    ///*ww w  .  j a  v a 2 s  . co  m*/
    //double DELTA_l = 1; //Rozptie.getKrok();

    FazorVektor deltaE = new FazorVektor(new Complex(0, 0), new Complex(0, 0), new Complex(0, 0));

    deltaE.setX_Real(K * (((tau_real * DELTA_l * R_r_unit.getX()) / menovatel_r)
            - ((tau_real * DELTA_l * R_m_unit.getX()) / menovatel_m)));
    deltaE.setY_Real(K * (((tau_real * DELTA_l * R_r_unit.getY()) / menovatel_r)
            - ((tau_real * DELTA_l * R_m_unit.getY()) / menovatel_m)));
    deltaE.setZ_Real(K * (((tau_real * DELTA_l * R_r_unit.getZ()) / menovatel_r)
            - ((tau_real * DELTA_l * R_m_unit.getZ()) / menovatel_m)));

    deltaE.setX_Imaginary(K * (((tau_image * DELTA_l * R_r_unit.getX()) / menovatel_r)
            - ((tau_image * DELTA_l * R_m_unit.getX()) / menovatel_m)));
    deltaE.setY_Imaginary(K * (((tau_image * DELTA_l * R_r_unit.getY()) / menovatel_r)
            - ((tau_image * DELTA_l * R_m_unit.getY()) / menovatel_m)));
    deltaE.setZ_Imaginary(K * (((tau_image * DELTA_l * R_r_unit.getZ()) / menovatel_r)
            - ((tau_image * DELTA_l * R_m_unit.getZ()) / menovatel_m)));

    return deltaE;
}

From source file:BackEnd.E_old_calculation.java

private FazorVektor calc_DE(double tau_real, double tau_image, DPoint Rp, DPoint R0, DPoint R0m, DPoint deltaL)
        throws DelaunayError {
    DPoint R_0 = new DPoint(R0.getX(), R0.getY(), R0.getZ());
    DPoint R_0m = new DPoint(R0m.getX(), R0m.getY(), R0m.getZ());
    R_0.setY(R0.getY() + R0_bundleY); //  bundle korektura pre jeden druhy SMER 
    R_0.setZ(R0.getZ() + Math.cos(beta) * R0_bundleZ); // priemety
    R_0.setX(R0.getX() + Math.sin(beta) * R0_bundleZ);

    R_0m.setY(R0m.getY() - R0_bundleY); //  bundle korektura pre jeden druhy SMER 
    R_0m.setZ(R0m.getZ() + Math.cos(beta) * R0_bundleZ); // priemety
    R_0m.setX(R0m.getX() + Math.sin(beta) * R0_bundleZ);

    //  System.out.println( "R_0= " + R_0 );
    //  System.out.println( "Rp= " + Rp );
    // System.out.println( "deltal= " + deltaL );
    double K = 1 / (4 * Math.PI * constants.getEpsi0() * constants.getEpsi1()); // kontanta

    DPoint R_r = help.substract(Rp, R_0); // rozdiel vektorov Rp a RO
    DPoint R_m = help.substract(Rp, R_0m); // rozdiel vektorov RP a RO mirror
    DPoint R_r_unit = new DPoint(R_r);
    DPoint R_m_unit = new DPoint(R_m);

    //        R_r_unit.setX(R_r_unit.getX()/get_ABS(R_r));
    //        R_r_unit.setY(R_r_unit.getY()/get_ABS(R_r));
    //        R_r_unit.setZ(R_r_unit.getZ()/get_ABS(R_r));
    //        /* w  w w .  j  a  va 2  s .  c  om*/
    //        R_m_unit.setX(R_m_unit.getX()/get_ABS(R_m));
    //        R_m_unit.setY(R_m_unit.getY()/get_ABS(R_m));
    //        R_m_unit.setZ(R_m_unit.getZ()/get_ABS(R_m));

    double menovatel_r = 0;
    double menovatel_m = 0;

    menovatel_r = Math.pow(get_ABS(R_r), 3);
    menovatel_m = Math.pow(get_ABS(R_m), 3);

    double DELTA_l = get_ABS(deltaL);
    //
    //double DELTA_l = 1; //Rozptie.getKrok();

    FazorVektor deltaE = new FazorVektor(new Complex(0, 0), new Complex(0, 0), new Complex(0, 0));

    deltaE.setX_Real(K * (((tau_real * DELTA_l * R_r_unit.getX()) / menovatel_r)
            - ((tau_real * DELTA_l * R_m_unit.getX()) / menovatel_m)));
    deltaE.setY_Real(K * (((tau_real * DELTA_l * R_r_unit.getY()) / menovatel_r)
            - ((tau_real * DELTA_l * R_m_unit.getY()) / menovatel_m)));
    deltaE.setZ_Real(K * (((tau_real * DELTA_l * R_r_unit.getZ()) / menovatel_r)
            - ((tau_real * DELTA_l * R_m_unit.getZ()) / menovatel_m)));

    deltaE.setX_Imaginary(K * (((tau_image * DELTA_l * R_r_unit.getX()) / menovatel_r)
            - ((tau_image * DELTA_l * R_m_unit.getX()) / menovatel_m)));
    deltaE.setY_Imaginary(K * (((tau_image * DELTA_l * R_r_unit.getY()) / menovatel_r)
            - ((tau_image * DELTA_l * R_m_unit.getY()) / menovatel_m)));
    deltaE.setZ_Imaginary(K * (((tau_image * DELTA_l * R_r_unit.getZ()) / menovatel_r)
            - ((tau_image * DELTA_l * R_m_unit.getZ()) / menovatel_m)));

    return deltaE;
}

From source file:geogebra.common.geogebra3D.kernel3D.geos.Geo3DVec.java

final public static void complexMultiply(GeoVecInterface a, GeoVecInterface b, GeoVec2D c) {

    if (!Kernel.isZero(a.getZ()) || !Kernel.isZero(b.getZ())) {
        c.setX(Double.NaN);//  ww w . j  a va 2s .c o  m
        c.setY(Double.NaN);
        c.setMode(Kernel.COORD_COMPLEX);
        return;
    }

    Complex out = new Complex(a.getX(), a.getY());
    out = out.multiply(new Complex(b.getX(), b.getY()));
    c.setX(out.getReal());
    c.setY(out.getImaginary());

    c.setMode(Kernel.COORD_COMPLEX);
}

From source file:BackEnd.E_Spheres_calculation.java

public void priprava(int pocet_stupnov) throws DelaunayError {

    ArrayList<Double> U_real_list = new ArrayList<Double>();
    ArrayList<Double> U_image_list = new ArrayList<Double>();
    ArrayList<Integer> polohy_lan = new ArrayList<Integer>();

    //iteratory/*from  ww  w  .j  a  va2  s .  co  m*/
    int iterator_lan = 0;
    int elementarny_iterator = 0;
    //basic priprava vektorov 
    for (int cl1 = 0; cl1 < rozptie.getRetazovkaList().size(); cl1++) {

        //cyklus bundle   
        for (int cl2 = 0; cl2 < rozptie.getRetazovkaList().get(cl1).getBundle_over(); cl2++) {

            ArrayList<DPoint> R0_vectors_per_lano = new ArrayList<DPoint>(
                    rozptie.getRetazovka(cl1).getRo_vectors()); // nacitam jedno lano a upravim ho podla bundle konstant
            ArrayList<DPoint> R0_mirror_vectors_per_lano = new ArrayList<DPoint>(
                    rozptie.getRetazovka(cl1).getRo_mirror_vectors());
            polohy_lan.add(elementarny_iterator);
            // cyklus 
            for (int cl3 = 0; cl3 < rozptie.getRetazovka(cl1).getRo_vectors().size(); cl3++) {

                //  bundle korektura pre jeden druhy SMER  a korekcia
                double Y = (double) R0_vectors_per_lano.get(cl3).getY()
                        + (double) rozptie.getRetazovkaList().get(cl1).getZY_cor_Bundle()[1][cl2];
                double Z = (double) R0_vectors_per_lano.get(cl3).getZ()
                        + (double) Math.cos(rozptie.getRetazovkaList().get(cl1).getBeta_over())
                                * rozptie.getRetazovkaList().get(cl1).getZY_cor_Bundle()[0][cl2];
                double X = (double) R0_vectors_per_lano.get(cl3).getX()
                        + (double) Math.sin(rozptie.getRetazovkaList().get(cl1).getBeta_over())
                                * rozptie.getRetazovkaList().get(cl1).getZY_cor_Bundle()[0][cl2];
                DPoint R0 = new DPoint(X, Y, Z);

                //mirrorovanie len jedneho rozmeru pozor
                double Ym = (double) R0_mirror_vectors_per_lano.get(cl3).getY()
                        - (double) rozptie.getRetazovkaList().get(cl1).getZY_cor_Bundle()[1][cl2];
                double Zm = (double) R0_mirror_vectors_per_lano.get(cl3).getZ()
                        + (double) Math.cos(rozptie.getRetazovkaList().get(cl1).getBeta_over())
                                * rozptie.getRetazovkaList().get(cl1).getZY_cor_Bundle()[0][cl2];
                double Xm = (double) R0_mirror_vectors_per_lano.get(cl3).getX()
                        + (double) Math.sin(rozptie.getRetazovkaList().get(cl1).getBeta_over())
                                * rozptie.getRetazovkaList().get(cl1).getZY_cor_Bundle()[0][cl2];
                DPoint R0m = new DPoint(Xm, Ym, Zm);

                // nastavy U real a image do separatnych listov podla toho na akom vodi?i je ( tu sa bundle ignoruje )
                U_real_list.add(get_real(rozptie.getRetazovkaList().get(cl1).getU_over(),
                        rozptie.getRetazovkaList().get(cl1).getPhi_over()) / Math.sqrt(3));
                U_real_list.add(get_real(-rozptie.getRetazovkaList().get(cl1).getU_over(),
                        rozptie.getRetazovkaList().get(cl1).getPhi_over()) / Math.sqrt(3)); // add image voltage
                U_image_list.add(get_image(rozptie.getRetazovkaList().get(cl1).getU_over(),
                        rozptie.getRetazovkaList().get(cl1).getPhi_over()) / Math.sqrt(3));
                U_image_list.add(get_image(-rozptie.getRetazovkaList().get(cl1).getU_over(),
                        rozptie.getRetazovkaList().get(cl1).getPhi_over()) / Math.sqrt(3)); // add image voltage
                // nastavy polomery do jedej arraylistu
                this.polomery_lan.add(rozptie.getRetazovkaList().get(cl1).getR_over()); // realn
                this.polomery_lan.add(rozptie.getRetazovkaList().get(cl1).getR_over()); //image
                this.Ri.add(new DPoint(R0)); // add real
                this.Ri.add(new DPoint(R0m)); // add image to the total list

                //    elementarny_iterator = elementarny_iterator + 1;
            }

        }

    }

    //NULTY STUPEN Qi
    double pocitac = 0;
    for (int i = 0; i < Ri.size(); i++) {
        double qi_real = 4 * Math.PI * this.epsi0 * this.epsiR * polomery_lan.get(i) * U_real_list.get(i);
        double qi_image = 4 * Math.PI * this.epsi0 * this.epsiR * polomery_lan.get(i) * U_image_list.get(i);

        this.qi.add(new Complex(qi_real, qi_image));
        pocitac++;
    }
    System.out.println("pocet prvkov krok O =" + pocitac);
    pocitac = 0;

    //druhy stupen Qij
    for (int i = 0; i < Ri.size(); i++) {

        ArrayList<DPoint> R = new ArrayList<DPoint>();
        ArrayList<Complex> q = new ArrayList<Complex>();

        for (int j = 0; j < Ri.size(); j++) {

            if (i == j) {

            } else {

                double distance = get_distance(Ri.get(i), Ri.get(j));
                double distance2 = Math.pow(distance, 2);
                double Ai = polomery_lan.get(i);
                double Ai2 = Math.pow(Ai, 2);
                if (distance < rozptie.getRetazovka(0).getI_over()) {
                    double q_real = -(Ai / distance) * qi.get(j).getReal();
                    double q_image = -(Ai / distance) * qi.get(j).getImaginary();
                    double X = Ri.get(i).getX() - Ai2 * ((Ri.get(i).getX() - Ri.get(j).getX()) / distance2);
                    double Y = Ri.get(i).getY() - Ai2 * ((Ri.get(i).getY() - Ri.get(j).getY()) / distance2);
                    double Z = Ri.get(i).getZ() - Ai2 * ((Ri.get(i).getZ() - Ri.get(j).getZ()) / distance2);
                    DPoint Ri = new DPoint(X, Y, Z);

                    q.add(new Complex(q_real, q_image));
                    R.add(new DPoint(Ri));
                    pocitac++;

                }
            }

        }
        this.qij.add(new ArrayList<Complex>(q));
        this.Rij.add(new ArrayList<DPoint>(R));

    }
    System.out.println("pocet prvkov krok 1 =" + pocitac);
    pocitac = 0;

    //druhy stupen Qij
    for (int i = 0; i < Ri.size(); i++) {

        ArrayList<ArrayList<DPoint>> Rj = new ArrayList<ArrayList<DPoint>>();
        ArrayList<ArrayList<Complex>> qj = new ArrayList<ArrayList<Complex>>();

        for (int j = 0; j < Rij.size(); j++) {

            ArrayList<DPoint> R = new ArrayList<DPoint>();
            ArrayList<Complex> q = new ArrayList<Complex>();

            if (i == j) {

            } else {

                for (int k = 0; k < Rij.get(0).size(); k++) {
                    if (j == k) {

                    } else {
                        double distance = get_distance(Ri.get(i), Rij.get(j).get(k));
                        double distance2 = Math.pow(distance, 2);
                        double Ai = polomery_lan.get(i);
                        double Ai2 = Math.pow(Ai, 2);
                        if (distance < rozptie.getRetazovka(0).getI_over()) {
                            double q_real = -(Ai / distance) * qij.get(j).get(k).getReal();
                            double q_image = -(Ai / distance) * qij.get(j).get(k).getImaginary();

                            double X = Ri.get(i).getX()
                                    - Ai2 * ((Ri.get(i).getX() - Rij.get(j).get(k).getX()) / distance2);
                            double Y = Ri.get(i).getY()
                                    - Ai2 * ((Ri.get(i).getY() - Rij.get(j).get(k).getY()) / distance2);
                            double Z = Ri.get(i).getZ()
                                    - Ai2 * ((Ri.get(i).getZ() - Rij.get(j).get(k).getZ()) / distance2);
                            DPoint Ri = new DPoint(X, Y, Z);

                            q.add(new Complex(q_real, q_image));
                            R.add(new DPoint(Ri));
                            pocitac++;
                        }
                    }
                }
                qj.add(new ArrayList<Complex>(q));
                Rj.add(new ArrayList<DPoint>(R));
            }

        }
        this.qijk.add(new ArrayList<ArrayList<Complex>>(qj));
        this.Rijk.add(new ArrayList<ArrayList<DPoint>>(Rj));

    }
    System.out.println("pocet prvkov krok 2 =" + pocitac);
    pocitac = 0;

    //druhy stupen Qijkl
    for (int i = 0; i < Ri.size(); i++) {

        ArrayList<ArrayList<ArrayList<DPoint>>> Rjk = new ArrayList<ArrayList<ArrayList<DPoint>>>();
        ArrayList<ArrayList<ArrayList<Complex>>> qjk = new ArrayList<ArrayList<ArrayList<Complex>>>();

        for (int j = 0; j < Rijk.size(); j++) {

            ArrayList<ArrayList<DPoint>> Rj = new ArrayList<ArrayList<DPoint>>();
            ArrayList<ArrayList<Complex>> qj = new ArrayList<ArrayList<Complex>>();

            if (i == j) {

            } else {

                for (int k = 0; k < Rijk.get(0).size(); k++) {

                    ArrayList<DPoint> R = new ArrayList<DPoint>();
                    ArrayList<Complex> q = new ArrayList<Complex>();

                    if (j == k) {

                    } else {

                        for (int l = 0; l < Rijk.get(0).get(0).size(); l++) {
                            if (k == l) {

                            } else {
                                double distance = get_distance(Ri.get(i), Rijk.get(j).get(k).get(l));
                                double distance2 = Math.pow(distance, 2);
                                double Ai = polomery_lan.get(i);
                                double Ai2 = Math.pow(Ai, 2);
                                if (distance < rozptie.getRetazovka(0).getI_over()) {
                                    double q_real = -(Ai / distance) * qijk.get(j).get(k).get(l).getReal();
                                    double q_image = -(Ai / distance)
                                            * qijk.get(j).get(k).get(l).getImaginary();

                                    double X = Ri.get(i).getX()
                                            - Ai2 * ((Ri.get(i).getX() - Rijk.get(j).get(k).get(l).getX())
                                                    / distance2);
                                    double Y = Ri.get(i).getY()
                                            - Ai2 * ((Ri.get(i).getY() - Rijk.get(j).get(k).get(l).getY())
                                                    / distance2);
                                    double Z = Ri.get(i).getZ()
                                            - Ai2 * ((Ri.get(i).getZ() - Rijk.get(j).get(k).get(l).getZ())
                                                    / distance2);
                                    DPoint Ri = new DPoint(X, Y, Z);

                                    q.add(new Complex(q_real, q_image));
                                    R.add(new DPoint(Ri));
                                    pocitac++;
                                }
                            }
                        }
                        qj.add(new ArrayList<Complex>(q));
                        Rj.add(new ArrayList<DPoint>(R));
                    }

                }
            }

            qjk.add(new ArrayList<ArrayList<Complex>>(qj));
            Rjk.add(new ArrayList<ArrayList<DPoint>>(Rj));

        }
        this.qijkl.add(new ArrayList<ArrayList<ArrayList<Complex>>>(qjk));
        this.Rijkl.add(new ArrayList<ArrayList<ArrayList<DPoint>>>(Rjk));

    }
    System.out.println("pocet prvkov krok 3 =" + pocitac);
    pocitac = 0;

}

From source file:BackEnd.Observer.java

public void calculateI(double KE, double KB, double epsi0, double epsi1, double sigma0, double f) {

    double JeXR = KE * epsi0 * epsi1 * 2 * Math.PI * f * E.getX_ABS();
    // double JeXI = KE*epsi0*epsi1*2*Math.PI*f*E.getX_Imaginary();  
    double JeYR = KE * epsi0 * epsi1 * 2 * Math.PI * f * E.getY_ABS();
    // double JeYI = KE*epsi0*epsi1*2*Math.PI*f*E.getY_Imaginary();  
    double JeZR = KE * epsi0 * epsi1 * 2 * Math.PI * f * E.getZ_ABS();
    //  double JeZI = KE*epsi0*epsi1*2*Math.PI*f*E.getZ_Imaginary();

    double JbXR = KB * sigma0 * 2 * Math.PI * f * B.getX_ABS();
    //  double JbXI = KB*sigma0*2*Math.PI*f*B.getX_Imaginary();  
    double JbYR = KB * sigma0 * 2 * Math.PI * f * B.getY_ABS();
    //  double JbYI = KB*sigma0*2*Math.PI*f*B.getY_Imaginary();  
    double JbZR = KB * sigma0 * 2 * Math.PI * f * B.getZ_ABS();
    //  double JbZI = KB*sigma0*2*Math.PI*f*B.getZ_Imaginary();

    I = new FazorVektor(new Complex(JeXR + JbXR, 0), new Complex(JeYR + JbYR, 0), new Complex(JeZR + JbZR, 0));
    //System.out.println(B.getX().getReal() +"  " +E.getX().getReal() +"  " +I.getX().getReal()  +"  "+ (KE*epsi0*epsi1*2*Math.PI*f)+"  "+ (KB*sigma0*2*Math.PI*f) );
}

From source file:geogebra.kernel.GeoVec2D.java

/** c = a / b Michael Borcherds 2007-12-09 
 * //from w  w  w. jav a  2s  .co m
 * */
final public static void complexDivide(GeoVec2D a, GeoVec2D b, GeoVec2D c) {
    // NB temporary variables *crucial*: a and c can be the same variable
    //double x1=a.x,y1=a.y,x2=b.x,y2=b.y;
    // complex division
    //c.x = (x1 * x2 + y1 * y2)/(x2 * x2 + y2 * b.y);
    //c.y = (y1 * x2 - x1 * y2)/(x2 * x2 + y2 * b.y);

    Complex out = new Complex(a.x, a.y);
    out = out.divide(new Complex(b.x, b.y));
    c.x = out.getReal();
    c.y = out.getImaginary();
    c.setMode(Kernel.COORD_COMPLEX);

}

From source file:com.isencia.passerelle.message.TokenHelper.java

/**
 * Tries to get a Complex from the token, by:
 * <ul>/*from   ww w .  jav a  2 s.  c  o  m*/
 * <li>checking if the token is not an ObjectToken, containing a Double
 * <li>checking if the token is not an ObjectToken, and converting the object.toString() into a Double
 * <li>checking if the token is not a StringToken, and converting the string into a Double
 * <li>checking if the token is not a ScalarToken, and reading its double value
 * </ul>
 * 
 * @param token
 * @return
 */
public static Complex getComplexFromToken(Token token) throws PasserelleException {
    if (logger.isTraceEnabled()) {
        logger.trace(token.toString()); // TODO Check if correct converted
    }
    Complex res = null;

    if (token != null) {
        try {
            if (token instanceof ObjectToken) {
                Object obj = ((ObjectToken) token).getValue();
                if (obj instanceof Complex) {
                    res = (Complex) obj;
                }
                if (obj instanceof ptolemy.math.Complex) {
                    ptolemy.math.Complex tmp = (ptolemy.math.Complex) obj;
                    res = new Complex(tmp.real, tmp.imag);
                } else if (obj != null) {
                    String content = obj.toString();
                    try {
                        res = iFormat.parse(content);
                    } catch (ParseException e) {
                        // Try the j-format
                        try {
                            res = jFormat.parse(content);
                        } catch (ParseException e1) {
                            throw new PasserelleException(ErrorCode.MSG_CONTENT_TYPE_ERROR,
                                    "Invalid Complex format in " + token, e1);
                        }
                    }
                }
            } else {
                if (token instanceof StringToken) {
                    String content = ((StringToken) token).stringValue();
                    if (content != null) {
                        try {
                            res = iFormat.parse(content);
                        } catch (ParseException e) {
                            // Try the j-format
                            res = jFormat.parse(content);
                        }
                    }
                } else if (token instanceof ComplexToken) {
                    ptolemy.math.Complex tmp = ((ComplexToken) token).complexValue();
                    res = new Complex(tmp.real, tmp.imag);
                } else if (token instanceof ScalarToken) {
                    try {
                        res = new Complex(((ScalarToken) token).doubleValue(), 0);
                    } catch (IllegalActionException e) {
                        throw new PasserelleException(ErrorCode.MSG_CONTENT_TYPE_ERROR,
                                "Invalid token for obtaining Complex value in " + token, e);
                    }
                } else {
                    throw new PasserelleException(ErrorCode.MSG_CONTENT_TYPE_ERROR,
                            "Invalid token for obtaining Complex value in " + token, null);
                }
            }
        } catch (Exception e) {
            throw new PasserelleException(ErrorCode.MSG_CONTENT_TYPE_ERROR,
                    "Error building Complex from token in " + token, e);
        }
    }

    if (logger.isTraceEnabled()) {
        logger.trace("exit :" + res);
    }
    return res;
}

From source file:geogebra.kernel.GeoVec2D.java

/** c = a / b Michael Borcherds 2008-08-12 
 * //from  w w w . java  2  s.co  m
 * */
final public static void complexDivide(NumberValue a, GeoVec2D b, GeoVec2D c) {
    // NB temporary variables *crucial*: a and c can be the same variable
    //double x1=a.getDouble(), x2 = b.x, y2 = b.y;
    // complex division
    //c.x = (x1 * x2 )/(x2 * x2 + y2 * b.y);
    //c.y = ( - x1 * y2)/(x2 * x2 + y2 * b.y);

    Complex out = new Complex(a.getDouble(), 0);
    out = out.divide(new Complex(b.x, b.y));
    c.x = out.getReal();
    c.y = out.getImaginary();
    c.setMode(Kernel.COORD_COMPLEX);
}

From source file:geogebra.kernel.GeoVec2D.java

/** c = a * b Michael Borcherds 2007-12-09 */
final public static void complexMultiply(GeoVec2D a, GeoVec2D b, GeoVec2D c) {
    // NB temporary variables *crucial*: a and c can be the same variable
    //double x1=a.x,y1=a.y,x2=b.x,y2=b.y;
    //  do multiply
    //c.x = (x1 * x2 - y1 * y2);
    //c.y = (y2 * x1 + x2 * y1);

    Complex out = new Complex(a.x, a.y);
    out = out.multiply(new Complex(b.x, b.y));
    c.x = out.getReal();/*w w  w .j  a  va 2 s. com*/
    c.y = out.getImaginary();

    c.setMode(Kernel.COORD_COMPLEX);
}

From source file:geogebra.kernel.GeoVec2D.java

/** c = a ^ b Michael Borcherds 2009-03-10 */
final public static void complexPower(GeoVec2D a, NumberValue b, GeoVec2D c) {
    Complex out = new Complex(a.x, a.y);
    out = out.pow(new Complex(b.getDouble(), 0));
    c.x = out.getReal();//from  w  w  w  .j  ava  2s .  co m
    c.y = out.getImaginary();
    c.setMode(Kernel.COORD_COMPLEX);
}