Java Code Examples for processing.core.PApplet#atan2()

The following examples show how to use processing.core.PApplet#atan2() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaperScreen.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void drawOnTable() {
        if (!isDrawingOnDisplay) {
            return;
        }

//        PMatrix3D location = this.getLocation().get();
//        PMatrix3D t = tableInv.get();
//        t.apply(location);
//        PVector tableRelativePos = new PVector(t.m03, t.m13, t.m23);
        PVector p2 = getRelativePos(new PVector(20, 20, 0));
        PVector tableRelativePos = getRelativePos(new PVector(0, 0, 0));

        float r = PApplet.atan2(p2.y - tableRelativePos.y, p2.x - tableRelativePos.x);

        PMatrix3D locationInv = this.getLocation().get();
        locationInv.invert();
        currentGraphics.scale(1, -1, 1);
        currentGraphics.translate(0, -getSize().y, 0);
        currentGraphics.applyMatrix(locationInv);
        currentGraphics.applyMatrix(table);
        currentGraphics.translate(tableRelativePos.x, tableRelativePos.y);
        currentGraphics.rotate(r);
        currentGraphics.scale(1, -1, 1);
    }
 
Example 2
Source File: Papart.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Return the x,y positions of a 3D location projected onto a given
 * reference. The Z axis is the angle (in radians) given by the rotation of
 * the positionToFind.
 *
 * @param positionToFind
 * @param reference
 * @return
 */
public PVector projectPositionTo2D(PMatrix3D positionToFind,
        PMatrix3D reference,
        float referenceHeight) {
    PMatrix3D referenceInv = reference.get();
    referenceInv.invert();
    PMatrix3D relative = positionToFind.get();
    relative.preApply(referenceInv);

    PMatrix3D positionToFind2 = positionToFind.get();
    positionToFind2.translate(100, 0, 0);
    PMatrix3D relative2 = positionToFind2.get();
    relative2.preApply(referenceInv);

    PVector out = new PVector();
    float x = relative.m03 - relative2.m03;
    float y = relative.m13 - relative2.m13;
    out.z = PApplet.atan2(x, y);

    out.x = relative.m03;
    out.y = referenceHeight - relative.m13;

    return out;
}
 
Example 3
Source File: Papart.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Return the x,y positions of a 3D location projected onto a given
 * reference. The Z axis is the angle (in radians) given by the rotation of
 * the positionToFind.
 *
 * @param positionToFind
 * @param reference
 * @return
 */
public PVector projectPositionTo(PMatrix3D positionToFind,
        PaperScreen reference) {
    PMatrix3D referenceInv = reference.getLocation().get();
    referenceInv.invert();
    PMatrix3D relative = positionToFind.get();
    relative.preApply(referenceInv);

    PMatrix3D positionToFind2 = positionToFind.get();
    positionToFind2.translate(100, 0, 0);
    PMatrix3D relative2 = positionToFind2.get();
    relative2.preApply(referenceInv);

    PVector out = new PVector();
    float x = relative.m03 - relative2.m03;
    float y = relative.m13 - relative2.m13;
    out.z = PApplet.atan2(x, y);

    out.x = relative.m03;
    out.y = reference.drawingSize.y - relative.m13;

    return out;
}
 
Example 4
Source File: Utility.java    From Project-16x16 with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Calculates the angle between two PVectors where: East = 0; North = -1/2PI;
 * West = -PI; South = -3/2PI | 1/2PI
 * 
 * @param tail PVector Coordinate 1.
 * @param head PVector Coordinate 2.
 * @return float θ in radians.
 */
public static float angleBetween(PVector tail, PVector head) {
	float a = PApplet.atan2(tail.y - head.y, tail.x - head.x);
	if (a < 0) {
		a += PConstants.TWO_PI;
	}
	return a;
}