Newer
Older
EPQ-3D-renderer / src / main / java / uk / org / floop / epq3d / Vector3D.java
@cory cory on 10 Jan 2023 1 KB - added http stuff
package uk.org.floop.epq3d;// technically not required as vectors have the same information as points, but it's useful to have separate vector and point things..

public class Vector3D {
    public double x;
    public double y;
    public double z;

    public Vector3D(double _x, double _y, double _z){
        x = _x;
        y = _y;
        z = _z;
    }
    public void createFrom2Points(Point3D start, Point3D end){
            x = end.x - start.x;
        y = end.y - start.y;
        z = end.z - start.z;
    }
    public double getLength(){
        return Math.sqrt(x*x + y*y + z*z);
    }
    public double angleTo(Vector3D vec2){
        return Math.acos(
                (x*vec2.x + y*vec2.y + z*vec2.z)
                        /( //-----------------------------------------------------------
                        Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)) *
                        Math.sqrt(Math.pow(vec2.x,  2) + Math.pow(vec2.y, 2) + Math.pow(vec2.z, 2))));
    }
    public Vector3D cross(Vector3D vec2){
        return new Vector3D(
                y*vec2.z - z*vec2.y,
                z*vec2.x - x*vec2.z,
                x*vec2.y - y*vec2.x);
    }
    public double dot(Vector3D vec2){
        return x*vec2.x + y* vec2.y+z* vec2.z;
    }
}