Search in sources :

Example 21 with Vector2D

use of org.apache.commons.math3.geometry.euclidean.twod.Vector2D in project graphysica by Graphysica.

the class DroiteHorizontale method dessiner.

@Override
public void dessiner(@NotNull final Canvas toile, @NotNull final Repere repere) {
    if (isVisible(toile, repere)) {
        final double ordonneeVirtuelle = repere.ordonneeVirtuelle(getOrdonnee());
        origineTrace = new Vector2D(0, ordonneeVirtuelle);
        arriveeTrace = new Vector2D(toile.getWidth(), ordonneeVirtuelle);
        dessinerContinue(toile.getGraphicsContext2D());
    }
}
Also used : Vector2D(org.apache.commons.math3.geometry.euclidean.twod.Vector2D)

Example 22 with Vector2D

use of org.apache.commons.math3.geometry.euclidean.twod.Vector2D in project graphysica by Graphysica.

the class Etiquette method distance.

@Override
public double distance(@NotNull final Vector2D curseur, @NotNull final Repere repere) {
    final Vector2D coinSuperieurGauche = repere.positionVirtuelle(getPositionAncrage()).add(getPositionRelative());
    final Vector2D coinSuperieurDroit = coinSuperieurGauche.add(new Vector2D(getLargeur(), 0));
    final Vector2D coinInferieurDroit = coinSuperieurDroit.add(new Vector2D(0, getHauteur()));
    final Vector2D coinInferieurGauche = coinInferieurDroit.add(new Vector2D(-getLargeur(), 0));
    if (curseur.getX() >= coinSuperieurGauche.getX() && curseur.getX() <= coinSuperieurDroit.getX() && curseur.getY() >= coinSuperieurDroit.getY() && curseur.getY() <= coinInferieurDroit.getY()) {
        return 0;
    }
    return Math.min(new Segment(coinSuperieurGauche, coinSuperieurDroit, null).distance(curseur), Math.min(new Segment(coinSuperieurDroit, coinInferieurDroit, null).distance(curseur), Math.min(new Segment(coinInferieurDroit, coinInferieurGauche, null).distance(curseur), new Segment(coinInferieurGauche, coinSuperieurGauche, null).distance(curseur))));
}
Also used : Vector2D(org.apache.commons.math3.geometry.euclidean.twod.Vector2D) Segment(org.apache.commons.math3.geometry.euclidean.twod.Segment)

Example 23 with Vector2D

use of org.apache.commons.math3.geometry.euclidean.twod.Vector2D in project graphysica by Graphysica.

the class RepereTest method testPositionVirtuelle.

@Test
public void testPositionVirtuelle() {
    assertEquals(new Vector2D(500 - 2 * 50, 500 + 2 * 50), repere.positionVirtuelle(new Vector2D(-2, -2)));
    assertEquals(new Vector2D(500 - 2 * 50, 500 + 50), repere.positionVirtuelle(new Vector2D(-2, -1)));
    assertEquals(new Vector2D(500 - 50, 500 + 2 * 50), repere.positionVirtuelle(new Vector2D(-1, -2)));
    assertEquals(new Vector2D(500 - 50, 500 + 50), repere.positionVirtuelle(new Vector2D(-1, -1)));
    assertEquals(new Vector2D(500 - 50, 500), repere.positionVirtuelle(new Vector2D(-1, 0)));
    assertEquals(new Vector2D(500, 500 + 50), repere.positionVirtuelle(new Vector2D(0, -1)));
    assertEquals(new Vector2D(500, 500), repere.positionVirtuelle(new Vector2D(0, 0)));
    assertEquals(new Vector2D(500, 500 - 50), repere.positionVirtuelle(new Vector2D(0, 1)));
    assertEquals(new Vector2D(500 + 50, 500), repere.positionVirtuelle(new Vector2D(1, 0)));
    assertEquals(new Vector2D(500 + 50, 500 - 50), repere.positionVirtuelle(new Vector2D(1, 1)));
    assertEquals(new Vector2D(500 + 50, 500 - 2 * 50), repere.positionVirtuelle(new Vector2D(1, 2)));
    assertEquals(new Vector2D(500 + 2 * 50, 500 - 50), repere.positionVirtuelle(new Vector2D(2, 1)));
    assertEquals(new Vector2D(500 + 2 * 50, 500 - 2 * 50), repere.positionVirtuelle(new Vector2D(2, 2)));
}
Also used : Vector2D(org.apache.commons.math3.geometry.euclidean.twod.Vector2D) Test(org.junit.Test)

Example 24 with Vector2D

use of org.apache.commons.math3.geometry.euclidean.twod.Vector2D in project graphysica by Graphysica.

the class RepereTest method initialiser.

@Before
public void initialiser() {
    origineVirtuelle = new Vector2D(500, 500);
    echelle = new Vector2D(50, 50);
    repere = new Repere(origineVirtuelle, echelle);
}
Also used : Vector2D(org.apache.commons.math3.geometry.euclidean.twod.Vector2D) Before(org.junit.Before)

Example 25 with Vector2D

use of org.apache.commons.math3.geometry.euclidean.twod.Vector2D in project chordatlas by twak.

the class Concarnie method removeOverlaps.

private void removeOverlaps(List<Problem> current) {
    Closer<Problem> closer = new Closer();
    for (Problem a : current) {
        try {
            Region<Euclidean2D> ar = a.chull.createRegion();
            b: for (Problem b : current) if (a != b)
                for (Vector2D v : b.chull.getVertices()) {
                    Location vInA = ar.checkPoint(v);
                    if (vInA == Location.BOUNDARY || vInA == Location.INSIDE) {
                        closer.add(a, b);
                        continue b;
                    }
                }
        } catch (InsufficientDataException th) {
        } catch (MathIllegalArgumentException th) {
        }
    }
    for (Set<Problem> close : closer.close()) {
        List<Problem> intersecting = new ArrayList<Problem>(close);
        Collections.sort(intersecting, (a, b) -> -Double.compare(a.area(), b.area()));
        for (int i = 1; i < intersecting.size(); i++) {
            Problem togo = intersecting.get(i);
            togo.addPortal();
            current.remove(togo);
        }
    }
}
Also used : InsufficientDataException(org.apache.commons.math3.exception.InsufficientDataException) ArrayList(java.util.ArrayList) Euclidean2D(org.apache.commons.math3.geometry.euclidean.twod.Euclidean2D) Paint(java.awt.Paint) Vector2D(org.apache.commons.math3.geometry.euclidean.twod.Vector2D) MathIllegalArgumentException(org.apache.commons.math3.exception.MathIllegalArgumentException) Location(org.apache.commons.math3.geometry.partitioning.Region.Location)

Aggregations

Vector2D (org.apache.commons.math3.geometry.euclidean.twod.Vector2D)26 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Point2d (javax.vecmath.Point2d)4 Point3d (javax.vecmath.Point3d)4 Tweed (org.twak.tweed.Tweed)4 TweedSettings (org.twak.tweed.TweedSettings)4 Line (org.twak.utils.Line)4 Material (com.jme3.material.Material)3 ColorRGBA (com.jme3.math.ColorRGBA)3 Geometry (com.jme3.scene.Geometry)3 Mesh (com.jme3.scene.Mesh)3 Node (com.jme3.scene.Node)3 VertexBuffer (com.jme3.scene.VertexBuffer)3 Collections (java.util.Collections)3 Comparator (java.util.Comparator)3