List of usage examples for org.apache.commons.math3.geometry.euclidean.twod Vector2D Vector2D
public Vector2D(double a, Vector2D u)
From source file:de.thkwalter.et.ortskurve.StartpunktbestimmungTest.java
/** * Test fr die Methode {@link Startpunktbestimmung#maxMesspunktBestimmen(ArrayList)}. * //from ww w.ja v a 2 s . c o m * @throws NoSuchMethodException * @throws SecurityException * @throws InvocationTargetException * @throws IllegalAccessException * @throws IllegalArgumentException */ @Test public void testMaxMesspunktBestimmen2() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { // Die Testdaten werden erzeugt. Vector2D messpunkt1 = new Vector2D(0.0, 2.0); Vector2D messpunkt2 = new Vector2D(0.0, 1.0); ArrayList<YKomponenteMesspunkt> yListe = new ArrayList<YKomponenteMesspunkt>(); yListe.add(new YKomponenteMesspunkt(messpunkt1)); yListe.add(new YKomponenteMesspunkt(messpunkt2)); // Die zu testende Methode wird aufgerufen Method methode = Startpunktbestimmung.class.getDeclaredMethod("maxMesspunktBestimmen", ArrayList.class); methode.setAccessible(true); Vector2D maxYMesspunkt = (Vector2D) methode.invoke(Startpunktbestimmung.class, yListe); // Es wird berprft, ob der korrekte Messpunkt zurckgegeben wird. assertEquals(messpunkt1, maxYMesspunkt); // Es wird berprft, ob der korrekte Messpunkt aus der Liste entfernt worden ist. assertEquals(1, yListe.size()); assertEquals(messpunkt2, yListe.get(0).getMesspunkt()); }
From source file:de.thkwalter.et.ortskurve.StartpunktbestimmungTest.java
/** * Test fr die Methode {@link Startpunktbestimmung#minMesspunktBestimmen(ArrayList)}. * //from w ww . j a v a 2s .c om * @throws NoSuchMethodException * @throws SecurityException * @throws InvocationTargetException * @throws IllegalAccessException * @throws IllegalArgumentException */ @Test public void testMinMesspunktBestimmen1() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { // Die Testdaten werden erzeugt. Vector2D messpunkt1 = new Vector2D(1.0, 0.0); Vector2D messpunkt2 = new Vector2D(2.0, 0.0); ArrayList<XKomponenteMesspunkt> xListe = new ArrayList<XKomponenteMesspunkt>(); xListe.add(new XKomponenteMesspunkt(messpunkt1)); xListe.add(new XKomponenteMesspunkt(messpunkt2)); // Die zu testende Methode wird aufgerufen Method methode = Startpunktbestimmung.class.getDeclaredMethod("minMesspunktBestimmen", ArrayList.class); methode.setAccessible(true); Vector2D minXMesspunkt = (Vector2D) methode.invoke(Startpunktbestimmung.class, xListe); // Es wird berprft, ob der korrekte Messpunkt zurckgegeben wird. assertEquals(messpunkt1, minXMesspunkt); // Es wird berprft, ob der korrekte Messpunkt aus der Liste entfernt worden ist. assertEquals(1, xListe.size()); assertEquals(messpunkt2, xListe.get(0).getMesspunkt()); }
From source file:de.thkwalter.et.ortskurve.StartpunktbestimmungTest.java
/** * Test fr die Methode {@link Startpunktbestimmung#minMesspunktBestimmen(ArrayList)}. * /* w ww. j a v a 2 s .c om*/ * @throws NoSuchMethodException * @throws SecurityException * @throws InvocationTargetException * @throws IllegalAccessException * @throws IllegalArgumentException */ @Test public void testMinMesspunktBestimmen2() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { // Die Testdaten werden erzeugt. Vector2D messpunkt1 = new Vector2D(0.0, 2.0); Vector2D messpunkt2 = new Vector2D(0.0, 1.0); ArrayList<YKomponenteMesspunkt> yListe = new ArrayList<YKomponenteMesspunkt>(); yListe.add(new YKomponenteMesspunkt(messpunkt1)); yListe.add(new YKomponenteMesspunkt(messpunkt2)); // Die zu testende Methode wird aufgerufen Method methode = Startpunktbestimmung.class.getDeclaredMethod("minMesspunktBestimmen", ArrayList.class); methode.setAccessible(true); Vector2D minYMesspunkt = (Vector2D) methode.invoke(Startpunktbestimmung.class, yListe); // Es wird berprft, ob der korrekte Messpunkt zurckgegeben wird. assertEquals(messpunkt2, minYMesspunkt); // Es wird berprft, ob der korrekte Messpunkt aus der Liste entfernt worden ist. assertEquals(1, yListe.size()); assertEquals(messpunkt1, yListe.get(0).getMesspunkt()); }
From source file:edu.unc.cs.gamma.rvo.Agent.java
/** * Solves a two-dimensional linear program subject to linear constraints * defined by lines and a circular constraint. * * @param numObstacleLines Count of obstacle lines. * @param beginLine The line on which the 2-D linear program failed. */// w w w . j av a 2s .c o m private void linearProgram3(int numObstacleLines, int beginLine) { double distance = 0.0; for (int i = beginLine; i < lines.size(); i++) { if (RVOMath.det(lines.get(i).direction, lines.get(i).point.subtract(newVelocity)) > distance) { // Result does not satisfy constraint of line i. final List<Line> projectedLines = new ArrayList<>(numObstacleLines); for (int j = 0; j < numObstacleLines; j++) { projectedLines.add(lines.get(j)); } for (int j = numObstacleLines; j < i; j++) { final double determinant = RVOMath.det(lines.get(i).direction, lines.get(j).direction); final Vector2D point; if (FastMath.abs(determinant) <= RVOMath.EPSILON) { // Line i and line j are parallel. if (lines.get(i).direction.dotProduct(lines.get(j).direction) > 0.0) { // Line i and line j point in the same direction. continue; } // Line i and line j point in opposite direction. point = lines.get(i).point.add(lines.get(j).point).scalarMultiply(0.5); } else { point = lines.get(i).point.add(lines.get(i).direction.scalarMultiply( RVOMath.det(lines.get(j).direction, lines.get(i).point.subtract(lines.get(j).point)) / determinant)); } final Vector2D direction = lines.get(j).direction.subtract(lines.get(i).direction).normalize(); projectedLines.add(new Line(point, direction)); } final Vector2D tempResult = newVelocity; if (linearProgram2(projectedLines, new Vector2D(-lines.get(i).direction.getY(), lines.get(i).direction.getX()), true) < projectedLines.size()) { // This should in principle not happen. The result is by // definition already in the feasible region of this linear // program. If it fails, it is due to small floating point // error, and the current result is kept. newVelocity = tempResult; } distance = RVOMath.det(lines.get(i).direction, lines.get(i).point.subtract(newVelocity)); } } }
From source file:de.thkwalter.et.ortskurve.OrtskurveModellTest.java
/** * Test der Methode {@link OrtskurveModell#randpunkteOrtskurveZusammenstellen(Ortskurve)}. * //from w w w .jav a 2 s.c o m * @throws SecurityException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalArgumentException * @throws IllegalAccessException */ @Test public void testRandpunkteOrtskurveZusammenstellen() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Die zu testende Methode wird ausgefhrt. Method methode = OrtskurveModell.class.getDeclaredMethod("randpunkteOrtskurveZusammenstellen", Ortskurve.class); methode.setAccessible(true); @SuppressWarnings("unchecked") ArrayList<Vector2D> randpunkteOrtskurve = (ArrayList<Vector2D>) methode.invoke(this.ortskurveModell, this.ortskurve); // Es wird berprft, ob die Liste die korrekten Randpunkte enthlt. assertEquals(4, randpunkteOrtskurve.size()); assertTrue(randpunkteOrtskurve.contains(new Vector2D(0, 0))); assertTrue(randpunkteOrtskurve.contains(new Vector2D(2, 0))); assertTrue(randpunkteOrtskurve.contains(new Vector2D(1, 1))); assertTrue(randpunkteOrtskurve.contains(new Vector2D(1, -1))); }
From source file:nova.core.render.model.TechneModelProvider.java
@Override public void load(InputStream stream) { try {//from w w w. j a va2 s.c o m Map<String, byte[]> zipContents = new HashMap<>(); ZipInputStream zipInput = new ZipInputStream(stream); ZipEntry entry; while ((entry = zipInput.getNextEntry()) != null) { byte[] data = new byte[(int) entry.getSize()]; // For some reason, using read(byte[]) makes reading stall upon reaching a 0x1E byte int i = 0; while (zipInput.available() > 0 && i < data.length) { data[i++] = (byte) zipInput.read(); } zipContents.put(entry.getName(), data); } byte[] modelXml = zipContents.get("model.xml"); if (modelXml == null) { throw new RenderException("Model " + name + " contains no model.xml file"); } DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(new ByteArrayInputStream(modelXml)); NodeList nodeListTechne = document.getElementsByTagName("Techne"); if (nodeListTechne.getLength() < 1) { throw new RenderException("Model " + name + " contains no Techne tag"); } NodeList nodeListModel = document.getElementsByTagName("Model"); if (nodeListModel.getLength() < 1) { throw new RenderException("Model " + name + " contains no Model tag"); } NamedNodeMap modelAttributes = nodeListModel.item(0).getAttributes(); if (modelAttributes == null) { throw new RenderException("Model " + name + " contains a Model tag with no attributes"); } NodeList textureSize = document.getElementsByTagName("TextureSize"); if (textureSize.getLength() == 0) throw new RenderException("Model has no texture size"); String[] textureDimensions = textureSize.item(0).getTextContent().split(","); double textureWidth = Integer.parseInt(textureDimensions[0]); double textureHeight = Integer.parseInt(textureDimensions[1]); NodeList shapes = document.getElementsByTagName("Shape"); for (int i = 0; i < shapes.getLength(); i++) { Node shape = shapes.item(i); NamedNodeMap shapeAttributes = shape.getAttributes(); if (shapeAttributes == null) { throw new RenderException("Shape #" + (i + 1) + " in " + name + " has no attributes"); } Node name = shapeAttributes.getNamedItem("name"); String shapeName = null; if (name != null) { shapeName = name.getNodeValue(); } if (shapeName == null) { shapeName = "Shape #" + (i + 1); } String shapeType = null; Node type = shapeAttributes.getNamedItem("type"); if (type != null) { shapeType = type.getNodeValue(); } if (shapeType != null && !cubeIDs.contains(shapeType)) { System.out.println( "Model shape [" + shapeName + "] in " + this.name + " is not a cube, ignoring"); continue; } boolean mirrored = false; String[] offset = new String[3]; String[] position = new String[3]; String[] rotation = new String[3]; String[] size = new String[3]; String[] textureOffset = new String[2]; NodeList shapeChildren = shape.getChildNodes(); for (int j = 0; j < shapeChildren.getLength(); j++) { Node shapeChild = shapeChildren.item(j); String shapeChildName = shapeChild.getNodeName(); String shapeChildValue = shapeChild.getTextContent(); if (shapeChildValue != null) { shapeChildValue = shapeChildValue.trim(); switch (shapeChildName) { case "IsMirrored": mirrored = !shapeChildValue.equals("False"); break; case "Offset": offset = shapeChildValue.split(","); break; case "Position": position = shapeChildValue.split(","); break; case "Rotation": rotation = shapeChildValue.split(","); break; case "Size": size = shapeChildValue.split(","); break; case "TextureOffset": textureOffset = shapeChildValue.split(","); break; } } } /* Generate new models Models in Techne are based on cubes. Each cube is, by default, skewed to the side. They are not centered. Everything is scaled by a factor of 16. The y coordinate is inversed, y = 24 is the surface The z coordinate is inverted, too. */ double positionX = Double.parseDouble(position[0]) / 16d; double positionY = (16 - Double.parseDouble(position[1])) / 16d; double positionZ = -Double.parseDouble(position[2]) / 16d; double sizeX = Double.parseDouble(size[0]) / 16d; double sizeY = Double.parseDouble(size[1]) / 16d; double sizeZ = Double.parseDouble(size[2]) / 16d; double offsetX = Double.parseDouble(offset[0]) / 16d; double offsetY = -Double.parseDouble(offset[1]) / 16d; double offsetZ = -Double.parseDouble(offset[2]) / 16d; double angleX = -Math.toRadians(Double.parseDouble(rotation[0])); double angleY = Math.toRadians(Double.parseDouble(rotation[1])); double angleZ = Math.toRadians(Double.parseDouble(rotation[2])); double textureOffsetU = Double.parseDouble(textureOffset[0]); double textureOffsetV = Double.parseDouble(textureOffset[1]); CubeTextureCoordinates textureCoordinates = new TechneCubeTextureCoordinates(textureWidth, textureHeight, textureOffsetU, textureOffsetV, sizeX, sizeY, sizeZ); final String modelName = shapeName; MeshModel modelPart = new MeshModel(modelName); BlockRenderPipeline.drawCube(modelPart, offsetX, offsetY - sizeY, offsetZ - sizeZ, offsetX + sizeX, offsetY, offsetZ, textureCoordinates); MatrixStack ms = new MatrixStack(); ms.translate(positionX, positionY, positionZ); ms.rotate(Vector3D.PLUS_J, angleY); ms.rotate(Vector3D.PLUS_I, angleX); ms.rotate(Vector3D.PLUS_K, angleZ); modelPart.matrix = ms; modelPart.textureOffset = new Vector2D(Integer.parseInt(textureOffset[0]), Integer.parseInt(textureOffset[1])); if (model.children.stream().anyMatch(m -> m.name.equals(modelName))) { throw new RenderException( "Model contained duplicate part name: '" + shapeName + "' node #" + i); } model.children.add(modelPart); } } catch (ZipException e) { throw new RenderException("Model " + name + " is not a valid zip file"); } catch (IOException e) { throw new RenderException("Model " + name + " could not be read", e); } catch (SAXException e) { throw new RenderException("Model " + name + " contains invalid XML", e); } catch (Exception e) { e.printStackTrace(); } }
From source file:nova.core.util.math.Vector2DUtil.java
/** * @return Creates a random unit vector//from w ww . j a va2 s.c o m */ public static Vector2D random() { Random random = new Random(); return new Vector2D(random.nextDouble(), random.nextDouble()).scalarMultiply(2).subtract(ONE); }
From source file:nova.core.util.math.Vector2DUtil.java
public static Vector2D max(Vector2D a, Vector2D b) { return new Vector2D(FastMath.max(a.getX(), b.getX()), FastMath.max(a.getY(), b.getY())); }
From source file:nova.core.util.math.Vector2DUtil.java
public static Vector2D min(Vector2D a, Vector2D b) { return new Vector2D(FastMath.min(a.getX(), b.getX()), FastMath.min(a.getY(), b.getY())); }
From source file:nova.core.util.math.Vector2DUtil.java
public static Vector2D reciprocal(Vector2D vec) { return new Vector2D(1 / vec.getX(), 1 / vec.getY()); }