public static double angleBetweenOriented(Tuple2d tip1, Tuple2d tail, Tuple2d tip2) { double a1 = angle(tail, tip1); double a2 = angle(tail, tip2); double angDel = a2 - a1; if (angDel <= -Math.PI) { return angDel + PI_2; } if (angDel > Math.PI) { return angDel - PI_2; } return angDel; }
/** * @see http://en.wikipedia.org/wiki/Transformation_matrix * @param pTuple * @param pAngle * @return */ public static Vector2d rotateCounterClockwise2d(Tuple2d pTuple, double pAngle) { double cosA = Math.cos(pAngle); double sinA = Math.sin(pAngle); return new Vector2d( pTuple.x * cosA - pTuple.y * sinA, pTuple.x * sinA + pTuple.y * cosA); }
/** * @see http://en.wikipedia.org/wiki/Transformation_matrix * @param pTuple * @param pAngle * @return */ public static Vector2d rotateClockwise2d(Tuple2d pTuple, double pAngle) { double cosA = Math.cos(pAngle); double sinA = Math.sin(pAngle); return new Vector2d( pTuple.x * cosA + pTuple.y * sinA, - pTuple.x * sinA + pTuple.y * cosA); }
public TextureFP(FacialPointType type, Tuple2d point) { this.type = type; this.x = (float) point.x; this.y = (float) point.y; }
@Override public void moveLoop(Loop<Bar> draggedLoop, Tuple2d offset) { // do nothing }
@Override public void moveLoop( Loop<Bar> draggedLoop, Tuple2d offset ) { return; // no thx! }
public static double angle(Tuple2d p0, Tuple2d p1) { double dx = p1.x - p0.x; double dy = p1.y - p0.y; return Math.atan2(dy, dx); }
public static double angle(Tuple2d p) { return Math.atan2(p.y, p.x); }
/** * <code> * <pre> * * unitVector * ^ * | * | * + -- ^ vectorToProject * | / * | / * | / * |/ * 0 * </pre> * </code> * * * @see http://en.wikipedia.org/wiki/Vector_projection * @param unitVector * @param vectorToProject * @return */ public static Vector2d orthogonalProjection(Vector2d unitVector, Tuple2d vectorToProject) { Vector2d n = new Vector2d(unitVector); n.normalize(); double px = vectorToProject.x; double py = vectorToProject.y; double ax = n.x; double ay = n.y; return new Vector2d( px * ax * ax + py * ax * ay, px * ax * ay + py * ay * ay ); }
public static Point2d sub(Tuple2d p1, Tuple2d p2) { return new Point2d(p1.x - p2.x, p1.y - p2.y ); }
/** * Computes the distance between this point and point p1. * * @param p0 * * @param p1 * the other point * @return */ private static double distance(Tuple2d p0, Tuple2d p1) { double dx, dy; dx = p0.x - p1.x; dy = p0.y - p1.y; return Math.sqrt(dx * dx + dy * dy); }
/** * Computes the distance between this point and point p1. * * @param p0 * * @param p1 * the other point * @return */ public static double distance(Tuple2d p0, Tuple2d p1) { double dx, dy; dx = p0.x - p1.x; dy = p0.y - p1.y; return Math.sqrt(dx * dx + dy * dy); }
/** * add two points * @param p point to fill * @param pA first point to add * @param pB second point to add */ public static Point2d add(final Point2d p, final Point2d pA, final Tuple2d pB) { p.x = pB.x + pA.x; p.y = pB.y + pA.y; return p; }
/** * add two points * @param p point to fill * @param x1Pixel first point to add * @param nPixel second point to add */ public static Point2d add(final Point2d pA, final Tuple2d v) { return add(new Point2d(), pA, v); }
/** Determinate if point is over line or on line. * @param pPoint point * @return point is over line or on line * TODO RENAME TO POINT_IN_FRONT */ public boolean inFront(Tuple2d pPoint) { return LineUtil.matrixDet(this.p1, this.p2, pPoint) >= 0; }
/** Determinate if point is under line. * <img src="doc-files/LineLinear2d_point.png"> * @param pPoint point * @return point is under line */ public boolean pointIsUnder(Tuple2d pPoint) { // XXX veryfy if it have sense return A * pPoint.x + B * pPoint.y + C > 0; }
/** Determinate if point is over line. * <img src="doc-files/LineLinear2d_point.png"> * @param pPoint point * @return point is over line */ public boolean pointIsOver(Tuple2d pPoint) { // XXX veryfy if it have sense return A * pPoint.x + B * pPoint.y + C < 0; }
/** Determinate if point is on line. * <img src="doc-files/LineLinear2d_point.png"> * <img src="doc-files/test.png"> * @param pPoint point * @return point is on line */ public boolean pointIsOn(Tuple2d pPoint) { return A * pPoint.x + B * pPoint.y + C == 0; }
/** Determinate if point is over line or on line. * <img src="doc-files/LineLinear2d_point.png"> * @param pPoint point * @return point is over line or on line */ public boolean pointInFront(Tuple2d pPoint) { // XXX veryfy if it have sense return A * pPoint.x + B * pPoint.y + C >= 0; }
/** Determinate if point is under line or on line. * <img src="doc-files/LineLinear2d_point.png"> * @param pPoint point * @return point is under line or on line */ public boolean pointInBack(Tuple2d pPoint) { // XXX veryfy if it have sense return A * pPoint.x + B * pPoint.y + C <= 0; }
/** Det of matrix. * @param A first column of matrix * @param B second column of matrix * @param Z third column of matrix * @return det of matrix */ public static double matrixDet(Point2d A, Point2d B, Tuple2d Z) { return A.x * B.y + B.x * Z.y + Z.x * A.y - Z.x * B.y - A.x * Z.y - B.x * A.y; }
/** * Cross product for 2d is same as doc * * @param u * @param v * @return * @see {http://mathworld.wolfram.com/CrossProduct.html} */ public static double cross(Tuple2d u, Tuple2d v) { return u.x * v.y - u.y * v.x; }
/** * Computes the dot product of the v1 vector and vector v2. Parameter can be * point then vector will start from origin and to point. * * @param v1 first vector * @param v2 second vector * @return dot product * XXX */ private final static double dot(Tuple2d v1, Tuple2d v2) { return v1.x*v2.x + v1.y*v2.y; }