Java Code Examples for javax.vecmath.Vector3f#angle()

The following examples show how to use javax.vecmath.Vector3f#angle() . 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: Stroke.java    From justaline-android with Apache License 2.0 5 votes vote down vote up
private float calculateAngle(int index) {
    Vector3f p1 = points.get(index - 1);
    Vector3f p2 = points.get(index);
    Vector3f p3 = points.get(index + 1);

    Vector3f n1 = new Vector3f();
    n1.sub(p2, p1);

    Vector3f n2 = new Vector3f();
    n2.sub(p3, p2);

    return n1.angle(n2);
}
 
Example 2
Source File: Stroke.java    From justaline-android with Apache License 2.0 5 votes vote down vote up
private void subdivideSection(int s, float maxAngle, int iteration) {
    if (iteration == 6) {
        return;
    }

    Vector3f p1 = points.get(s);
    Vector3f p2 = points.get(s + 1);
    Vector3f p3 = points.get(s + 2);

    Vector3f n1 = new Vector3f();
    n1.sub(p2, p1);

    Vector3f n2 = new Vector3f();
    n2.sub(p3, p2);

    float angle = n1.angle(n2);

    // If angle is too big, add points
    if (angle > maxAngle) {
        n1.scale(0.5f);
        n2.scale(0.5f);
        n1.add(p1);
        n2.add(p2);

        points.add(s + 1, n1);
        points.add(s + 3, n2);

        subdivideSection(s + 2, maxAngle, iteration + 1);
        subdivideSection(s, maxAngle, iteration + 1);
    }
}