
org.bimserver.geometry.Vector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of PluginBase Show documentation
Show all versions of PluginBase Show documentation
Base project for BIMserver plugin development. Some plugins mights also need the Shared library
package org.bimserver.geometry;
/******************************************************************************
* Copyright (C) 2009-2016 BIMserver.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see {@literal }.
*****************************************************************************/
public class Vector {
// dot product (3D) which allows vector operations in arguments
public static float dot(float[] u,float[] v) {
return ((u[X] * v[X]) + (u[Y] * v[Y]) + (u[Z] * v[Z]));
}
public static float[] minus(float[] u, float[] v){
return new float[]{u[X]-v[X],u[Y]-v[Y],u[Z]-v[Z]};
}
public static float[] addition(float[] u, float[] v){
return new float[]{u[X]+v[X],u[Y]+v[Y],u[Z]+v[Z]};
}
//scalar product
public static float[] scalarProduct(float r, float[] u){
return new float[]{u[X]*r,u[Y]*r,u[Z]*r};
}
// (cross product)
public static float[] crossProduct(float[] u, float[] v){
return new float[]{(u[Y]*v[Z]) - (u[Z]*v[Y]),(u[Z]*v[X]) - (u[X]*v[Z]),(u[X]*v[Y]) - (u[Y]*v[X])};
}
//mangnatude or length
public static float length(float[] u){
return (float) Math.abs(Math.sqrt((u[X] *u[X]) + (u[Y] *u[Y]) + (u[Z] *u[Z])));
}
public static final int X = 0;
public static final int Y = 1;
public static final int Z = 2;
public static void normalize(float[] rayDir) {
float l = length(rayDir);
rayDir[0] = rayDir[0] / l;
rayDir[1] = rayDir[1] / l;
rayDir[2] = rayDir[2] / l;
}
public static void dump(float[] v) {
System.out.println(v[0] + ", " + v[1] + ", " + v[2] + (v.length == 4 ? (", " + v[3]) : ""));
}
public static void dump(String pre, float[] v) {
System.out.println(pre + ": " + v[0] + ", " + v[1] + ", " + v[2] + (v.length == 4 ? (", " + v[3]) : ""));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy