Example usage for org.apache.commons.math.geometry Vector3D Vector3D

List of usage examples for org.apache.commons.math.geometry Vector3D Vector3D

Introduction

In this page you can find the example usage for org.apache.commons.math.geometry Vector3D Vector3D.

Prototype

public Vector3D(double x, double y, double z) 

Source Link

Document

Simple constructor.

Usage

From source file:com.l2jserver.util.geometry.Coordinate.java

/**
 * Creates a new coordinate/*from ww  w  . j a  va2 s  . c o  m*/
 * 
 * @param x
 *            the x point
 * @param y
 *            the y point
 * @param z
 *            the z point
 */
protected Coordinate(int x, int y, int z) {
    this.vector = new Vector3D(x, y, z);
}

From source file:magma.util.geometry.GeometryTest.java

@Test
public void testIsInsidePolygon() {
    double[][] points = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
    Vector3D[] polygon = Geometry.getPolygon(points);

    // point outside
    assertEquals(false, Geometry.isInsidePolygon(new Vector3D(1, 1, 0), polygon));
    assertEquals(false, Geometry.isInsidePolygon(new Vector3D(-1, 1, 0), polygon));
    // point inside
    assertEquals(true, Geometry.isInsidePolygon(new Vector3D(0, 0, 0), polygon));
    // point on corner
    assertEquals(true, Geometry.isInsidePolygon(new Vector3D(0, 1, 0), polygon));
    // point on edge
    assertEquals(true, Geometry.isInsidePolygon(new Vector3D(0.5, 0.5, 0), polygon));
}

From source file:magma.util.geometry.PositionOrientation.java

public static PositionOrientation average(PositionOrientation[] result) {
    // float angle = averageAngle(angles);
    double x = 0.0;
    double y = 0.0;
    double z = 0.0;

    // average position
    for (PositionOrientation value : result) {
        x += value.getPosition().getX();
        y += value.getPosition().getY();
        z += value.getPosition().getZ();
    }//from   ww  w .j av a 2  s.c om
    if (result.length > 1) {
        x /= result.length;
        y /= result.length;
        z /= result.length;
    }
    Vector3D pos = new Vector3D(x, y, z);

    // average angles
    Angle[] angles = new Angle[result.length];
    for (int i = 0; i < result.length; i++) {
        angles[i] = result[i].getOrientationX();
    }
    Angle angle = Angle.average(angles);
    return new PositionOrientation(pos, angle);
}

From source file:magma.agent.worldmodel.impl.ThisPlayerTest.java

/**
 * Test method for// w ww. j a v a  2 s.  c  o  m
 * {@link magma.agent.worldmodel.impl.ThisPlayer#isInsidePolygonXY(org.apache.commons.math.geometry.Vector3D, org.apache.commons.math.geometry.Vector3D[])}
 * .
 */
@Test
public void testIsInsidePolygonXY() {
    Vector3D[] polygon = new Vector3D[4];
    polygon[0] = new Vector3D(0, 1, 0);
    polygon[1] = new Vector3D(1, 1, 0);
    polygon[2] = new Vector3D(1, -1, 0);
    polygon[3] = new Vector3D(0, -1, 0);

    testee.setPosition(new Vector3D(2.0, 0.0, 0.0));
    testee.setHorizontalAngle(Angle.deg(90));

    assertEquals(false, testee.isInsidePolygonXY(new Vector3D(0, 0, 0), polygon));
    assertEquals(false, testee.isInsidePolygonXY(new Vector3D(2, -0.1, 0), polygon));
    assertEquals(true, testee.isInsidePolygonXY(new Vector3D(1.01, 0.99, 0), polygon));
    assertEquals(true, testee.isInsidePolygonXY(new Vector3D(2.9, 0.99, 0), polygon));
}

From source file:magma.agent.worldmodel.impl.SerializationTest.java

@Test
public void testBallSerialization() throws Exception {
    VisibleObjectPerceptor vision = new VisibleObjectPerceptor("test", new Vector3D(1.0, 2.0, 3.0));
    thisPlayer.setPosition(new Vector3D(4.0, -2.0, 1.0));
    Ball testee = new Ball();
    testee.update(vision, 1.0f, thisPlayer);

    Ball result = (Ball) SerializationUtil.doubleSerialize(testee);
    assertEquals(testee, result);/*from   w  w w . j  a v a 2s.  c  o m*/
}

From source file:magma.util.geometry.Geometry.java

/**
 * Converts the passed points to a Vector3D array representing a polygon
 * @param points the corner points (x,y)
 * @return a Vector3D array representing a polygon
 *//*  w  w  w  . ja v a  2s  . com*/
public static Vector3D[] getPolygon(double[][] points) {
    Vector3D[] polygon = new Vector3D[points.length];
    for (int i = 0; i < points.length; i++) {
        double[] point = points[i];
        polygon[i] = new Vector3D(point[0], point[1], 0);
    }
    return polygon;
}

From source file:magma.agent.perception.impl.GyroPerceptor.java

/**
 * Assignment constructor//from w  w  w  .j a v  a 2 s  . com
 * 
 * @param name Perceptor name
 * @param rotationX X rotation
 * @param rotationY Y rotation
 * @param rotationZ Z rotation
 */
public GyroPerceptor(String name, float rotationX, float rotationY, float rotationZ) {
    super(name);
    this.vector = new Vector3D(rotationX, rotationY, rotationZ);
}

From source file:magma.agent.worldmodel.impl.GlobalMapTest.java

@Test
public void testUpdatePlayers() {
    testee.thisPlayer = new ThisPlayer("self", 0);
    testee.thisPlayer.setPosition(new Vector3D(0.0, 0.0, 0.0));
    PlayerPos playerVision = new PlayerPos(new Vector3D(2.0, 3.0, 0.0), 1, "test");
    List<PlayerPos> playersVision = new ArrayList<PlayerPos>();
    playersVision.add(playerVision);// w w  w . ja  va2  s.  c  o  m
    expect(perceptionMock.getVisiblePlayers()).andStubReturn(playersVision);
    replay(perceptionMock);

    testee.updatePlayers(perceptionMock);

    List<IPlayer> players = testee.getVisiblePlayers();
    assertEquals(1, players.size());
    IPlayer player = players.get(0);
    assertEquals(1, player.getID());
    assertEquals("test", player.getTeamname());

    // test clear of list if called twice
    testee.updatePlayers(perceptionMock);
    assertEquals(1, testee.getVisiblePlayers().size());

}

From source file:magma.agent.worldmodel.localizer.impl.LocalizerBaseTest.java

@Before
public void setUp() {
    G1L = createMock(ILocalizationFlag.class);
    expect(G1L.getKnownPosition())//from   w w  w.  jav a  2  s.  co m
            .andStubReturn(new Vector3D(IServerConfigFilesConstants.LANDMARK_POSITIONS[0][0],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[0][1],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[0][2]));

    G2L = createMock(ILocalizationFlag.class);
    expect(G2L.getKnownPosition())
            .andStubReturn(new Vector3D(IServerConfigFilesConstants.LANDMARK_POSITIONS[1][0],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[1][1],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[1][2]));

    G1R = createMock(ILocalizationFlag.class);
    expect(G1R.getKnownPosition())
            .andStubReturn(new Vector3D(IServerConfigFilesConstants.LANDMARK_POSITIONS[2][0],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[2][1],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[2][2]));

    G2R = createMock(ILocalizationFlag.class);
    expect(G2R.getKnownPosition())
            .andStubReturn(new Vector3D(IServerConfigFilesConstants.LANDMARK_POSITIONS[3][0],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[3][1],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[3][2]));

    F1L = createMock(ILocalizationFlag.class);
    expect(F1L.getKnownPosition())
            .andStubReturn(new Vector3D(IServerConfigFilesConstants.LANDMARK_POSITIONS[4][0],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[4][1],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[4][2]));

    F2L = createMock(ILocalizationFlag.class);
    expect(F2L.getKnownPosition())
            .andStubReturn(new Vector3D(IServerConfigFilesConstants.LANDMARK_POSITIONS[5][0],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[5][1],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[5][2]));

    F1R = createMock(ILocalizationFlag.class);
    expect(F1R.getKnownPosition())
            .andStubReturn(new Vector3D(IServerConfigFilesConstants.LANDMARK_POSITIONS[6][0],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[6][1],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[6][2]));

    F2R = createMock(ILocalizationFlag.class);
    expect(F2R.getKnownPosition())
            .andStubReturn(new Vector3D(IServerConfigFilesConstants.LANDMARK_POSITIONS[7][0],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[7][1],
                    IServerConfigFilesConstants.LANDMARK_POSITIONS[7][2]));

    flags = new HashMap<String, ILocalizationFlag>();
}

From source file:magma.agent.behavior.complex.GetInScorePositionTest.java

@Test
public void testPerform() {
    thisPlayer.setPosition(new Vector3D(0, 0, 0));
    expect(worldModelMock.getBall()).andReturn(ballMock);
    expect(worldModelMock.getThisPlayer()).andReturn(thisPlayer);
    expect(worldModelMock.getOtherGoalPosition()).andReturn(new Vector3D(6.0, 0.0, 0.0));
    Vector3D ballPosition = new Vector3D(2.0, 0.0, 0.0);
    expect(ballMock.getPosition()).andReturn(ballPosition);
    // this is the expected position
    replay(worldModelMock, ballMock);/*from w  w  w.ja va  2  s.c  o  m*/

    double[] result = testee.getPosition();

    assertEquals(1.75, result[0], 0.001);
    assertEquals(0.0, result[1], 0.001);
    assertEquals(0.0, result[2], 0.001);

}