If you think the Android project Thrift-box listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.github.mikephil.charting.matrix;
//fromwww.java2s.com/**
* Simple 3D vector class. Handles basic vector math for 3D vectors.
*/publicfinalclass Vector3 {
publicfloat x;
publicfloat y;
publicfloat z;
publicstaticfinal Vector3 ZERO = new Vector3(0, 0, 0);
publicstaticfinal Vector3 UNIT_X = new Vector3(1, 0, 0);
publicstaticfinal Vector3 UNIT_Y = new Vector3(0, 1, 0);
publicstaticfinal Vector3 UNIT_Z = new Vector3(0, 0, 1);
public Vector3() {
}
public Vector3(float[] array)
{
set(array[0], array[1], array[2]);
}
public Vector3(float xValue, float yValue, float zValue) {
set(xValue, yValue, zValue);
}
public Vector3(Vector3 other) {
set(other);
}
publicfinalvoid add(Vector3 other) {
x += other.x;
y += other.y;
z += other.z;
}
publicfinalvoid add(float otherX, float otherY, float otherZ) {
x += otherX;
y += otherY;
z += otherZ;
}
publicfinalvoid subtract(Vector3 other) {
x -= other.x;
y -= other.y;
z -= other.z;
}
publicfinalvoid subtractMultiple(Vector3 other, float multiplicator)
{
x -= other.x * multiplicator;
y -= other.y * multiplicator;
z -= other.z * multiplicator;
}
publicfinalvoid multiply(float magnitude) {
x *= magnitude;
y *= magnitude;
z *= magnitude;
}
publicfinalvoid multiply(Vector3 other) {
x *= other.x;
y *= other.y;
z *= other.z;
}
publicfinalvoid divide(float magnitude) {
if (magnitude != 0.0f) {
x /= magnitude;
y /= magnitude;
z /= magnitude;
}
}
publicfinalvoid set(Vector3 other) {
x = other.x;
y = other.y;
z = other.z;
}
publicfinalvoid set(float xValue, float yValue, float zValue) {
x = xValue;
y = yValue;
z = zValue;
}
publicfinalfloat dot(Vector3 other) {
return (x * other.x) + (y * other.y) + (z * other.z);
}
publicfinal Vector3 cross(Vector3 other) {
returnnew Vector3(y * other.z - z * other.y,
z * other.x - x * other.z,
x * other.y - y * other.x);
}
publicfinalfloat length() {
return (float) Math.sqrt(length2());
}
publicfinalfloat length2() {
return (x * x) + (y * y) + (z * z);
}
publicfinalfloat distance2(Vector3 other) {
float dx = x - other.x;
float dy = y - other.y;
float dz = z - other.z;
return (dx * dx) + (dy * dy) + (dz * dz);
}
publicfinalfloat normalize() {
finalfloat magnitude = length();
// TODO: I'm choosing safety over speed here.
if (magnitude != 0.0f) {
x /= magnitude;
y /= magnitude;
z /= magnitude;
}
return magnitude;
}
publicfinalvoid zero() {
set(0.0f, 0.0f, 0.0f);
}
publicfinalboolean pointsInSameDirection(Vector3 other) {
return this.dot(other) > 0;
}
}