Calculate angle at B, given 3 positions via Vector3d - Java java.lang

Java examples for java.lang:Math Vector

Description

Calculate angle at B, given 3 positions via Vector3d

Demo Code

/***//  w  w w.j av a  2  s .c  o m
 * Copyright (C) 2010 Johan Henriksson
 * This code is under the Endrov / BSD license. See www.endrov.net
 * for the full text and how to cite.
 */
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.vecmath.Vector3d;

public class Main{
    /**
     * Calculate angle at B, given 3 positions
     */
    public static double midAngle(Vector3d posA, Vector3d posB,
            Vector3d posC) {
        Vector3d ba = new Vector3d(posA);
        ba.sub(posB);
        Vector3d bc = new Vector3d(posC);
        bc.sub(posB);
        return Math.acos(ba.dot(bc) / (ba.length() * bc.length()));
    }
}

Related Tutorials