public static double interiorAngleBetween(Tuple2d a, Tuple2d b, Tuple2d c) { Vector2d left = new Vector2d(b); Vector2d right = new Vector2d(c); left.sub(a); right.sub(b); // left.normalize(); // right.normalize(); return interiorAngle(left, right); }
public Vector2d project(Vector2d axis) { double min = axis.dot(vertices.get(0)); double max = min; for (int i = 0; i < vertices.size(); i++) { double p = axis.dot(vertices.get(i)); if (p < min) min = p; else if (p > max) max = p; } return new Vector2d(min, max); }
/** * @param BirdBody otherBird : le Bird que l'on voit peut-etre. * @param double distance : la ditance de decision. return TRUE si on le voit, FALSE sinon. */ protected boolean proximal(BirdBody otherBird, double distance) { Vector2d tmp; tmp = new Vector2d(((BirdBody) theSensor).position); tmp.moins(otherBird.position); // si on est trop loin tand-pis. if (tmp.length() > distance) return false; return true; }
public void getCoordSystem(Vector2d e0, Vector2d e1, Point2d origin) { skiaviewJNI.Matrix2d_getCoordSystem( swigCPtr, this, Vector2d.getCPtr(e0), e0, Vector2d.getCPtr(e1), e1, Point2d.getCPtr(origin), origin); }
public Matrix2d setCoordSystem(Vector2d e0, Vector2d e1, Point2d origin) { return new Matrix2d( skiaviewJNI.Matrix2d_setCoordSystem( swigCPtr, this, Vector2d.getCPtr(e0), e0, Vector2d.getCPtr(e1), e1, Point2d.getCPtr(origin), origin), false); }
public boolean isBlocked(Vector2d nextPos, int width, int height) { Rectangle tileRect = new Rectangle(0, 0, SIZE, SIZE); Rectangle objRect = new Rectangle(nextPos.getX(), nextPos.getY(), width, height); for (int y = 0; y < blocked.length; y++) { for (int x = 0; x < blocked[0].length; x++) { if (blocked[x][y]) { tileRect.setLocation(x * SIZE, y * SIZE); if (objRect.intersects(tileRect)) return true; } } } return false; }
public static void testAngleVector2dVector2d() { Vector2d testVec1 = new Vector2d(-9.37, 5.892); Vector2d testVec2 = new Vector2d(); // angle(v, v) should give 0 double angle = testVec1.angle(testVec1); assertEquals(0, angle, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_DOUBLE); // angle(v, -v) should give Math.PI testVec1.negate(testVec2); angle = testVec1.angle(testVec2); assertEquals(java.lang.Math.PI, angle, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_DOUBLE); }
// Override public int hashCode() { if (hashcode == 0) { // TODO: is this an efficient hash code? hashcode = center.hashCode() + (int) (33 * (radius + min_z + max_z)); } return hashcode; }
public ArrayList<Vector2d> clip(Vector2d v1, Vector2d v2, Vector2d reference, double o) { ArrayList<Vector2d> clipPoints = new ArrayList<Vector2d>(); double d1 = reference.dot(v1) - o; double d2 = reference.dot(v2) - o; // System.out.println("d1: " + d1 + " d2: " + d2 + " v1: " + v1 + " v2: " + v2 + " ref: " + // reference + " offset: " + o); if (d1 >= 0) clipPoints.add(v1); if (d2 >= 0) clipPoints.add(v2); if (d1 * d2 < 0) { Vector2d e = new Vector2d(v2.x - v1.x, v2.y - v1.y); double u = d1 / (d1 - d2); e = new Vector2d((e.x * u) + v1.x, (e.y * u) + v1.y); clipPoints.add(e); } return clipPoints; }
public static double interiorAngle(Vector2d a, Vector2d b) { if (cross(b, a) >= -10E-15) return PI - a.angle(b); else return 2 * PI - a.angle(b); }
public boolean offset(Vector2d vec, int segment) { return touchvgJNI.MgGroup_offset(swigCPtr, this, Vector2d.getCPtr(vec), vec, segment); }
public static Vector2d rotateRad(double x, double y, double radiants) { temp.set(x, y); return temp.rotateRad(radiants); }
public void TransformVectors(int count, Vector2d vectors) { skiaviewJNI.Matrix2d_TransformVectors( swigCPtr, this, count, Vector2d.getCPtr(vectors), vectors); }
public Matrix2d(Vector2d e0, Vector2d e1, Point2d origin) { this( skiaviewJNI.new_Matrix2d__SWIG_3( Vector2d.getCPtr(e0), e0, Vector2d.getCPtr(e1), e1, Point2d.getCPtr(origin), origin), true); }
public Vector2d intersect(Rectangle b) { double overlap = Double.MAX_VALUE; // depth Vector2d collisionNormal = null; // minimum penetration vector or collision normal ArrayList<Vector2d> aAxes = getEdgeNormals(); ArrayList<Vector2d> bAxes = b.getEdgeNormals(); for (int i = 0; i < aAxes.size(); i++) { Vector2d p1 = project(aAxes.get(i)); Vector2d p2 = b.project(aAxes.get(i)); if ((p1.x > p2.y || p2.x > p1.y)) // if they overlap they are intersecting on this axis return null; else { double o = Math.min(p1.y, p2.y) - Math.max(p1.x, p2.x); if (o < overlap) { overlap = o; collisionNormal = aAxes.get(i); } } } for (int i = 0; i < bAxes.size(); i++) { Vector2d p1 = project(bAxes.get(i)); Vector2d p2 = b.project(bAxes.get(i)); if ((p1.x > p2.y || p2.x > p1.y)) // if they overlap they are intersecting on this axis return null; else { double o = Math.min(p1.y, p2.y) - Math.max(p1.x, p2.x); if (o < overlap) { overlap = o; collisionNormal = bAxes.get(i); } } } // collision normal and penetration depth has been found // now we find the most perpendicular edges to the collision normal Line aEdge = bestEdge(collisionNormal); Line bEdge = b.bestEdge(new Vector2d(-collisionNormal.x, -collisionNormal.y)); // determine reference and incident edges Line reference, incident; Vector2d ref; boolean flipped = false; if (aEdge.toVector2d().dot(collisionNormal) <= bEdge.toVector2d().dot(collisionNormal)) { reference = aEdge; incident = bEdge; } else { reference = bEdge; incident = aEdge; flipped = true; } ref = reference.toVector2d().normalize(); double offset1 = ref.dot(reference.getPoint1()); ArrayList<Vector2d> clipPoints = clip(incident.getPoint1(), incident.getPoint2(), new Vector2d(-ref.x, -ref.y), -offset1); if (clipPoints.size() < 2) return null; System.out.println("clip1 success"); double offset2 = ref.dot(reference.getPoint2()); clipPoints = clip(clipPoints.get(0), clipPoints.get(1), ref, offset2); if (clipPoints.size() < 2) return null; System.out.println("clip2 success"); Vector2d refNormal = ref.getLeftNormal(); if (flipped) refNormal = new Vector2d(refNormal.x * -1, refNormal.y * -1); double max = refNormal.dot(reference.getPoint1()); if (refNormal.dot(clipPoints.get(0)) - max < 0.0) { clipPoints.remove(clipPoints.get(0)); if (!clipPoints.isEmpty()) if (refNormal.dot(clipPoints.get(0)) - max < 0.0) clipPoints.remove(clipPoints.get(0)); } if (!clipPoints.isEmpty()) { Vector2d collision = new Vector2d(0, 0); for (int i = 0; i < clipPoints.size(); i++) { collision = new Vector2d(collision.x + clipPoints.get(i).x, collision.y + clipPoints.get(i).y); } collision = new Vector2d(collision.x / clipPoints.size(), collision.y / clipPoints.size()); return collision; } else return null; }
public void getPosition(Vector2d dest) { dest.x = center.x; dest.y = center.y; }
public Matrix2d setToMirroring(Point2d pnt, Vector2d dir) { return new Matrix2d( skiaviewJNI.Matrix2d_setToMirroring__SWIG_2( swigCPtr, this, Point2d.getCPtr(pnt), pnt, Vector2d.getCPtr(dir), dir), false); }
public Matrix2d setToTranslation(Vector2d vec) { return new Matrix2d( skiaviewJNI.Matrix2d_setToTranslation(swigCPtr, this, Vector2d.getCPtr(vec), vec), false); }
public static double cross(double x1, double y1, double x2, double y2) { temp.set(x1, y1); return temp.cross(x2, y2); }
public static Vector2d rotateDeg(double x, double y, double degrees) { temp.set(x, y); return temp.rotate(degrees); }
public static double angleRad(double x1, double y1, double x2, double y2) { temp.set(x1, y1); return temp.angleRad(x2, y2); }
public boolean hasMirror(Vector2d reflex) { return skiaviewJNI.Matrix2d_hasMirror(swigCPtr, this, Vector2d.getCPtr(reflex), reflex); }
public Line bestEdge(Vector2d collisionNormal) // FIXME { double max = -Double.MAX_VALUE; int index = -1; System.out.println(collisionNormal); for (int i = 0; i < vertices.size(); i++) { double projection = collisionNormal.dot(vertices.get(i)); if (projection > max) { max = projection; index = i; } } // now we find the most perpendicular edge Vector2d v = vertices.get(index); Vector2d v1, v0; if (index + 1 == vertices.size()) v1 = vertices.get(0); else v1 = vertices.get(index + 1); if (index == 0) v0 = vertices.get(vertices.size() - 1); else v0 = vertices.get(index - 1); Vector2d left = new Vector2d(v.x - v1.x, v.y - v1.y); Vector2d right = new Vector2d(v.x - v0.x, v.y - v0.y); System.out.println("right: " + right + " left: " + left); if (Math.abs(right.dot(collisionNormal)) <= Math.abs(left.dot(collisionNormal))) { // System.out.println("return right"); v0.draw(); v.draw(); return new Line(v0, v); } else { // System.out.println("return left"); v.draw(); v1.draw(); return new Line(v, v1); } }
public static double dot(double x1, double y1, double x2, double y2) { temp.set(x1, y1); return temp.dot(x2, y2); }
public double distanceOnXYPlaneSquared(Vector2d v) { return ((x - v.getX()) * (x - v.getX())) + ((y - v.getY()) * (y - v.getY())); }
public static Matrix2d translation(Vector2d vec) { return new Matrix2d(skiaviewJNI.Matrix2d_translation(Vector2d.getCPtr(vec), vec), true); }
public static Matrix2d coordSystem(Vector2d e0, Vector2d e1, Point2d origin) { return new Matrix2d( skiaviewJNI.Matrix2d_coordSystem__SWIG_0( Vector2d.getCPtr(e0), e0, Vector2d.getCPtr(e1), e1, Point2d.getCPtr(origin), origin), true); }
public static Matrix2d mirroring(Point2d pnt, Vector2d dir) { return new Matrix2d( skiaviewJNI.Matrix2d_mirroring__SWIG_2( Point2d.getCPtr(pnt), pnt, Vector2d.getCPtr(dir), dir), true); }