Example usage for org.apache.commons.math3.geometry.euclidean.twod Vector2D Vector2D

List of usage examples for org.apache.commons.math3.geometry.euclidean.twod Vector2D Vector2D

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.twod Vector2D Vector2D.

Prototype

public Vector2D(double a, Vector2D u) 

Source Link

Document

Multiplicative constructor Build a vector from another one and a scale factor.

Usage

From source file:de.thkwalter.et.ortskurve.Ausgleichsproblem.java

/**
 * Diese Methode lst das Ausgleichsproblem.
 * //from w w  w  .  ja  v a  2  s. c  o  m
 * @param startpunkt Der Startpunkt der Ausgleichsrechnung
 * @param ausgleichsproblemtyp Der Typ des Ausgleichsproblems
 * 
 * @return Die berechnete Ortskurve
 */
public Ortskurve ausgleichsproblemLoesen(double[] startpunkt, Ausgleichsproblemtyp ausgleichsproblemtyp) {
    // Die Referenzen auf die Modellgleichungen und die Jakobimatrix werden deklariert.
    MultivariateVectorFunction modellgleichungen = null;
    MultivariateMatrixFunction jakobiMatrix = null;

    // Falls das zweidimensionale Ausgleichsproblem gelst werden soll, ...
    if (ausgleichsproblemtyp == Ausgleichsproblemtyp.ORTSKURVE_2d) {
        // Die Modellgleichungen (die Kreisgleichungen) werden erzeugt.
        modellgleichungen = new Modellgleichungen2d(this.messpunkte);

        // Die Jakobi-Matrix der Modellgleichungen (der Kreisgleichungen) wird erzeugt.
        jakobiMatrix = new Jakobimatrix2d(this.messpunkte);
    }

    // Falls das dreidimensionale Ausgleichsproblem gelst werden soll, ...
    else if (ausgleichsproblemtyp == Ausgleichsproblemtyp.ORTSKURVE_3d) {
        // Die Modellgleichungen (die Kreisgleichungen) werden erzeugt.
        modellgleichungen = new Modellgleichungen(this.messpunkte);

        // Die Jakobi-Matrix der Modellgleichungen (der Kreisgleichungen) wird erzeugt.
        jakobiMatrix = new Jakobimatrix(this.messpunkte);
    }

    // Das Ausgleichsproblem wird gelst, wobei hchstens 200 Iterationsschritte durchgefhrt werden.
    double[] ortskurvenparameter = null;
    try {
        PointVectorValuePair endParameter = this.gaussNewtonOptimizer.optimize(new Weight(gewichte),
                new Target(zielwerte), new InitialGuess(startpunkt), new MaxEval(200),
                new ModelFunction(modellgleichungen), new ModelFunctionJacobian(jakobiMatrix));

        ortskurvenparameter = endParameter.getPoint();
    }

    // Falls das Verfahren nicht konvergiert hat, wird die entsprechende Ausnahme gefangen.
    catch (TooManyEvaluationsException e) {
        // Die Fehlermeldung fr den Entwickler wird erzeugt und protokolliert.
        String fehlermeldung = "Der Gauss-Newton-Algorithmus konvergiert nicht!";
        Ausgleichsproblem.logger.severe(fehlermeldung);

        // Die Ausnahme wird erzeugt und mit der Fehlermeldung fr den Benutzer initialisiert.
        String jsfMeldung = "Der Gauss-Newton-Algorithmus zur Berechnung der Ortskurve konvergiert nicht! "
                + "berprfen Sie bitte, ob die eingegebenen Punkte annhernd auf einem Kreis liegen.";
        ApplicationRuntimeException applicationRuntimeException = new ApplicationRuntimeException(jsfMeldung);

        throw applicationRuntimeException;
    }

    // Die Referenz auf die Ortskurve wird deklariert.
    Ortskurve ortskurve = null;

    // Falls das zweidimensionale Ausgleichsproblem gelst werden soll, ...
    if (ausgleichsproblemtyp == Ausgleichsproblemtyp.ORTSKURVE_2d) {
        ortskurve = new Ortskurve(new Vector2D(ortskurvenparameter[0], 0.0), ortskurvenparameter[1]);
    }

    // Falls das dreidimensionale Ausgleichsproblem gelst werden soll, ...
    else if (ausgleichsproblemtyp == Ausgleichsproblemtyp.ORTSKURVE_3d) {
        ortskurve = new Ortskurve(new Vector2D(ortskurvenparameter[0], ortskurvenparameter[1]),
                ortskurvenparameter[2]);
    }

    // Die berechnete Ortskurve wird zurckgegeben.
    return ortskurve;
}

From source file:de.thkwalter.et.ortskurve.OrtskurveControllerTest.java

/**
 * Test fr die Methode {@link OrtskurveController#ortskurveBestimmen(Vector2D[], double[])}.
 * @throws SecurityException /*from  w  ww . j a v a2s .com*/
 * @throws NoSuchMethodException 
 * @throws InvocationTargetException 
 * @throws IllegalArgumentException 
 * @throws IllegalAccessException 
 */
@Test
public void testOrtskurveBestimmen() throws NoSuchMethodException, SecurityException, IllegalAccessException,
        IllegalArgumentException, InvocationTargetException {
    // Die in diesem Test verwendeten Messpunkte werden deklariert.
    Vector2D[] testMesspunkte = new Vector2D[] { new Vector2D(2.0, 0.0), new Vector2D(3.0, 1.0),
            new Vector2D(3.0, -1.0) };

    // Der in diesem Test verwendete Startpunkt wird deklariert.
    double[] testStartpunkt = new double[] { 3.0, 0.0, 1.0 };

    // Die zu testenden Methode wird aufgerufen.
    Method methode = OrtskurveController.class.getDeclaredMethod("ortskurveBestimmen", Vector2D[].class,
            double[].class);
    methode.setAccessible(true);
    Ortskurve ortskurve = (Ortskurve) methode.invoke(this.ortskurveController, testMesspunkte, testStartpunkt);

    // Es wird berprft, ob der Startpunkt als Ortskurve zurckgegeben worden ist.
    assertEquals(testStartpunkt[0], ortskurve.getMittelpunktOrtskurve().getX(), 0.0);
    assertEquals(testStartpunkt[1], ortskurve.getMittelpunktOrtskurve().getY(), 0.0);
    assertEquals(testStartpunkt[2], ortskurve.getRadiusOrtskurve(), 0.0);
}

From source file:de.thkwalter.et.schlupfbezifferung.SchlupfbezifferungModellTest.java

/**
 * Test der Methode {@link SchlupfbezifferungModell#getOrtskurve()}.
 * /*from  w w  w  . j  ava 2s.c  o  m*/
 * @throws SecurityException 
 * @throws NoSuchFieldException 
 * @throws IllegalAccessException 
 * @throws IllegalArgumentException 
 */
@Test
public void testGetOrtskurve()
        throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    // Die in diesem Test verwendete Ortskurve wird erzeugt.
    Ortskurve testOrtskurve = new Ortskurve(new Vector2D(0.0, 0.0), 1.0);

    // Das in diesem Test verwendete Ortskurve wird im Datenmodell gespeichert.
    Field feldOrtskurve = SchlupfbezifferungModell.class.getDeclaredField("ortskurve");
    feldOrtskurve.setAccessible(true);
    feldOrtskurve.set(this.schlupfbezifferungModell, testOrtskurve);

    // Es wird berprft, ob die Ortskurve korrekt zurckgegeben wird.
    assertEquals(testOrtskurve, this.schlupfbezifferungModell.getOrtskurve());
}

From source file:edu.snu.leader.discrete.simulator.SueurSimpleAngularUninformedAgentBuilder.java

@Override
public List<Agent> build() {
    List<Agent> agents = new ArrayList<Agent>();
    // build them
    DecisionProbabilityCalculator temp = (DecisionProbabilityCalculator) MiscUtils.loadAndInstantiate(
            _simState.getProperties().getProperty("decision-calculator"),
            "Decision Probability Calculator Class");
    temp.initialize(_simState);//from w w  w.  j  a v  a2s  . c om
    for (int i = 0; i < _numAgents; i++) {
        agents.add(new Agent(temp));
    }

    /** Array of 70 unique colors to use for destinations */
    Color[] colors = { new Color(0xFF0000), new Color(0x9ACD32), new Color(0xFFFF00), new Color(0xF5DEB3),
            new Color(0xEE82EE), new Color(0x40E0D0), new Color(0xFF6347), new Color(0xD8BFD8),
            new Color(0x008080), new Color(0x4682B4), new Color(0x00FF7F), new Color(0x708090),
            new Color(0x6A5ACD), new Color(0x87CEEB), new Color(0xC0C0C0), new Color(0xA0522D),
            new Color(0x2E8B57), new Color(0xF4A460), new Color(0xFA8072), new Color(0x8B4513),
            new Color(0x4169E1), new Color(0xBC8F8F), new Color(0x000000), new Color(0x800080),
            new Color(0xB0E0E6), new Color(0xDDA0DD), new Color(0xFFC0CB), new Color(0xCD853F),
            new Color(0xFFDAB9), new Color(0xFFEFD5), new Color(0xDB7093), new Color(0x98FB98),
            new Color(0xEEE8AA), new Color(0xDA70D6), new Color(0xFF4500), new Color(0xFFA500),
            new Color(0x6B8E23), new Color(0x000080), new Color(0xFFDEAD), new Color(0xF0A0AA),
            new Color(0x191970), new Color(0xC71585), new Color(0x48D1CC), new Color(0x00FA9A),
            new Color(0x7B68EE), new Color(0x3CB371), new Color(0x0000CD), new Color(0x66CDAA),
            new Color(0x800000), new Color(0x32CD32), new Color(0x00FF00), new Color(0xFFFFE0),
            new Color(0xB0C4DE), new Color(0x778899), new Color(0x87CEFA), new Color(0x20B2AA),
            new Color(0xFFA07A), new Color(0xFFB6C1), new Color(0x90EE90), new Color(0xD3D3D3),
            new Color(0xFAFAD2), new Color(0xE0FFFF), new Color(0xF08080), new Color(0xADD8E6),
            new Color(0x7CFC00), new Color(0x4B0082), new Color(0xFF69B4), new Color(0xFFD700),
            new Color(0x1E90FF), new Color(0x8FBC8F) };

    // holds the count of agents that prefer each destination
    Map<Vector2D, Integer> destinationCounts = new HashMap<Vector2D, Integer>();
    // holds the colors assigned to each destination
    Map<Vector2D, Color> destinationColors = new HashMap<Vector2D, Color>();
    // holds the index for colors used to assign destination colors
    Map<Color, Integer> destinationIds = new HashMap<Color, Integer>();
    // the current index for colors
    int colorCount = 0;

    // initialize them
    for (int i = 0; i < _numAgents; i++) {
        Agent tempAgent = agents.get(i);
        // create new movement behavior instance
        MovementBehavior mb = new SimpleAngularMovement();
        // Initialize the agent
        tempAgent.initialize(_simState, _locations.get(i));

        // get the number of informed individuals as defined by file name
        int informedCount = 0;
        // create the pattern and matcher
        Pattern pattern = Pattern.compile("(split-poles-)([0-9]+)");
        Matcher matcher = pattern.matcher(_destinationsFile);
        // if we have a match
        if (matcher.find()) {
            // get the informed individual per pole count in group 2
            informedCount = Integer.parseInt(matcher.group(2));
            // multiply it by 2 to get our total number of informed agents
            informedCount *= 2;
        }

        // set their destination if they have one
        if (i < informedCount) {
            Vector2D agentDestination = new Vector2D(_destinations[i].getX(), _destinations[i].getY());
            Color destinationColor = null;
            // set their color for their destination
            // if new destination then give it new color
            if (destinationColors.containsKey(agentDestination)) {
                // assign its color from the map
                destinationColor = destinationColors.get(agentDestination);
                // increment agent count going to this destination
                destinationCounts.put(agentDestination, destinationCounts.get(agentDestination) + 1);
            }
            // not a new destination, give it the color other's have been
            // assigned
            else {
                // add new destination
                _simState.addDestination(agentDestination);
                // assign color and set counts to 0
                destinationColor = colors[colorCount];
                destinationCounts.put(agentDestination, 0);
                destinationColors.put(agentDestination, destinationColor);
                destinationIds.put(destinationColor, colorCount);
                // increment color count
                colorCount++;
            }
            String destinationID = "D-" + destinationIds.get(destinationColor);

            // create a new preferred destination and give it to agent
            Destination agentPreferredDestination = new Destination(destinationID, true, agentDestination,
                    destinationColor, _destinationRadius);
            tempAgent.setPreferredDestination(agentPreferredDestination);
        }

        // the agent name formatted for the position reporter
        String agentName = tempAgent.getId().toString();
        agentName = agentName.replaceAll("Agent", "");
        agentName = "Ind" + String.format("%05d", Integer.parseInt(agentName));

        // the header for the position reporter
        tempAgent.setPositionReportHeader("world-object-name=" + agentName + "\n" + "team-name="
                + tempAgent.getPreferredDestinationId() + "\n" + "collision-bounding-radius="
                + (Agent.AGENT_DIAMETER / 2) + "\n\n" + "position=" + tempAgent.getInitialLocation().getX()
                + "," + tempAgent.getInitialLocation().getY() + ",0\n");

        // set and initialize movement behavior
        tempAgent.setMovementBehavior(mb);
        mb.initialize(tempAgent);
    }

    // set the good and bad destinations
    for (int i = 0; i < agents.size(); i++) {
        // if there is more than one agent going to a destination it is good
        if (agents.get(i).getPreferredDestination() != null
                && destinationCounts.get(agents.get(i).getPreferredDestination().getVector()) > 1) {
            agents.get(i).getPreferredDestination().setIsGood(true);
        } else if (agents.get(i).getPreferredDestination() == null) {
            agents.get(i).setPreferredDestination(_simState.noneDestination);
        }
    }

    return agents;
}

From source file:de.thkwalter.et.ortskurve.OrtskurveController.java

/**
 * Diese Methode bestimmt die Ortskurve.
 * /*from  w  w  w. j  a  v a2s  .c  om*/
 * @param messpunkte Die Messpunkte
 * @param startpunkt Das erste Element ist die x-Komponente des Mittelpunkts, das zweite Element die y-Komponente des 
 * Mittelpunkts, das dritte Element der Radius.
 * 
 * @return Die Ortskurve
 */
private Ortskurve ortskurveBestimmen(Vector2D[] messpunkte, double[] startpunkt) {
    // Die Referenz auf die Ortskurve wird deklariert.
    Ortskurve ortskurve = null;

    // Falls nur drei Messpunkte eingegeben worden sind, entspricht der Startpunkt der Lsung.
    if (messpunkte.length == 3) {
        ortskurve = new Ortskurve(new Vector2D(startpunkt[0], startpunkt[1]), startpunkt[2]);
    }

    // Falls mehr als drei Messpunkte eingegeben worden sind, muss die Lsung durch eine nicht-lineare 
    // Ausgleichsrechnung bestimmt werden.
    else {
        Ausgleichsproblem ausgleichsproblem = new Ausgleichsproblem(messpunkte);
        ortskurve = ausgleichsproblem.ausgleichsproblemLoesen(startpunkt, Ausgleichsproblemtyp.ORTSKURVE_3d);
    }

    // Die berechnete Ortskurve wird protokolliert.
    OrtskurveController.logger.info(ortskurve.toString());

    // Die berechnete Ortskurve wird zurckgegeben.
    return ortskurve;
}

From source file:de.thkwalter.et.schlupfbezifferung.SchlupfbezifferungController.java

/**
 * Diese Methode berechnet das Inversionszentrum (in A). Das Inversionszentrum liegt auf der gedrehten Ortskurve unter 
 * dem Polarwinkel von 315 Grad./*from ww  w .j  ava2  s . co m*/
 * 
 * @return Das Inversionzentrum (in A)
 */
private Vector2D inversionszentrumBerechnen() {
    // Der Mittelpunkt der gedrehten Ortskurve (in A) wird gelesen.
    Vector2D mittelpunktOrtskurve = this.schlupfbezifferungModell.getOrtskurve().getMittelpunktOrtskurve();
    double m_x = mittelpunktOrtskurve.getX();
    double m_y = mittelpunktOrtskurve.getY();

    // Der Radius der Ortskurve (in A) wird gelesen.
    double r = this.schlupfbezifferungModell.getOrtskurve().getRadiusOrtskurve();

    // Das Inversionszentrum (in A) wird berechnet. 
    double x_0 = m_x + r * Math.cos(7 * Math.PI / 4);
    double y_0 = m_y + r * Math.sin(7 * Math.PI / 4);
    Vector2D inversionszentrum = new Vector2D(x_0, y_0);

    // Das Inversionszentrum (in A) wird zurckgegeben.
    return inversionszentrum;
}

From source file:de.thkwalter.et.ortskurve.StartpunktbestimmungTest.java

/**
 * Test fr die Methode {@link Startpunktbestimmung#messpunkteAuswaehlen(Vector2D[])}.
 * /*from   ww w .j av  a  2s .c  o m*/
 * @throws NoSuchMethodException 
 * @throws SecurityException 
 * @throws InvocationTargetException 
 * @throws IllegalAccessException 
 * @throws IllegalArgumentException 
 * @throws NoSuchFieldException 
 */
@Test
public void testMesspunkteAuswaehlen1() throws SecurityException, NoSuchMethodException,
        IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchFieldException {
    // Die Messpunkte, die fr den Test verwendet werden.
    Vector2D[] messpunkte = new Vector2D[] { new Vector2D(1.0, 1.0), new Vector2D(1.0, -1.0),
            new Vector2D(0.0, -0.1), new Vector2D(0.0, -0.2) };

    // Die zu testende Methode wird aufgerufen
    Method methode = Startpunktbestimmung.class.getDeclaredMethod("messpunkteAuswaehlen", Vector2D[].class);
    methode.setAccessible(true);
    Vector2D[] messpunkteZurStartpunktbestimmung = (Vector2D[]) methode.invoke(Startpunktbestimmung.class,
            (Object) messpunkte);

    // Es wird geprft, ob die korrekten Messpunkt gefunden worden sind.
    assertEquals(messpunkte[0], messpunkteZurStartpunktbestimmung[0]);
    assertEquals(messpunkte[1], messpunkteZurStartpunktbestimmung[1]);
    assertEquals(messpunkte[2], messpunkteZurStartpunktbestimmung[2]);
}

From source file:de.thkwalter.et.schlupfbezifferung.SchlupfbezifferungModellTest.java

/**
 * Test der Methode {@link SchlupfbezifferungModell#setOrtskurve(Ortskurve)}.
 *///from   w w w. j a v  a2s. c  o m
@Test
public void testSetOrtskurve() {
    // Die in diesem Test verwendete Ortskurve wird erzeugt.
    Ortskurve testOrtskurve = new Ortskurve(new Vector2D(0.0, 0.0), 1.0);

    // Die zu testende Methode wird aufgerufen.
    this.schlupfbezifferungModell.setOrtskurve(testOrtskurve);

    // Es wird berprft, ob die Ortskurve korrekt im Datenmodell der Schlupfbezifferungsbestimmung gespeichert worden 
    // ist.
    assertEquals(testOrtskurve, this.schlupfbezifferungModell.getOrtskurve());
}

From source file:de.thkwalter.et.ortskurve.OrtskurveModellTest.java

/**
 * Test fr die Methode {@link OrtskurveModell#randpunkteZusammenstellen(Vector2D[])}.
 * /*from   w w w  . ja  va2s.  c o  m*/
 * @throws NoSuchMethodException 
 * @throws SecurityException 
 * @throws InvocationTargetException 
 * @throws IllegalAccessException 
 * @throws IllegalArgumentException 
 */
@Test
public void testRandpunkteZusammenstellen1() throws SecurityException, NoSuchMethodException,
        IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    // Das Modell wird initialisiert.
    this.ortskurveModell.setMesspunkte(this.test_messpunkte);
    this.ortskurveModell.setOrtskurve(this.ortskurve2d);
    this.ortskurveModell.setOptimalerAusgleichskreis(this.ortskurve);

    // Die zu testende Methode wird ausgefhrt.
    Method method = OrtskurveModell.class.getDeclaredMethod("randpunkteZusammenstellen", (Class[]) null);
    method.setAccessible(true);
    Vector2D[] randpunkte = (Vector2D[]) method.invoke(this.ortskurveModell, (Object[]) null);

    // Es wird berprft, ob die Anzahl der zusammengestellten Randpunkte korrekt ist.
    assertEquals(this.test_messpunkte.length + 8, randpunkte.length);

    // Es wird berprft, ob die Randpunkte korrekt zusammengestellt worden sind.
    assertEquals(this.test_messpunkte[0], randpunkte[0]);
    assertEquals(this.test_messpunkte[1], randpunkte[1]);
    assertEquals(new Vector2D(0, -0.5), randpunkte[2]);
    assertEquals(new Vector2D(2, -0.5), randpunkte[3]);
    assertEquals(new Vector2D(1, 0.5), randpunkte[4]);
    assertEquals(new Vector2D(1, -1.5), randpunkte[5]);
    assertEquals(new Vector2D(0, 0), randpunkte[6]);
    assertEquals(new Vector2D(2, 0), randpunkte[7]);
    assertEquals(new Vector2D(1, 1), randpunkte[8]);
    assertEquals(new Vector2D(1, -1), randpunkte[9]);
}

From source file:de.thkwalter.et.schlupfbezifferung.SchlupfbezifferungController.java

/**
 * Diese Methode berechnet den Drehpunkt der Schlupfgerade (in A). Der Drehpunkt liegt auf der gedrehten Ortskurve 
 * senkrecht unter dem Mittelpunkt./*  w  w w.  ja v a 2 s  .c  o  m*/
 * 
 * @return Der Drehpunkt der Schlupfgerade (in A)
 */
private Vector2D drehpunktSchlupfgeradeBerechnen() {
    // Der Mittelpunkt der gedrehten Ortskurve (in A) wird gelesen.
    Vector2D mittelpunktOrtskurve = this.schlupfbezifferungModell.getOrtskurve().getMittelpunktOrtskurve();

    // Der Radius der Ortskurve (in A) wird gelesen.
    double r = this.schlupfbezifferungModell.getOrtskurve().getRadiusOrtskurve();

    // Der Drehpunkt der Schupfgerade (in A) wird berechnet.
    Vector2D drehpunkt = mittelpunktOrtskurve.subtract(new Vector2D(0.0, r));

    // Der Drehpunkt der Schlupfgerade (in A) wird zurckgegeben.
    return drehpunkt;
}