mirror of
https://github.com/SimplexDevelopment/Polarize.git
synced 2025-07-02 06:36:41 +00:00
Update
This commit is contained in:
42
Converter/.gitignore
vendored
Normal file
42
Converter/.gitignore
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
.gradle
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
15
Converter/build.gradle
Normal file
15
Converter/build.gradle
Normal file
@ -0,0 +1,15 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'io.github.simplexdev'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
dependencies {
|
||||
implementation 'org.jetbrains:annotations:24.0.0'
|
||||
testImplementation 'org.mockito:mockito-core:4.11.0'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package io.github.simplexdev.polarize.api.rotation;
|
||||
|
||||
import io.github.simplexdev.polarize.api.units.Theta;
|
||||
|
||||
public interface IAxisAngle {
|
||||
double getX();
|
||||
|
||||
double getY();
|
||||
|
||||
double getZ();
|
||||
|
||||
Theta getAngle();
|
||||
|
||||
IAxisAngle negate();
|
||||
|
||||
IAxisAngle normalize();
|
||||
|
||||
IAxisAngle inverse();
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
package io.github.simplexdev.polarize.api.rotation;
|
||||
|
||||
import io.github.simplexdev.polarize.api.spatial.IVector;
|
||||
|
||||
/**
|
||||
* Represents the rotation of an object in 3D space.
|
||||
*/
|
||||
public interface IQuaternion {
|
||||
/**
|
||||
* Adds a fixed length to this quaternion.
|
||||
*
|
||||
* @param add The amount to add.
|
||||
* @return The result of the addition.
|
||||
*/
|
||||
IQuaternion add(double add);
|
||||
|
||||
/**
|
||||
* Adds this quaternion to another quaternion.
|
||||
*
|
||||
* @param quaternion The quaternion to add.
|
||||
* @return The result of the addition.
|
||||
*/
|
||||
IQuaternion add(IQuaternion quaternion);
|
||||
|
||||
/**
|
||||
* Multiplies this quaternion by a fixed length.
|
||||
*
|
||||
* @param multiply The scalar to multiply by.
|
||||
* @return The result of the multiplication.
|
||||
*/
|
||||
IQuaternion multiply(double multiply);
|
||||
|
||||
/**
|
||||
* Multiplies this quaternion by another quaternion.
|
||||
*
|
||||
* @param quaternion The quaternion to multiply by.
|
||||
* @return The result of the multiplication.
|
||||
*/
|
||||
IQuaternion multiply(IQuaternion quaternion);
|
||||
|
||||
/**
|
||||
* Returns a normalized quaternion that has the same orientation as this quaternion.
|
||||
* <p>
|
||||
* A normalized quaternion has a magnitude of 1 and represents the same
|
||||
* orientation as the original quaternion. An ArithmeticException is thrown
|
||||
* if the magnitude of the quaternion is zero, as it is impossible to
|
||||
* normalize a quaternion with a magnitude of zero.
|
||||
*
|
||||
* @return A normalized quaternion that has the same orientation as this quaternion.
|
||||
* @throws ArithmeticException If this quaternion has a magnitude of zero.
|
||||
*/
|
||||
IQuaternion normalize();
|
||||
|
||||
/**
|
||||
* Returns the inverse of this quaternion.
|
||||
* <p>
|
||||
* In mathematics, the inverse of a quaternion is a value that,
|
||||
* when multiplied by the original quaternion, results in the identity quaternion
|
||||
* (i.e., a quaternion with a scalar part of 1 and a vector part of 0).
|
||||
* <p>
|
||||
* The inverse of a quaternion is defined as the conjugate of the quaternion
|
||||
* divided by its magnitude.
|
||||
*
|
||||
* @return the inverse of this quaternion
|
||||
* @throws ArithmeticException if the magnitude of this quaternion is zero.
|
||||
*/
|
||||
IQuaternion inverse() throws ArithmeticException;
|
||||
|
||||
/**
|
||||
* Returns the conjugate of this quaternion.
|
||||
* <p>
|
||||
* In mathematics, the conjugate of a complex number or quaternion is a value
|
||||
* obtained by changing the sign of its imaginary part.
|
||||
* <p>
|
||||
* Specifically, for a complex number a + bi, the conjugate is a - bi,
|
||||
* where a and b are real numbers and i is the imaginary unit.
|
||||
* <p>
|
||||
* For a quaternion a + bi + cj + dk, the conjugate is a - bi - cj - dk,
|
||||
* where a, b, c, and d are real numbers and i, j, and k are imaginary units.
|
||||
*
|
||||
* @return the conjugate of this quaternion
|
||||
*/
|
||||
IQuaternion conjugate();
|
||||
|
||||
/**
|
||||
* Returns the magnitude of this quaternion.
|
||||
* <p>
|
||||
* The magnitude of a quaternion is a measure of its size or length
|
||||
* and is calculated as the square root of the sum of the squares of its four components.
|
||||
*
|
||||
* @return the magnitude of this quaternion
|
||||
*/
|
||||
double getMagnitude();
|
||||
|
||||
/**
|
||||
* Returns the angular rotation of this quaternion.
|
||||
*
|
||||
* @return the angular rotation of this quaternion
|
||||
*/
|
||||
double getW();
|
||||
|
||||
/**
|
||||
* Returns the x component of this quaternion.
|
||||
*
|
||||
* @return the x component of this quaternion
|
||||
*/
|
||||
double getX();
|
||||
|
||||
/**
|
||||
* Returns the y component of this quaternion.
|
||||
*
|
||||
* @return the y component of this quaternion
|
||||
*/
|
||||
double getY();
|
||||
|
||||
/**
|
||||
* Returns the z component of this quaternion.
|
||||
*
|
||||
* @return the z component of this quaternion
|
||||
*/
|
||||
double getZ();
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package io.github.simplexdev.polarize.api.spatial;
|
||||
|
||||
import static io.github.simplexdev.polarize.api.units.Point.X;
|
||||
import static io.github.simplexdev.polarize.api.units.Point.Z;
|
||||
|
||||
/**
|
||||
* Represents a point in 2D space along an XZ plane.
|
||||
* We are using XZ instead of XY because Minecraft uses XZ.
|
||||
* While this library is not Minecraft specific, it is designed with Minecraft in mind.
|
||||
*/
|
||||
public interface IPoint2D {
|
||||
/**
|
||||
* Returns the X coordinate of the point.
|
||||
*
|
||||
* @return The X coordinate of the point.
|
||||
*/
|
||||
X getX();
|
||||
|
||||
/**
|
||||
* Returns the Z coordinate of the point.
|
||||
*
|
||||
* @return The Z coordinate of the point.
|
||||
*/
|
||||
Z getZ();
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package io.github.simplexdev.polarize.api.spatial;
|
||||
|
||||
import java.util.Set;
|
||||
import static io.github.simplexdev.polarize.api.units.Point.*;
|
||||
|
||||
/**
|
||||
* Represents a point in 3D space.
|
||||
* It's important to note that Y is our vertical plane, and XZ is our horizontal plane.
|
||||
* This is because Minecraft's coordinate system is based on the XZ plane.
|
||||
* While this library is not Minecraft-specific, it is designed with Minecraft in mind.
|
||||
*/
|
||||
public interface IPoint3D {
|
||||
/**
|
||||
* Returns the X coordinate of this point.
|
||||
*
|
||||
* @return The X coordinate of this point.
|
||||
*/
|
||||
X getX();
|
||||
|
||||
/**
|
||||
* Returns the Y coordinate of this point.
|
||||
*
|
||||
* @return The Y coordinate of this point.
|
||||
*/
|
||||
Y getY();
|
||||
|
||||
/**
|
||||
* Returns the Z coordinate of this point.
|
||||
*
|
||||
* @return The Z coordinate of this point.
|
||||
*/
|
||||
Z getZ();
|
||||
|
||||
/**
|
||||
* Returns the distance between this point and another point.
|
||||
*
|
||||
* @param point The point to calculate the distance to.
|
||||
* @return The distance between this point and the other point.
|
||||
*/
|
||||
IVector getDistance(IPoint3D point);
|
||||
|
||||
/**
|
||||
* Returns the difference between this point and another point.
|
||||
*
|
||||
* @param point The point to calculate the difference to.
|
||||
* @return The difference between this point and the other point.
|
||||
*/
|
||||
IPoint3D getDifferential(IPoint3D point);
|
||||
|
||||
/**
|
||||
* Returns the sum of this point and another point.
|
||||
*
|
||||
* @param point The point to add to this point.
|
||||
* @return The sum of this point and the other point.
|
||||
*/
|
||||
IPoint3D add(IPoint3D point);
|
||||
|
||||
/**
|
||||
* Returns the product of this point and another point.
|
||||
* This will effectively scale the point by the other point.
|
||||
* For example, if this point is (1, 1, 1) and the other point is (2, 2, 2),
|
||||
* the resulting point will be (2, 2, 2).
|
||||
*
|
||||
* @param point The point to multiply this point by.
|
||||
* @return The product of this point and the other point.
|
||||
*/
|
||||
IPoint3D multiply(IPoint3D point);
|
||||
|
||||
/**
|
||||
* Translates this point according to the vector provided.
|
||||
* This will effectively move the point to the desired destination defined by the vector.
|
||||
*
|
||||
* @param vector The vector to add to this point.
|
||||
* @return The sum of this point and the vector.
|
||||
*/
|
||||
IPoint3D move(IVector vector);
|
||||
|
||||
/**
|
||||
* Returns the midpoint between this point and another point.
|
||||
*
|
||||
* @param point The point to calculate the midpoint to.
|
||||
* @param numPoints The number of points to draw between this point and the other point.
|
||||
* @return The midpoint between this point and the other point.
|
||||
*/
|
||||
Set<IPoint3D> drawLine(IPoint3D point, double numPoints);
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package io.github.simplexdev.polarize.api.spatial;
|
||||
|
||||
import io.github.simplexdev.polarize.api.rotation.IQuaternion;
|
||||
|
||||
/**
|
||||
* Represents a scalar value.
|
||||
* This is similar to a Vector, but with only one dimension.
|
||||
* This is intended for use against polar-specific coordinates, and is not
|
||||
* compatible with cartesian coordinates.
|
||||
*
|
||||
* @see IVector
|
||||
*/
|
||||
public interface IScalar {
|
||||
/**
|
||||
* Returns the origin of the scalar.
|
||||
* This is the value that the scalar is relative to.
|
||||
*
|
||||
* @return The origin of the scalar.
|
||||
*/
|
||||
double getOrigin();
|
||||
|
||||
/**
|
||||
* Returns the magnitude of the scalar.
|
||||
* This is effectively the length of the scalar.
|
||||
*
|
||||
* @return The magnitude of the scalar.
|
||||
*/
|
||||
double getMagnitude();
|
||||
|
||||
/**
|
||||
* Adds a double value to this scalar and returns the result.
|
||||
*
|
||||
* @param add The value to add to this scalar.
|
||||
* @return The result of adding the given scalar value to this scalar.
|
||||
*/
|
||||
IScalar add(double add);
|
||||
|
||||
/**
|
||||
* Adds this scalar with the passed one.
|
||||
*
|
||||
* @param scalar The scalar to add to this scalar.
|
||||
* @return The result of adding the given scalar value to this scalar.
|
||||
*/
|
||||
IScalar add(IScalar scalar);
|
||||
|
||||
/**
|
||||
* Multiplies this scalar by the passed value and returns the result.
|
||||
*
|
||||
* @param multiply The value to multiply this scalar by.
|
||||
* @return The result of multiplying this scalar by the given scalar value.
|
||||
*/
|
||||
IScalar multiply(double multiply);
|
||||
|
||||
/**
|
||||
* Multiplies this scalar by the passed scalar and returns the result.
|
||||
*
|
||||
* @param scalar The scalar to multiply this scalar by.
|
||||
* @return The result of multiplying this scalar by the given scalar value.
|
||||
*/
|
||||
IScalar multiply(IScalar scalar);
|
||||
|
||||
/**
|
||||
* Multiplies this scalar by a quaternion and returns the result.
|
||||
*
|
||||
* @param quaternion The quaternion to multiply this scalar by.
|
||||
* @return The result of multiplying this scalar by the given quaternion.
|
||||
*/
|
||||
IScalar multiply(IQuaternion quaternion);
|
||||
|
||||
/**
|
||||
* Returns a normalized version of this scalar.
|
||||
*
|
||||
* @return A normalized version of this scalar.
|
||||
*/
|
||||
IScalar normalize();
|
||||
|
||||
/**
|
||||
* Returns the inverse of this scalar.
|
||||
*
|
||||
* @return The inverse of this scalar.
|
||||
* @throws ArithmeticException If this scalar is zero.
|
||||
*/
|
||||
IScalar inverse() throws ArithmeticException;
|
||||
|
||||
/**
|
||||
* Returns the negation of this scalar.
|
||||
*
|
||||
* @return The negation of this scalar.
|
||||
*/
|
||||
IScalar negate();
|
||||
}
|
@ -0,0 +1,183 @@
|
||||
package io.github.simplexdev.polarize.api.spatial;
|
||||
|
||||
import io.github.simplexdev.polarize.api.rotation.IQuaternion;
|
||||
import io.github.simplexdev.polarize.api.units.Point;
|
||||
import io.github.simplexdev.polarize.cartesian.Point3D;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This interface represents a vector in 3D space.
|
||||
* A vector is a line with a direction and a length.
|
||||
* A vector can be represented by a point in space.
|
||||
* However, there is a much better suited Point2D and Point3D interface
|
||||
* for this purpose.
|
||||
*/
|
||||
public interface IVector {
|
||||
/**
|
||||
* This method adds the X Y Z mods of the vector passed in
|
||||
* to the X Y Z mods of this vector. The length is recalculated.
|
||||
*
|
||||
* @param vector The vector to add to this vector.
|
||||
* @return A new vector with the X Y Z mods added.
|
||||
*/
|
||||
IVector add(@NotNull IVector vector);
|
||||
|
||||
/**
|
||||
* This method multiplies the X Y Z mods of the vector passed in
|
||||
* to the X Y Z mods of this vector. The length is recalculated.
|
||||
*
|
||||
* @param vector The vector to multiply to this vector.
|
||||
* @return A new vector with the X Y Z mods multiplied.
|
||||
*/
|
||||
IVector multiply(@NotNull IVector vector);
|
||||
|
||||
/**
|
||||
* This method returns a new vector with the X Y Z mods added
|
||||
* by the value. The length is recalculated. This is a static input based
|
||||
* on the value passed in which will add to each mod of the vector.
|
||||
*
|
||||
* @param value The value to add to the X Y Z mods.
|
||||
* @return A new vector with the X Y Z mods added by the value.
|
||||
*/
|
||||
IVector add(double value);
|
||||
|
||||
/**
|
||||
* This method returns a new vector with the X Y Z mods multiplied
|
||||
* by the value. The length is recalculated. This is a static input based
|
||||
* on the value passed in which will multiply each mod of the vector.
|
||||
*
|
||||
* @param value The value to multiply the X Y Z mods by.
|
||||
* @return A new vector with the X Y Z mods multiplied by the value.
|
||||
*/
|
||||
IVector multiply(double value);
|
||||
|
||||
/**
|
||||
* This method returns a copy of this vector with the X Y Z mods inverted.
|
||||
* The length is recalculated. The X Y Z mods are multiplied by -1.
|
||||
*
|
||||
* @return A copy of this vector with the X Y Z mods inverted.
|
||||
*/
|
||||
IVector inverse();
|
||||
|
||||
/**
|
||||
* This method returns a copy of this vector with a length of 1.
|
||||
* X Y Z mods all remain unchanged.
|
||||
*
|
||||
* @return A copy of this vector with a length of 1.
|
||||
*/
|
||||
IVector normalize();
|
||||
|
||||
/**
|
||||
* This method returns the dot product of this vector and the
|
||||
* vector passed in. The dot product of two vectors is
|
||||
* the sum of the corresponding product components.
|
||||
*
|
||||
* @param vector The vector to dot product with.
|
||||
* @return The dot product of this vector and the vector passed in.
|
||||
*/
|
||||
double dot(@NotNull IVector vector);
|
||||
|
||||
/**
|
||||
* This method returns the angle between this vector and the vector
|
||||
* passed in. The angle is in radians. The angle is the angle between
|
||||
* the two vectors, which is calculated from the dot product.
|
||||
*
|
||||
* @param vector The vector to get the angle between.
|
||||
* @return The angle between this vector and the vector passed in.
|
||||
*/
|
||||
double getAngle(@NotNull IVector vector);
|
||||
|
||||
/**
|
||||
* This method returns the length of this vector.
|
||||
* The length is the distance between the origin and the desired point.
|
||||
* The length is calculated from the X Y Z mods as
|
||||
* sqrt(x * x + y * y + z * z).
|
||||
*
|
||||
* @return The length of this vector.
|
||||
*/
|
||||
double length();
|
||||
|
||||
/**
|
||||
* This method returns the length of this vector squared.
|
||||
* The length is determined by sqrt(x * x + y * y + z * z).
|
||||
*
|
||||
* @return The length of this vector squared.
|
||||
* @see #length()
|
||||
*/
|
||||
double lengthSquared();
|
||||
|
||||
/**
|
||||
* This method returns the distance between this vector and the vector
|
||||
* passed in. The distance is the length of the vector between the two
|
||||
* vectors. The distance is calculated from the X Y Z mods as
|
||||
* sqrt(distanceSquared(vector));
|
||||
*
|
||||
* @param vector The vector to get the distance between.
|
||||
* @return The distance between this vector and the vector passed in.
|
||||
* @see #distanceSquared(IVector)
|
||||
*/
|
||||
double distance(@NotNull IVector vector);
|
||||
|
||||
/**
|
||||
* This method returns the distance between this vector and the vector
|
||||
* passed in squared. The distance is the length of the vector between the two
|
||||
* vectors. The distance is calculated from the X Y Z mods as
|
||||
* (x - x1) * (x - x1) + (y - y1) * (y - y1) + (z - z1) * (z - z1).
|
||||
*
|
||||
* @param vector The vector to get the distance between.
|
||||
* @return The distance between this vector and the vector passed in squared.
|
||||
*/
|
||||
double distanceSquared(@NotNull IVector vector);
|
||||
|
||||
/**
|
||||
* @return The X mod of this vector.
|
||||
*/
|
||||
double getX();
|
||||
|
||||
/**
|
||||
* @return The Y mod of this vector.
|
||||
*/
|
||||
double getY();
|
||||
|
||||
/**
|
||||
* @return The Z mod of this vector.
|
||||
*/
|
||||
double getZ();
|
||||
|
||||
/**
|
||||
* This method returns a new vector with the X Y Z mods rotated
|
||||
* by the quaternion passed in. The length is recalculated.
|
||||
*
|
||||
* @param quaternion The quaternion to rotate the vector by.
|
||||
* @return A new vector with the X Y Z mods rotated by the quaternion passed in.
|
||||
*/
|
||||
IVector rotate(@NotNull IQuaternion quaternion);
|
||||
|
||||
/**
|
||||
* This method returns the destination point defined by the XYZ mods and the length of the vector.
|
||||
* The destination point is calculated from the X Y Z mods as
|
||||
* (x * length, y * length, z * length).
|
||||
* The destination point is the point that the vector is pointing to.
|
||||
*
|
||||
* @return The destination point defined by the XYZ mods and the length of the vector.
|
||||
*/
|
||||
default IPoint3D getDestination() {
|
||||
return Point.fromDouble(getX() * length(), getY() * length(), getZ() * length());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a cross-product of this vector and the vector passed in.
|
||||
* The cross-product is calculated from the X Y Z mods as
|
||||
* (y * vector.getZ() - z * vector.getY(), z * vector.getX() - x * vector.getZ(), x * vector.getY() - y * vector.getX()).
|
||||
*
|
||||
* @param vector The vector to cross-product with.
|
||||
* @return A cross-product of this vector and the vector passed in.
|
||||
*/
|
||||
default IPoint3D cross(IVector vector) {
|
||||
return Point.fromDouble(
|
||||
getY() * vector.getZ() - getZ() * vector.getY(),
|
||||
getZ() * vector.getX() - getX() * vector.getZ(),
|
||||
getX() * vector.getY() - getY() * vector.getX()
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package io.github.simplexdev.polarize.api.spatial;
|
||||
|
||||
public interface IVertex {
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package io.github.simplexdev.polarize.api.units;
|
||||
|
||||
/**
|
||||
* This is a functional interface representing a mathematical function Phi, which returns the azimuth value.
|
||||
* <p>
|
||||
* The interface has a single method 'getAzimuth' which returns a double value representing the azimuth.
|
||||
* <p>
|
||||
* This interface is marked with the @FunctionalInterface annotation which indicates that it should be
|
||||
* <p>
|
||||
* used as a functional interface with a single abstract method (SAM).
|
||||
*
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Azimuth">Azimuth</a>
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Phi {
|
||||
|
||||
/**
|
||||
* This method returns a double value representing the azimuth.
|
||||
*
|
||||
* @return the azimuth value as a double
|
||||
*/
|
||||
double getAzimuth();
|
||||
|
||||
static Phi from(double y, Radius r) {
|
||||
return () -> Math.cos(y / r.length());
|
||||
}
|
||||
|
||||
static Phi of(double azimuth) {
|
||||
return () -> azimuth;
|
||||
}
|
||||
}
|
@ -0,0 +1,244 @@
|
||||
package io.github.simplexdev.polarize.api.units;
|
||||
|
||||
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint2D;
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint3D;
|
||||
import io.github.simplexdev.polarize.cartesian.Point2D;
|
||||
import io.github.simplexdev.polarize.cartesian.Point3D;
|
||||
import io.github.simplexdev.polarize.math.function.Integral;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.function.DoubleUnaryOperator;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Point extends Serializable {
|
||||
|
||||
/**
|
||||
* Creates a 2d point from a given X and Z value.
|
||||
*
|
||||
* @param x The X value.
|
||||
* @param z The Z value.
|
||||
* @return The 2d point.
|
||||
*/
|
||||
static IPoint2D fromXZ(X x, Z z) {
|
||||
return new Point2D(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a 3d point from a given X, Y, and Z value.
|
||||
*
|
||||
* @param x The X value.
|
||||
* @param y The Y value.
|
||||
* @param z The Z value.
|
||||
* @return The 3d point.
|
||||
*/
|
||||
static IPoint3D fromXYZ(X x, Y y, Z z) {
|
||||
return new Point3D(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a 2d point from the given double values.
|
||||
*
|
||||
* @param x The X value.
|
||||
* @param z The Z value.
|
||||
* @return The 2d point.
|
||||
*/
|
||||
static IPoint2D fromDouble(double x, double z) {
|
||||
return new Point2D(() -> x, () -> z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a 3d point from the given double values.
|
||||
*
|
||||
* @param x The X value.
|
||||
* @param y The Y value.
|
||||
* @param z The Z value.
|
||||
* @return The 3d point.
|
||||
*/
|
||||
static IPoint3D fromDouble(double x, double y, double z) {
|
||||
return new Point3D(() -> x, () -> y, () -> z);
|
||||
}
|
||||
|
||||
@Override
|
||||
String toString();
|
||||
|
||||
/**
|
||||
* Returns the numerical representation of the point.
|
||||
*
|
||||
* @return The value of the point.
|
||||
*/
|
||||
double get();
|
||||
|
||||
/**
|
||||
* Returns the distance between this point and the given point.
|
||||
*
|
||||
* @param point The point to compare to.
|
||||
* @return The distance between the two points.
|
||||
*/
|
||||
default double distance(double point) {
|
||||
return Math.abs(this.get() - point);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the distance between this point and the given point.
|
||||
*
|
||||
* @param point The point to compare to.
|
||||
* @return The distance between the two points.
|
||||
*/
|
||||
default double distance(Point point) {
|
||||
return this.distance(point.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given point to this point.
|
||||
*
|
||||
* @param point The point to add.
|
||||
* @return The sum of the two points.
|
||||
*/
|
||||
default double add(double point) {
|
||||
return this.get() + point;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given point to this point.
|
||||
*
|
||||
* @param point The point to add.
|
||||
* @return The sum of the two points.
|
||||
*/
|
||||
default double add(Point point) {
|
||||
return this.add(point.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtracts the given point from this point.
|
||||
*
|
||||
* @param point The point to subtract.
|
||||
* @return The difference of the two points.
|
||||
*/
|
||||
default double subtract(double point) {
|
||||
return this.get() - point;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtracts the given point from this point.
|
||||
*
|
||||
* @param point The point to subtract.
|
||||
* @return The difference of the two points.
|
||||
*/
|
||||
default double subtract(Point point) {
|
||||
return this.subtract(point.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplies this point by the given point.
|
||||
*
|
||||
* @param point The point to multiply by.
|
||||
* @return The product of the two points.
|
||||
*/
|
||||
default double multiply(double point) {
|
||||
return this.get() * point;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplies this point by the given point.
|
||||
*
|
||||
* @param point The point to multiply by.
|
||||
* @return The product of the two points.
|
||||
*/
|
||||
default double multiply(Point point) {
|
||||
return this.multiply(point.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Divides this point by the given point.
|
||||
*
|
||||
* @param point The point to divide by.
|
||||
* @return The quotient of the two points.
|
||||
*/
|
||||
default double divide(double point) {
|
||||
return this.get() / point;
|
||||
}
|
||||
|
||||
/**
|
||||
* Divides this point by the given point.
|
||||
*
|
||||
* @param point The point to divide by.
|
||||
* @return The quotient of the two points.
|
||||
*/
|
||||
default double divide(Point point) {
|
||||
return this.divide(point.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this point raised to the power of the given point.
|
||||
*
|
||||
* @param point The point to raise this point to.
|
||||
* @return The power of the two points.
|
||||
*/
|
||||
default double power(double point) {
|
||||
return Math.pow(this.get(), point);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this point raised to the power of the given point.
|
||||
*
|
||||
* @param point The point to raise this point to.
|
||||
* @return The power of the two points.
|
||||
*/
|
||||
default double power(Point point) {
|
||||
return this.power(point.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integral of the given function from this point to the given point.
|
||||
*
|
||||
* @param point The point to integrate to.
|
||||
* @param subIntervals The number of sub-intervals to use.
|
||||
* @param function The function to integrate.
|
||||
* @return The integral of the function.
|
||||
*/
|
||||
default double integ(double point, double subIntervals, DoubleUnaryOperator function) {
|
||||
return Integral.integrate(this.get(), point, subIntervals, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integral of the given function from this point to the given point.
|
||||
*
|
||||
* @param point The point to integrate to.
|
||||
* @param subIntervals The number of sub-intervals to use.
|
||||
* @param function The function to integrate.
|
||||
* @return The integral of the function.
|
||||
*/
|
||||
default double integ(Point point, double subIntervals, DoubleUnaryOperator function) {
|
||||
return this.integ(point.get(), subIntervals, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents any value of X along the <u>X coordinate plane</u>.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
interface X extends Point {
|
||||
@Override
|
||||
double get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents any value of Y along the <u>Y coordinate plane</u>.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
interface Y extends Point {
|
||||
|
||||
@Override
|
||||
double get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents any value of Z along the <u>Z coordinate plane</u>.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
interface Z extends Point {
|
||||
|
||||
@Override
|
||||
double get();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package io.github.simplexdev.polarize.api.units;
|
||||
|
||||
/**
|
||||
* This is a functional interface representing a mathematical function Radius, which returns the length of the radius.
|
||||
* <p>
|
||||
* The interface has a single method 'length' which returns a double value representing the length of the radius.
|
||||
* <p>
|
||||
* This interface is marked with the @FunctionalInterface annotation which indicates that it should be
|
||||
* <p>
|
||||
* used as a functional interface with a single abstract method (SAM).
|
||||
*
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Radius">Radius</a>
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Radius {
|
||||
/**
|
||||
* This method returns a double value representing the length of the radius.
|
||||
*
|
||||
* @return the length of the radius as a double
|
||||
*/
|
||||
double length();
|
||||
|
||||
static Radius of(double length) {
|
||||
return () -> length;
|
||||
}
|
||||
|
||||
static Radius from(double x, double y, double z) {
|
||||
return () -> Math.sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package io.github.simplexdev.polarize.api.units;
|
||||
|
||||
/**
|
||||
* This is a functional interface representing a mathematical angle Theta, which returns the zenith value.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Theta {
|
||||
/**
|
||||
* This method returns a double value representing the zenith angle.
|
||||
*
|
||||
* @return the zenith angle as a double.
|
||||
*/
|
||||
double getZenith();
|
||||
|
||||
static Theta from(double x, double z) {
|
||||
return () -> Math.atan2(x, z);
|
||||
}
|
||||
|
||||
static Theta of(double zenithAngle) {
|
||||
return () -> zenithAngle;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package io.github.simplexdev.polarize.cartesian;
|
||||
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint2D;
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint3D;
|
||||
import io.github.simplexdev.polarize.api.units.Point;
|
||||
|
||||
/**
|
||||
* CartesianUnit is a class that contains a 3D point and a 2D point
|
||||
* which share the same x and z values for the horizontal plane.
|
||||
*/
|
||||
public class CartesianUnit {
|
||||
private final IPoint3D point3d;
|
||||
private final IPoint2D point2d;
|
||||
|
||||
/**
|
||||
* Creates a new CartesianUnit with the given x, y, and z values.
|
||||
*
|
||||
* @param x The x value of the 3D point and the 2D point.
|
||||
* @param y The y value of the 3D point.
|
||||
* @param z The z value of the 3D point and the 2D point.
|
||||
*/
|
||||
public CartesianUnit(double x, double y, double z) {
|
||||
this.point3d = Point.fromDouble(x, y, z);
|
||||
this.point2d = Point.fromDouble(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the 3D point of the CartesianUnit.
|
||||
*
|
||||
* @return The 3D point of the CartesianUnit.
|
||||
*/
|
||||
public IPoint3D getPoint3D() {
|
||||
return this.point3d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the 2D point of the CartesianUnit.
|
||||
*
|
||||
* @return The 2D point of the CartesianUnit.
|
||||
*/
|
||||
public IPoint2D getPoint2D() {
|
||||
return this.point2d;
|
||||
}
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
package io.github.simplexdev.polarize.cartesian;
|
||||
|
||||
import io.github.simplexdev.polarize.api.rotation.IQuaternion;
|
||||
import io.github.simplexdev.polarize.api.spatial.IVector;
|
||||
import io.github.simplexdev.polarize.math.Quaternion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class CartesianVector implements IVector {
|
||||
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
private final double length;
|
||||
|
||||
public CartesianVector(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.length = Math.sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
private CartesianVector(double x, double y, double z, double length) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IVector add(@NotNull IVector vector) {
|
||||
Objects.requireNonNull(vector);
|
||||
return new CartesianVector(
|
||||
this.x + vector.getX(),
|
||||
this.y + vector.getY(),
|
||||
this.z + vector.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IVector multiply(@NotNull IVector vector) {
|
||||
return new CartesianVector(
|
||||
this.x * vector.getX(),
|
||||
this.y * vector.getY(),
|
||||
this.z * vector.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IVector add(double value) {
|
||||
return new CartesianVector(
|
||||
this.x + value,
|
||||
this.y + value,
|
||||
this.z + value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IVector multiply(double value) {
|
||||
return new CartesianVector(
|
||||
this.x * value,
|
||||
this.y * value,
|
||||
this.z * value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IVector inverse() {
|
||||
return new CartesianVector(
|
||||
this.x * -1.0,
|
||||
this.y * -1.0,
|
||||
this.z * -1.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IVector normalize() {
|
||||
if (this.length == 0) {
|
||||
return new CartesianVector(0, 0, 0);
|
||||
}
|
||||
return new CartesianVector(
|
||||
this.x / this.length,
|
||||
this.y / this.length,
|
||||
this.z / this.length,
|
||||
1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double dot(@NotNull IVector vector) {
|
||||
return this.x * vector.getX() + this.y * vector.getY() + this.z * vector.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAngle(@NotNull IVector vector) {
|
||||
double dot = this.dot(vector);
|
||||
return Math.acos(dot / (this.length() * vector.length()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double length() {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double lengthSquared() {
|
||||
return this.length * this.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double distance(@NotNull IVector vector) {
|
||||
Objects.requireNonNull(vector);
|
||||
return Math.sqrt(distanceSquared(vector));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double distanceSquared(@NotNull IVector vector) {
|
||||
Objects.requireNonNull(vector);
|
||||
double dx = this.x - vector.getX();
|
||||
double dy = this.y - vector.getY();
|
||||
double dz = this.z - vector.getZ();
|
||||
return dx * dx + dy * dy + dz * dz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IVector rotate(@NotNull IQuaternion quaternion) {
|
||||
IQuaternion q = quaternion.normalize();
|
||||
IQuaternion p = new Quaternion(0, this.x, this.y, this.z);
|
||||
IQuaternion pRotated = q.multiply(p).multiply(q.conjugate());
|
||||
|
||||
return new CartesianVector(pRotated.getX(), pRotated.getY(), pRotated.getZ());
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package io.github.simplexdev.polarize.cartesian;
|
||||
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint2D;
|
||||
import static io.github.simplexdev.polarize.api.units.Point.*;
|
||||
|
||||
public class Point2D implements IPoint2D {
|
||||
|
||||
private final X x;
|
||||
private final Z z;
|
||||
|
||||
public Point2D(X x, Z z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public X getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Z getZ() {
|
||||
return this.z;
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
package io.github.simplexdev.polarize.cartesian;
|
||||
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint3D;
|
||||
import io.github.simplexdev.polarize.api.spatial.IVector;
|
||||
import io.github.simplexdev.polarize.api.units.Point;
|
||||
import io.github.simplexdev.polarize.log.PolarizeLogger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Point3D implements IPoint3D {
|
||||
private final Point.X x;
|
||||
private final Point.Y y;
|
||||
private final Point.Z z;
|
||||
|
||||
public Point3D(Point.X x, Point.Y y, Point.Z z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point.X getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point.Y getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point.Z getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IVector getDistance(@NotNull IPoint3D point) {
|
||||
return new CartesianVector(point.getX().subtract(x),
|
||||
point.getY().subtract(y),
|
||||
point.getZ().subtract(z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint3D multiply(IPoint3D point) {
|
||||
return new Point3D(() -> x.multiply(point.getX()),
|
||||
() -> y.multiply(point.getY()),
|
||||
() -> z.multiply(point.getZ()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint3D move(IVector vector) {
|
||||
return add(vector.getDestination());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint3D getDifferential(@NotNull IPoint3D point) {
|
||||
return new Point3D(() -> point.getX().subtract(x),
|
||||
() -> point.getY().subtract(y),
|
||||
() -> point.getZ().subtract(z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint3D add(IPoint3D point) {
|
||||
return new Point3D(() -> point.getX().add(x),
|
||||
() -> point.getY().add(y),
|
||||
() -> point.getZ().add(z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IPoint3D> drawLine(IPoint3D point, double numPoints) {
|
||||
IPoint3D diff = getDifferential(point);
|
||||
Set<IPoint3D> point3DSet = new LinkedHashSet<>();
|
||||
for (double i = 0.0; i <= numPoints; i++) {
|
||||
double multiplier = i / numPoints;
|
||||
PolarizeLogger.info("i: " + i);
|
||||
PolarizeLogger.info("multiplier: " + multiplier);
|
||||
IPoint3D adjusted = Point.fromDouble(diff.getX().multiply(() -> multiplier),
|
||||
diff.getY().multiply(multiplier),
|
||||
diff.getZ().multiply(multiplier));
|
||||
PolarizeLogger.info("adjusted: " + "X: " + adjusted.getX()
|
||||
+ " Y: " + adjusted.getY()
|
||||
+ " Z: " + adjusted.getZ());
|
||||
IPoint3D added = this.add(adjusted);
|
||||
PolarizeLogger.info("added: " + "X: " + added.getX()
|
||||
+ " Y: " + added.getY()
|
||||
+ " Z: " + added.getZ());
|
||||
point3DSet.add(added);
|
||||
}
|
||||
return point3DSet;
|
||||
}
|
||||
|
||||
public void drawLineTestMethod() {
|
||||
IPoint3D origin = Point.fromDouble(2, 6, 5);
|
||||
IPoint3D destination = Point.fromDouble(10, 6, -15);
|
||||
origin.drawLine(destination, 25).forEach(point3D ->
|
||||
PolarizeLogger.info("X: " + point3D.getX()
|
||||
+ " Y: " + point3D.getY()
|
||||
+ " Z: " + point3D.getZ()));
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package io.github.simplexdev.polarize.cartesian;
|
||||
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint3D;
|
||||
import io.github.simplexdev.polarize.api.spatial.IVector;
|
||||
|
||||
public class Vertex {
|
||||
private final IPoint3D vertex;
|
||||
|
||||
public Vertex(IVector vector1, IVector vector2) {
|
||||
this.vertex = vector1.cross(vector2);
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return vertex.getX().get();
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return vertex.getY().get();
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return vertex.getZ().get();
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package io.github.simplexdev.polarize.log;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PolarizeLogger {
|
||||
private static final Logger logger = Logger.getLogger("Polarize");
|
||||
|
||||
private PolarizeLogger() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static void info(String message) {
|
||||
logger.info(message);
|
||||
}
|
||||
|
||||
public static void warning(String message) {
|
||||
logger.warning(message);
|
||||
}
|
||||
|
||||
public static void warning(Throwable throwable) {
|
||||
logger.warning(throwable.getMessage());
|
||||
}
|
||||
|
||||
public static void severe(String message) {
|
||||
logger.severe(message);
|
||||
}
|
||||
|
||||
public static void severe(Throwable throwable) {
|
||||
logger.severe(throwable.getMessage());
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package io.github.simplexdev.polarize.math;
|
||||
|
||||
import io.github.simplexdev.polarize.api.rotation.IAxisAngle;
|
||||
import io.github.simplexdev.polarize.api.units.Theta;
|
||||
|
||||
public class AxisAngle implements IAxisAngle {
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
private final Theta angle;
|
||||
|
||||
public AxisAngle(double x, double y, double z, Theta angle) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Theta getAngle() {
|
||||
return this.angle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAxisAngle negate() {
|
||||
return new AxisAngle(-this.x, -this.y, -this.z, () -> -(this.angle.getZenith()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAxisAngle normalize() {
|
||||
double magnitude = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
||||
return new AxisAngle(this.x / magnitude, this.y / magnitude, this.z / magnitude, this.angle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAxisAngle inverse() {
|
||||
return new AxisAngle(-this.x, -this.y, -this.z, this.angle);
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package io.github.simplexdev.polarize.math;
|
||||
|
||||
import io.github.simplexdev.polarize.api.rotation.IQuaternion;
|
||||
|
||||
public class Quaternion implements IQuaternion {
|
||||
private final double w;
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
|
||||
public Quaternion(double w, double x, double y, double z) {
|
||||
this.w = w;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuaternion add(double scalar) {
|
||||
return new Quaternion(this.w + scalar, this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuaternion add(IQuaternion q) {
|
||||
return new Quaternion(this.w + q.getW(), this.x + q.getX(), this.y + q.getY(), this.z + q.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuaternion multiply(double scalar) {
|
||||
return new Quaternion(this.w * scalar, this.x * scalar, this.y * scalar, this.z * scalar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuaternion multiply(IQuaternion q) {
|
||||
double w1 = this.w,
|
||||
x1 = this.x,
|
||||
y1 = this.y,
|
||||
z1 = this.z;
|
||||
double w2 = q.getW(),
|
||||
x2 = q.getX(),
|
||||
y2 = q.getY(),
|
||||
z2 = q.getZ();
|
||||
|
||||
double w = w1 * w2 - x1 * x2 - y1 * y2 - z1 * z2;
|
||||
double x = w1 * x2 + x1 * w2 + y1 * z2 - z1 * y2;
|
||||
double y = w1 * y2 + y1 * w2 + z1 * x2 - x1 * z2;
|
||||
double z = w1 * z2 + z1 * w2 + x1 * y2 - y1 * x2;
|
||||
|
||||
return new Quaternion(w, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuaternion normalize() {
|
||||
double magnitude = this.getMagnitude();
|
||||
return new Quaternion(this.w / magnitude, this.x / magnitude, this.y / magnitude, this.z / magnitude);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuaternion inverse() {
|
||||
double magnitudeSquared = this.getMagnitude() * this.getMagnitude();
|
||||
return new Quaternion(this.w / magnitudeSquared, -this.x / magnitudeSquared, -this.y / magnitudeSquared, -this.z / magnitudeSquared);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuaternion conjugate() {
|
||||
return new Quaternion(this.w, -this.x, -this.y, -this.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMagnitude() {
|
||||
return Math.sqrt(w * w + x * x + y * y + z * z);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package io.github.simplexdev.polarize.math;
|
||||
|
||||
import io.github.simplexdev.polarize.api.spatial.IVector;
|
||||
import io.github.simplexdev.polarize.cartesian.CartesianVector;
|
||||
|
||||
public class ScalarTriple {
|
||||
private final double productA;
|
||||
private final double productB;
|
||||
private final double productC;
|
||||
|
||||
private final IVector scalarTripleProduct;
|
||||
|
||||
public ScalarTriple(IVector productA, IVector productB, IVector productC) {
|
||||
this.productA = productA.dot(productB.multiply(productC));
|
||||
this.productB = productB.dot(productC.multiply(productA));
|
||||
this.productC = productC.dot(productA.multiply(productB));
|
||||
|
||||
this.scalarTripleProduct = new CartesianVector(
|
||||
this.productA,
|
||||
this.productB,
|
||||
this.productC);
|
||||
}
|
||||
|
||||
public double getProductA() {
|
||||
return productA;
|
||||
}
|
||||
|
||||
public double getProductB() {
|
||||
return productB;
|
||||
}
|
||||
|
||||
public double getProductC() {
|
||||
return productC;
|
||||
}
|
||||
|
||||
public IVector getScalarTripleProduct() {
|
||||
return scalarTripleProduct;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package io.github.simplexdev.polarize.math.function;
|
||||
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint2D;
|
||||
import io.github.simplexdev.polarize.api.units.Point;
|
||||
import io.github.simplexdev.polarize.api.units.Theta;
|
||||
import io.github.simplexdev.polarize.cartesian.Point2D;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ArchimedeanSpiral {
|
||||
private final double origin;
|
||||
private final double step;
|
||||
private final double radius;
|
||||
private final Theta theta;
|
||||
|
||||
public ArchimedeanSpiral(double origin, double step, @NotNull Theta theta) {
|
||||
this.origin = origin;
|
||||
this.step = step;
|
||||
this.theta = theta;
|
||||
|
||||
this.radius = origin + (this.step * theta.getZenith());
|
||||
}
|
||||
|
||||
public Set<IPoint2D> getPoints(IPoint2D start) {
|
||||
Set<IPoint2D> hashSet = new LinkedHashSet<>();
|
||||
hashSet.add(start);
|
||||
for (double i = origin; i < theta.getZenith(); i += step) {
|
||||
double x = radius * Math.cos(i);
|
||||
double z = radius * Math.sin(i);
|
||||
hashSet.add(Point.fromDouble(x + start.getX().get(), z + start.getZ().get()));
|
||||
}
|
||||
return hashSet;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package io.github.simplexdev.polarize.math.function;
|
||||
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint3D;
|
||||
import io.github.simplexdev.polarize.api.units.Point;
|
||||
import io.github.simplexdev.polarize.cartesian.Point3D;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public final class FibonacciLattice {
|
||||
|
||||
public static Set<IPoint3D> populate(IPoint3D origin, int radius, double step) {
|
||||
Set<IPoint3D> points = new LinkedHashSet<>();
|
||||
final double goldenRatio = (1 + Math.sqrt(5)) / 2;
|
||||
|
||||
for (double i = 0; i <= radius; i += step) {
|
||||
double theta = 2 * Math.PI * i / goldenRatio;
|
||||
double phi = Math.acos(1 - 2 * (i + 0.5) / radius);
|
||||
double x = Math.cos(theta) * Math.sin(phi);
|
||||
double y = Math.cos(phi);
|
||||
double z = Math.sin(theta) * Math.sin(phi);
|
||||
|
||||
points.add(origin.add(Point.fromDouble(x, y, z)));
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package io.github.simplexdev.polarize.math.function;
|
||||
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint3D;
|
||||
import io.github.simplexdev.polarize.cartesian.Point3D;
|
||||
|
||||
import java.util.function.DoubleUnaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public interface Integral {
|
||||
static double integrate(double lower, double upper, double subIntervals, DoubleUnaryOperator function) {
|
||||
double dx = (upper - lower) / subIntervals;
|
||||
double sum = 0.5 * (function.applyAsDouble(lower) + function.applyAsDouble(upper));
|
||||
for (double i = 1; i < subIntervals; i++) {
|
||||
double s = lower + i * dx;
|
||||
sum += function.applyAsDouble(s);
|
||||
}
|
||||
return dx * sum;
|
||||
}
|
||||
|
||||
static double integrate(IPoint3D origin, IPoint3D destination, double subIntervals, TriFunction<Double, Double, Double, Double> function) {
|
||||
double x1 = origin.getX().get(), x2 = destination.getX().get();
|
||||
double y1 = origin.getY().get(), y2 = destination.getY().get();
|
||||
double z1 = origin.getZ().get(), z2 = destination.getZ().get();
|
||||
|
||||
double dx = (x2 - x1) / subIntervals;
|
||||
double dy = (y2 - y1) / subIntervals;
|
||||
double dz = (z2 - z1) / subIntervals;
|
||||
|
||||
double integral = 0.0;
|
||||
|
||||
for (double i = 0.0; i <= subIntervals; i++) {
|
||||
double x = x1 + i * dx;
|
||||
for (double j = 0.0; j <= subIntervals; j++) {
|
||||
double y = y1 + j * dy;
|
||||
for (double k = 0.0; k <= subIntervals; k++) {
|
||||
double z = z1 + k * dz;
|
||||
double weight = 1.0;
|
||||
if (i == 0.0 || i == subIntervals) weight *= 0.5;
|
||||
if (j == 0.0 || j == subIntervals) weight *= 0.5;
|
||||
if (k == 0.0 || k == subIntervals) weight *= 0.5;
|
||||
integral += weight * function.apply(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
integral *= dx * dy * dz;
|
||||
|
||||
return integral;
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package io.github.simplexdev.polarize.math.function;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TriFunction<T, S, U, V> {
|
||||
V apply(T t, S s, U u);
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package io.github.simplexdev.polarize.polar;
|
||||
|
||||
import io.github.simplexdev.polarize.api.units.Phi;
|
||||
import io.github.simplexdev.polarize.api.units.Theta;
|
||||
|
||||
/**
|
||||
* Represents a modifier that can be used in rotations of polar and spherical units.
|
||||
* <p>
|
||||
* Typically, these are used in full rotations along the unit circle / unit sphere,
|
||||
* but can be used in any degree of rotation.
|
||||
*/
|
||||
public class Delta {
|
||||
private final Theta theta;
|
||||
private final Phi phi;
|
||||
|
||||
/**
|
||||
* Creates a new Delta with the given theta and phi modifiers.
|
||||
*
|
||||
* @param theta the theta modifier.
|
||||
* @param phi the phi modifier.
|
||||
*/
|
||||
public Delta(double theta, double phi) {
|
||||
this.theta = () -> theta;
|
||||
this.phi = () -> phi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object that represents the theta modifier.
|
||||
*
|
||||
* @return an object that represents the theta modifier.
|
||||
* @see Theta
|
||||
*/
|
||||
public Theta getTheta() {
|
||||
return theta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object that represents the phi modifier.
|
||||
*
|
||||
* @return an object that represents the phi modifier.
|
||||
* @see Phi
|
||||
*/
|
||||
public Phi getPhi() {
|
||||
return phi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the theta modifier.
|
||||
* This is a double value for easier access.
|
||||
*
|
||||
* @return the theta modifier.
|
||||
*/
|
||||
public double theta() {
|
||||
return theta.getZenith();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the phi modifier.
|
||||
* This is a double value for easier access.
|
||||
*
|
||||
* @return the phi modifier.
|
||||
*/
|
||||
public double phi() {
|
||||
return phi.getAzimuth();
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package io.github.simplexdev.polarize.polar;
|
||||
|
||||
import io.github.simplexdev.polarize.api.units.Radius;
|
||||
import io.github.simplexdev.polarize.api.units.Theta;
|
||||
|
||||
/**
|
||||
* Represents a unit in polar coordinates.
|
||||
*/
|
||||
public class PolarUnit {
|
||||
private final Radius radius;
|
||||
private final Theta theta;
|
||||
|
||||
/**
|
||||
* Creates a new PolarUnit with the given radius and angle theta.
|
||||
*
|
||||
* @param radius the radius of the unit.
|
||||
* @param theta the angle theta of the unit.
|
||||
*/
|
||||
public PolarUnit(double radius, double theta) {
|
||||
this.radius = () -> radius;
|
||||
this.theta = () -> theta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the radius object of this unit.
|
||||
* <p>
|
||||
* This is an object which represents the variable r, which
|
||||
* represents the radius of the unit circle in 2d space.
|
||||
*
|
||||
* @return the radius object of this unit.
|
||||
*/
|
||||
public Radius getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the angle object theta of this unit.
|
||||
* <p>
|
||||
* This is an object which represents the variable theta, which
|
||||
* represents an angle on the unit circle in 2d space.
|
||||
*
|
||||
* @return the angle object theta of this unit.
|
||||
*/
|
||||
public Theta getTheta() {
|
||||
return theta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the radius of this unit.
|
||||
* This is formatted as a double for quick access.
|
||||
*
|
||||
* @return the radius of this unit.
|
||||
*/
|
||||
public double radius() {
|
||||
return radius.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the angle theta of this unit.
|
||||
* This is formatted as a double for quick access.
|
||||
*
|
||||
* @return the angle theta of this unit.
|
||||
*/
|
||||
public double theta() {
|
||||
return theta.getZenith();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adjacent side of the triangle formed by this unit in 2d space.
|
||||
* <p>
|
||||
* The adjacent side is the side adjacent the angle theta.
|
||||
*
|
||||
* @return the adjacent side of the triangle formed by this unit in 2d space.
|
||||
*/
|
||||
public double adjacent() {
|
||||
return radius() * Math.cos(theta());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the opposite side of the triangle formed by this unit in 2d space.
|
||||
* <p>
|
||||
* The opposite side is the side opposite the angle theta.
|
||||
*
|
||||
* @return the opposite side of the triangle formed by this unit in 2d space.
|
||||
*/
|
||||
public double opposite() {
|
||||
return radius() * Math.sin(theta());
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package io.github.simplexdev.polarize.polar;
|
||||
|
||||
import io.github.simplexdev.polarize.api.rotation.IQuaternion;
|
||||
import io.github.simplexdev.polarize.api.spatial.IScalar;
|
||||
|
||||
public class Scalar implements IScalar {
|
||||
private final double magnitude;
|
||||
private final double origin;
|
||||
|
||||
public Scalar(double magnitude, double origin) {
|
||||
this.magnitude = magnitude;
|
||||
this.origin = origin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMagnitude() {
|
||||
return this.magnitude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getOrigin() {
|
||||
return this.origin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScalar add(double add) {
|
||||
double sumValue = getMagnitude() + add;
|
||||
return new Scalar(sumValue, getOrigin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScalar add(IScalar scalar) {
|
||||
double sumValue = getMagnitude() + scalar.getMagnitude();
|
||||
return new Scalar(sumValue, getOrigin());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IScalar multiply(double multiply) {
|
||||
double productValue = getMagnitude() * multiply;
|
||||
return new Scalar(productValue, getOrigin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScalar multiply(IScalar scalar) {
|
||||
double productValue = getMagnitude() * scalar.getMagnitude();
|
||||
return new Scalar(productValue, getOrigin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScalar multiply(IQuaternion quaternion) {
|
||||
double productValue = getMagnitude() * quaternion.getW();
|
||||
return new Scalar(productValue, getOrigin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScalar normalize() {
|
||||
double magnitude = getMagnitude();
|
||||
if (magnitude == 0.0) {
|
||||
return new Scalar(0.0, getOrigin());
|
||||
}
|
||||
double normalizedMagnitude = 1.0 / magnitude;
|
||||
double normalizedValue = getMagnitude() * normalizedMagnitude;
|
||||
return new Scalar(normalizedValue, getOrigin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScalar inverse() throws ArithmeticException {
|
||||
if (getMagnitude() == 0.0) {
|
||||
throw new ArithmeticException("Cannot compute inverse of scalar with magnitude 0.");
|
||||
}
|
||||
double reciprocalValue = 1.0 / getMagnitude();
|
||||
return new Scalar(reciprocalValue, getOrigin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScalar negate() {
|
||||
double negatedValue = -getMagnitude();
|
||||
return new Scalar(negatedValue, getOrigin());
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
package io.github.simplexdev.polarize.polar;
|
||||
|
||||
import io.github.simplexdev.polarize.api.units.Phi;
|
||||
import io.github.simplexdev.polarize.api.units.Radius;
|
||||
import io.github.simplexdev.polarize.api.units.Theta;
|
||||
import io.github.simplexdev.polarize.cartesian.CartesianUnit;
|
||||
import io.github.simplexdev.polarize.util.Polarizer;
|
||||
|
||||
/**
|
||||
* A class that represents a spherical unit.
|
||||
*/
|
||||
public class SphericalUnit {
|
||||
private final Radius radius;
|
||||
private final Theta theta;
|
||||
private final Phi phi;
|
||||
|
||||
/**
|
||||
* Creates a new SphericalUnit with the given radius, theta, and phi.
|
||||
*
|
||||
* @param radius The radius of the unit.
|
||||
* @param theta The theta of the unit.
|
||||
* @param phi The phi of the unit.
|
||||
*/
|
||||
public SphericalUnit(double radius, double theta, double phi) {
|
||||
this.radius = () -> radius;
|
||||
this.theta = () -> theta;
|
||||
this.phi = () -> phi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the radius object of the unit.
|
||||
* <p>
|
||||
* This is an object which represents the variable r, which
|
||||
* represents the radius of the unit sphere in 3d space.
|
||||
*
|
||||
* @return The radius object of the unit.
|
||||
* @see Radius
|
||||
*/
|
||||
public Radius getRadius() {
|
||||
return this.radius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the theta object of the unit.
|
||||
* <p>
|
||||
* This is an object which represents the variable theta, which
|
||||
* represents the angle of the unit sphere in 3d space.
|
||||
*
|
||||
* @return The theta object of the unit.
|
||||
* @see Theta
|
||||
*/
|
||||
public Theta getTheta() {
|
||||
return this.theta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the phi object of the unit.
|
||||
* <p>
|
||||
* This is an object which represents the variable phi, which
|
||||
* represents the angle of the unit sphere in 3d space.
|
||||
*
|
||||
* @return The phi object of the unit.
|
||||
* @see Phi
|
||||
*/
|
||||
public Phi getPhi() {
|
||||
return this.phi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the radius of the unit.
|
||||
* This is formatted as a double for quick access.
|
||||
*
|
||||
* @return The radius of the unit.
|
||||
*/
|
||||
public double radius() {
|
||||
return this.radius.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the theta of the unit.
|
||||
* This is formatted as a double for quick access.
|
||||
*
|
||||
* @return The theta of the unit.
|
||||
*/
|
||||
public double theta() {
|
||||
return this.theta.getZenith();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the phi of the unit.
|
||||
* This is formatted as a double for quick access.
|
||||
*
|
||||
* @return The phi of the unit.
|
||||
*/
|
||||
public double phi() {
|
||||
return this.phi.getAzimuth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adjacent side of the unit.
|
||||
* <p>
|
||||
* This is calculated from a translation to Cartesian units,
|
||||
* and returning the X value.
|
||||
*
|
||||
* @return The adjacent side of the unit.
|
||||
*/
|
||||
public double adjacent() {
|
||||
CartesianUnit unit = Polarizer.toCartesianUnit(this);
|
||||
return unit.getPoint3D().getX().get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the opposite side of the unit.
|
||||
* <p>
|
||||
* This is calculated from a translation to Cartesian units,
|
||||
* and returning the Z value.
|
||||
*
|
||||
* @return The opposite side of the unit.
|
||||
*/
|
||||
public double opposite() {
|
||||
CartesianUnit unit = Polarizer.toCartesianUnit(this);
|
||||
return unit.getPoint3D().getZ().get();
|
||||
}
|
||||
}
|
@ -0,0 +1,422 @@
|
||||
package io.github.simplexdev.polarize.util;
|
||||
|
||||
import io.github.simplexdev.polarize.api.spatial.IScalar;
|
||||
import io.github.simplexdev.polarize.api.spatial.IVector;
|
||||
import io.github.simplexdev.polarize.cartesian.CartesianUnit;
|
||||
import io.github.simplexdev.polarize.polar.PolarUnit;
|
||||
import io.github.simplexdev.polarize.polar.SphericalUnit;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A utility class for generating sets of coordinate units based on different coordinate systems.
|
||||
* <p>
|
||||
* This class provides several methods for generating sets of coordinate units based on different
|
||||
* coordinate systems like Cartesian, Polar and Spherical. These methods take input vectors and scalars,
|
||||
* and generate corresponding coordinate units by iterating through angles in specific steps.
|
||||
* <p>
|
||||
* The generated sets of coordinate units can be used for interpolation and other mathematical operations
|
||||
* involving coordinates in different coordinate systems.
|
||||
*
|
||||
* @see CartesianUnit
|
||||
* @see PolarUnit
|
||||
* @see SphericalUnit
|
||||
* @see IVector
|
||||
* @see IScalar
|
||||
*/
|
||||
public class Interpolator {
|
||||
private Interpolator() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of CartesianUnits using the given IVector and step value.
|
||||
* This method generates the CartesianUnits by iterating through angles i and j in steps of the given value,
|
||||
* up to 45 degrees, and then computing their respective x, y and z values using the magnitude
|
||||
* and azimuth and polar angles of the input vector.
|
||||
*
|
||||
* @param vector the input vector used to generate the CartesianUnits
|
||||
* @param step the step value used for the angles 'i' and 'j'
|
||||
* @return a set of CartesianUnits generated from the input vector and step value
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Unit_vector">Unit vector</a>
|
||||
* @see IVector
|
||||
*/
|
||||
public static Set<CartesianUnit> cartesian45(IVector vector, double step) {
|
||||
Set<CartesianUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_45; i += step) {
|
||||
for (int j = 0; j <= Utilities.RADIAN_45; j += step) {
|
||||
CartesianUnit unit = new CartesianUnit(vector.length() * Math.sin(i) * Math.cos(j), vector.length() * Math.cos(i), vector.length() * Math.sin(i) * Math.sin(j));
|
||||
unitSet.add(unit);
|
||||
}
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of CartesianUnits using the given IVector and step value.
|
||||
* This method generates the CartesianUnits by iterating through angles i and j in steps of the given value,
|
||||
* up to 90 degrees, and then computing their respective x, y and z values using the magnitude
|
||||
* and azimuth and polar angles of the input vector.
|
||||
*
|
||||
* @param vector the input vector used to generate the CartesianUnits
|
||||
* @param step the step value used for the angles 'i' and 'j'
|
||||
* @return a set of CartesianUnits generated from the input vector and step value
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Unit_vector">Unit vector</a>
|
||||
* @see IVector
|
||||
*/
|
||||
public static Set<CartesianUnit> cartesian90(IVector vector, double step) {
|
||||
Set<CartesianUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_90; i += step) {
|
||||
for (int j = 0; j <= Utilities.RADIAN_90; j += step) {
|
||||
CartesianUnit unit = new CartesianUnit(vector.length() * Math.sin(i) * Math.cos(j), vector.length() * Math.cos(i), vector.length() * Math.sin(i) * Math.sin(j));
|
||||
unitSet.add(unit);
|
||||
}
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of CartesianUnits using the given IVector and step value.
|
||||
* This method generates the CartesianUnits by iterating through angles i and j in steps of the given value,
|
||||
* up to 180 degrees, and then computing their respective x, y and z values using the magnitude
|
||||
* and azimuth and polar angles of the input vector.
|
||||
*
|
||||
* @param vector the input vector used to generate the CartesianUnits
|
||||
* @param step the step value used for the angles 'i' and 'j'
|
||||
* @return a set of CartesianUnits generated from the input vector and step value
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Unit_vector">Unit vector</a>
|
||||
* @see IVector
|
||||
*/
|
||||
public static Set<CartesianUnit> cartesian180(IVector vector, double step) {
|
||||
Set<CartesianUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_180; i += step) {
|
||||
for (int j = 0; j <= Utilities.RADIAN_180; j += step) {
|
||||
CartesianUnit unit = new CartesianUnit(vector.length() * Math.sin(i) * Math.cos(j), vector.length() * Math.cos(i), vector.length() * Math.sin(i) * Math.sin(j));
|
||||
unitSet.add(unit);
|
||||
}
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of CartesianUnits using the given IVector and step value.
|
||||
* This method generates the CartesianUnits by iterating through angles i and j in steps of the given value,
|
||||
* up to 270 degrees, and then computing their respective x, y and z values using the magnitude
|
||||
* and azimuth and polar angles of the input vector.
|
||||
*
|
||||
* @param vector the input vector used to generate the CartesianUnits
|
||||
* @param step the step value used for the angles 'i' and 'j'
|
||||
* @return a set of CartesianUnits generated from the input vector and step value
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Unit_vector">Unit vector</a>
|
||||
* @see IVector
|
||||
*/
|
||||
public static Set<CartesianUnit> cartesian270(IVector vector, double step) {
|
||||
Set<CartesianUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_270; i += step) {
|
||||
for (int j = 0; j <= Utilities.RADIAN_270; j += step) {
|
||||
CartesianUnit unit = new CartesianUnit(vector.length() * Math.sin(i) * Math.cos(j), vector.length() * Math.cos(i), vector.length() * Math.sin(i) * Math.sin(j));
|
||||
unitSet.add(unit);
|
||||
}
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of CartesianUnits using the given IVector and step value.
|
||||
* This method generates the CartesianUnits by iterating through angles i and j in steps of the given value,
|
||||
* up to 360 degrees, and then computing their respective x, y and z values using the magnitude
|
||||
* and azimuth and polar angles of the input vector.
|
||||
*
|
||||
* @param vector the input vector used to generate the CartesianUnits
|
||||
* @param step the step value used for the angles 'i' and 'j'
|
||||
* @return a set of CartesianUnits generated from the input vector and step value
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Unit_vector">Unit vector</a>
|
||||
* @see IVector
|
||||
*/
|
||||
public static Set<CartesianUnit> cartesian360(IVector vector, double step) {
|
||||
Set<CartesianUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_360; i += step) {
|
||||
for (int j = 0; j <= Utilities.RADIAN_360; j += step) {
|
||||
CartesianUnit unit = new CartesianUnit(vector.length() * Math.sin(i) * Math.cos(j), vector.length() * Math.cos(i), vector.length() * Math.sin(i) * Math.sin(j));
|
||||
unitSet.add(unit);
|
||||
}
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of PolarUnits using the given IScalar and step value.
|
||||
* <p>
|
||||
* This method generates the PolarUnits by iterating through angles in steps of the given value,
|
||||
* up to a maximum of 45 degrees, and then computing their respective magnitude and angle values
|
||||
* using the magnitude of the input scalar.
|
||||
*
|
||||
* @param scalar The input scalar used to generate the PolarUnits.
|
||||
* @param step The step value used to increment angles while generating the PolarUnits.
|
||||
* @return A set of PolarUnits generated from the input scalar and step value.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Polar_coordinate_system">Polar coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Magnitude_(mathematics)">Magnitude</a>
|
||||
* @see IScalar
|
||||
*/
|
||||
public static Set<PolarUnit> polarSet45(IScalar scalar, double step) {
|
||||
Set<PolarUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_45; i += step) {
|
||||
PolarUnit unit = new PolarUnit(scalar.getMagnitude(), i);
|
||||
unitSet.add(unit);
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of PolarUnits using the given IScalar and step value.
|
||||
* <p>
|
||||
* This method generates the PolarUnits by iterating through angles in steps of the given value,
|
||||
* up to a maximum of 90 degrees, and then computing their respective magnitude and angle values
|
||||
* using the magnitude of the input scalar.
|
||||
*
|
||||
* @param scalar The input scalar used to generate the PolarUnits.
|
||||
* @param step The step value used to increment angles while generating the PolarUnits.
|
||||
* @return A set of PolarUnits generated from the input scalar and step value.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Polar_coordinate_system">Polar coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Magnitude_(mathematics)">Magnitude</a>
|
||||
* @see IScalar
|
||||
*/
|
||||
public static Set<PolarUnit> polarSet90(IScalar scalar, double step) {
|
||||
Set<PolarUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_90; i += step) {
|
||||
PolarUnit unit = new PolarUnit(scalar.getMagnitude(), i);
|
||||
unitSet.add(unit);
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of PolarUnits using the given IScalar and step value.
|
||||
* <p>
|
||||
* This method generates the PolarUnits by iterating through angles in steps of the given value,
|
||||
* up to a maximum of 180 degrees, and then computing their respective magnitude and angle values
|
||||
* using the magnitude of the input scalar.
|
||||
*
|
||||
* @param scalar The input scalar used to generate the PolarUnits.
|
||||
* @param step The step value used to increment angles while generating the PolarUnits.
|
||||
* @return A set of PolarUnits generated from the input scalar and step value.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Polar_coordinate_system">Polar coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Magnitude_(mathematics)">Magnitude</a>
|
||||
* @see IScalar
|
||||
*/
|
||||
public static Set<PolarUnit> polarSet180(IScalar scalar, double step) {
|
||||
Set<PolarUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_180; i += step) {
|
||||
PolarUnit unit = new PolarUnit(scalar.getMagnitude(), i);
|
||||
unitSet.add(unit);
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of PolarUnits using the given IScalar and step value.
|
||||
* <p>
|
||||
* This method generates the PolarUnits by iterating through angles in steps of the given value,
|
||||
* up to a maximum of 270 degrees, and then computing their respective magnitude and angle values
|
||||
* using the magnitude of the input scalar.
|
||||
*
|
||||
* @param scalar The input scalar used to generate the PolarUnits.
|
||||
* @param step The step value used to increment angles while generating the PolarUnits.
|
||||
* @return A set of PolarUnits generated from the input scalar and step value.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Polar_coordinate_system">Polar coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Magnitude_(mathematics)">Magnitude</a>
|
||||
* @see IScalar
|
||||
*/
|
||||
public static Set<PolarUnit> polarSet270(IScalar scalar, double step) {
|
||||
Set<PolarUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_270; i += step) {
|
||||
PolarUnit unit = new PolarUnit(scalar.getMagnitude(), i);
|
||||
unitSet.add(unit);
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of PolarUnits using the given IScalar and step value.
|
||||
* <p>
|
||||
* This method generates the PolarUnits by iterating through angles in steps of the given value,
|
||||
* up to a maximum of 45 degrees, and then computing their respective magnitude and angle values
|
||||
* using the magnitude of the input scalar.
|
||||
*
|
||||
* @param scalar The input scalar used to generate the PolarUnits.
|
||||
* @param step The step value used to increment angles while generating the PolarUnits.
|
||||
* @return A set of PolarUnits generated from the input scalar and step value.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Polar_coordinate_system">Polar coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Magnitude_(mathematics)">Magnitude</a>
|
||||
* @see IScalar
|
||||
*/
|
||||
public static Set<PolarUnit> polarSet360(IScalar scalar, double step) {
|
||||
Set<PolarUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i < Utilities.RADIAN_360; i += step) {
|
||||
PolarUnit unit = new PolarUnit(scalar.getMagnitude(), i);
|
||||
unitSet.add(unit);
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of SphericalUnits using the given IScalar and step value.
|
||||
* This method generates the SphericalUnits by iterating through angles i and j in steps of the given value,
|
||||
* up to a maximum of 45 degrees, and then computing their respective magnitude, zenith and azimuth
|
||||
* values using the magnitude of the input scalar.
|
||||
*
|
||||
* @param scalar The input scalar used to generate the SphericalUnits.
|
||||
* @param step The step value used to increment angles i and j while generating the SphericalUnits.
|
||||
* @return A set of SphericalUnits generated from the input scalar and step value.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Spherical_coordinate_system">Spherical coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Inclination">Inclination</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Azimuth">Azimuth</a>
|
||||
* @see IScalar
|
||||
*/
|
||||
public static Set<SphericalUnit> sphericalUnit45(IScalar scalar, double step) {
|
||||
Set<SphericalUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_45; i += step) {
|
||||
for (int j = 0; j <= Utilities.RADIAN_45; j += step) {
|
||||
SphericalUnit unit = new SphericalUnit(i, j, scalar.getMagnitude());
|
||||
unitSet.add(unit);
|
||||
}
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of SphericalUnits using the given IScalar and step value.
|
||||
* This method generates the SphericalUnits by iterating through angles i and j in steps of the given value,
|
||||
* up to a maximum of 90 degrees, and then computing their respective magnitude, zenith and azimuth
|
||||
* values using the magnitude of the input scalar.
|
||||
*
|
||||
* @param scalar The input scalar used to generate the SphericalUnits.
|
||||
* @param step The step value used to increment angles i and j while generating the SphericalUnits.
|
||||
* @return A set of SphericalUnits generated from the input scalar and step value.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Spherical_coordinate_system">Spherical coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Inclination">Inclination</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Azimuth">Azimuth</a>
|
||||
* @see IScalar
|
||||
*/
|
||||
public static Set<SphericalUnit> sphericalUnit90(IScalar scalar, double step) {
|
||||
Set<SphericalUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_90; i += step) {
|
||||
for (int j = 0; j <= Utilities.RADIAN_90; j += step) {
|
||||
SphericalUnit unit = new SphericalUnit(i, j, scalar.getMagnitude());
|
||||
unitSet.add(unit);
|
||||
}
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of SphericalUnits using the given IScalar and step value.
|
||||
* This method generates the SphericalUnits by iterating through angles i and j in steps of the given value,
|
||||
* up to a maximum of 180 degrees, and then computing their respective magnitude, zenith and azimuth
|
||||
* values using the magnitude of the input scalar.
|
||||
*
|
||||
* @param scalar The input scalar used to generate the SphericalUnits.
|
||||
* @param step The step value used to increment angles i and j while generating the SphericalUnits.
|
||||
* @return A set of SphericalUnits generated from the input scalar and step value.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Spherical_coordinate_system">Spherical coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Inclination">Inclination</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Azimuth">Azimuth</a>
|
||||
* @see IScalar
|
||||
*/
|
||||
public static Set<SphericalUnit> sphericalUnit180(IScalar scalar, double step) {
|
||||
Set<SphericalUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_180; i += step) {
|
||||
for (int j = 0; j <= Math.PI; j += step) {
|
||||
SphericalUnit unit = new SphericalUnit(i, j, scalar.getMagnitude());
|
||||
unitSet.add(unit);
|
||||
}
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of SphericalUnits using the given IScalar and step value.
|
||||
* This method generates the SphericalUnits by iterating through angles i and j in steps of the given value,
|
||||
* up to a maximum of 270 degrees, and then computing their respective magnitude, zenith and azimuth
|
||||
* values using the magnitude of the input scalar.
|
||||
*
|
||||
* @param scalar The input scalar used to generate the SphericalUnits.
|
||||
* @param step The step value used to increment angles i and j while generating the SphericalUnits.
|
||||
* @return A set of SphericalUnits generated from the input scalar and step value.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Spherical_coordinate_system">Spherical coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Inclination">Inclination</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Azimuth">Azimuth</a>
|
||||
* @see IScalar
|
||||
*/
|
||||
public static Set<SphericalUnit> sphericalUnit270(IScalar scalar, double step) {
|
||||
Set<SphericalUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i <= Utilities.RADIAN_270; i += step) {
|
||||
for (int j = 0; j <= Utilities.RADIAN_270; j += step) {
|
||||
SphericalUnit unit = new SphericalUnit(i, j, scalar.getMagnitude());
|
||||
unitSet.add(unit);
|
||||
}
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of SphericalUnits using the given IScalar and step value.
|
||||
* This method generates the SphericalUnits by iterating through angles i and j in steps of the given value,
|
||||
* up to a maximum of 360 degrees, and then computing their respective magnitude, zenith and azimuth
|
||||
* values using the magnitude of the input scalar.
|
||||
*
|
||||
* @param scalar The input scalar used to generate the SphericalUnits.
|
||||
* @param step The step value used to increment angles i and j while generating the SphericalUnits.
|
||||
* @return A set of SphericalUnits generated from the input scalar and step value.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Spherical_coordinate_system">Spherical coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Inclination">Inclination</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Azimuth">Azimuth</a>
|
||||
* @see IScalar
|
||||
*/
|
||||
public static Set<SphericalUnit> sphericalUnit360(IScalar scalar, double step) {
|
||||
Set<SphericalUnit> unitSet = new HashSet<>();
|
||||
|
||||
for (int i = 0; i < Utilities.RADIAN_360; i += step) {
|
||||
for (int j = 0; j < Utilities.RADIAN_360; j += step) {
|
||||
SphericalUnit unit = new SphericalUnit(i, j, scalar.getMagnitude());
|
||||
unitSet.add(unit);
|
||||
}
|
||||
}
|
||||
|
||||
return unitSet;
|
||||
}
|
||||
}
|
@ -0,0 +1,342 @@
|
||||
package io.github.simplexdev.polarize.util;
|
||||
|
||||
import io.github.simplexdev.polarize.api.rotation.IAxisAngle;
|
||||
import io.github.simplexdev.polarize.api.rotation.IQuaternion;
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint2D;
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint3D;
|
||||
import io.github.simplexdev.polarize.api.spatial.IScalar;
|
||||
import io.github.simplexdev.polarize.api.spatial.IVector;
|
||||
import io.github.simplexdev.polarize.api.units.Phi;
|
||||
import io.github.simplexdev.polarize.api.units.Radius;
|
||||
import io.github.simplexdev.polarize.api.units.Theta;
|
||||
import io.github.simplexdev.polarize.cartesian.CartesianUnit;
|
||||
import io.github.simplexdev.polarize.math.AxisAngle;
|
||||
import io.github.simplexdev.polarize.math.Quaternion;
|
||||
import io.github.simplexdev.polarize.polar.PolarUnit;
|
||||
import io.github.simplexdev.polarize.polar.SphericalUnit;
|
||||
|
||||
/**
|
||||
* This class provides static methods for converting between different polar coordinate systems and their Cartesian equivalents.
|
||||
* It includes methods for converting to and from polar coordinates in 2D and 3D, as well as to and from spherical coordinates.
|
||||
*/
|
||||
public class Polarizer {
|
||||
private Polarizer() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a {@link PolarUnit} to a {@link CartesianUnit}.
|
||||
* This method takes a PolarUnit and converts it to a corresponding CartesianUnit by computing its x and z values.
|
||||
* The x and z values are computed using the radius and theta angles of the input PolarUnit, and assuming that the y
|
||||
* coordinate of the resulting CartesianUnit is zero.
|
||||
*
|
||||
* @param unit The input PolarUnit to convert to a CartesianUnit.
|
||||
* @return A new CartesianUnit instance generated from the input PolarUnit.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Polar_coordinate_system">Polar coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian coordinate system</a>
|
||||
*/
|
||||
public static CartesianUnit toCartesianUnit(PolarUnit unit) {
|
||||
double x = unit.radius() * Math.sin(unit.theta());
|
||||
double z = unit.radius() * Math.cos(unit.theta());
|
||||
return new CartesianUnit(x, 0, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a {@link IScalar} and a {@link Theta} instance to a {@link CartesianUnit}.
|
||||
* This method takes a scalar magnitude and a {@link Theta} instance and computes the corresponding x and z values
|
||||
* for the resulting CartesianUnit, with a y coordinate of zero. The x and z values are computed using the scalar
|
||||
* magnitude and the zenith angle of the input Theta instance.
|
||||
*
|
||||
* @param scalar The scalar magnitude of the input.
|
||||
* @param theta The input Theta instance containing the zenith angle.
|
||||
* @return A new CartesianUnit instance generated from the input scalar and theta values.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Spherical_coordinate_system">Spherical coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian coordinate system</a>
|
||||
*/
|
||||
public static CartesianUnit toCartesianUnit(IScalar scalar, Theta theta) {
|
||||
double x = scalar.getMagnitude() * Math.sin(theta.getZenith());
|
||||
double z = scalar.getMagnitude() * Math.cos(theta.getZenith());
|
||||
return new CartesianUnit(x, 0, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a radius and a theta value to a {@link CartesianUnit}.
|
||||
* This method takes a radius value and a theta value and computes the corresponding x and z values for the resulting
|
||||
* CartesianUnit, with a y coordinate of zero. The x and z values are computed using the radius value and the input theta
|
||||
* value.
|
||||
*
|
||||
* @param radius The radius value of the input.
|
||||
* @param theta The input theta value containing the zenith angle in radians.
|
||||
* @return A new CartesianUnit instance generated from the input radius and theta values.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Spherical_coordinate_system">Spherical coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian coordinate system</a>
|
||||
*/
|
||||
public static CartesianUnit toCartesianUnit(double radius, double theta) {
|
||||
double x = radius * Math.sin(theta);
|
||||
double z = radius * Math.cos(theta);
|
||||
return new CartesianUnit(x, 0, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a {@link SphericalUnit} to a {@link CartesianUnit}.
|
||||
* This method takes a {@link SphericalUnit} object and computes the corresponding x, y, and z values for the resulting
|
||||
* CartesianUnit using the input's radius, theta, and phi values. The x, y, and z values are computed using the sine and
|
||||
* cosine trigonometric functions of the input's theta and phi values.
|
||||
*
|
||||
* @param unit The {@link SphericalUnit} instance to be converted to Cartesian coordinates.
|
||||
* @return A new {@link CartesianUnit} instance generated from the input {@link SphericalUnit} object.
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Spherical_coordinate_system">Spherical coordinate system</a>
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian coordinate system</a>
|
||||
*/
|
||||
public static CartesianUnit toCartesianUnit(SphericalUnit unit) {
|
||||
double x = unit.radius() * Math.sin(unit.theta()) * Math.cos(unit.phi());
|
||||
double y = unit.radius() * Math.cos(unit.theta());
|
||||
double z = unit.radius() * Math.sin(unit.theta()) * Math.sin(unit.phi());
|
||||
return new CartesianUnit(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a scalar with theta and phi coordinates to a CartesianUnit.
|
||||
*
|
||||
* @param scalar the scalar value of the vector
|
||||
* @param theta the theta coordinate of the vector
|
||||
* @param phi the phi coordinate of the vector
|
||||
* @return the CartesianUnit representation of the vector
|
||||
*/
|
||||
public static CartesianUnit toCartesianUnit(IScalar scalar, Theta theta, Phi phi) {
|
||||
double x = scalar.getMagnitude() * Math.sin(theta.getZenith()) * Math.cos(phi.getAzimuth());
|
||||
double y = scalar.getMagnitude() * Math.cos(theta.getZenith());
|
||||
double z = scalar.getMagnitude() * Math.sin(theta.getZenith()) * Math.sin(phi.getAzimuth());
|
||||
return new CartesianUnit(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a spherical coordinate (radius, theta, phi) to Cartesian coordinates (x, y, z).
|
||||
* <p>
|
||||
* This method uses the following formula:
|
||||
* <pre>
|
||||
* {@code radius = sqrt(x^2 + y^2 + z^2)}
|
||||
* {@code theta = acos(y / radius)}
|
||||
* {@code phi = atan2(z, x)}
|
||||
* {@code x = radius * sin(theta) * cos(phi)}
|
||||
* {@code y = radius * cos(theta)}
|
||||
* {@code z = radius * sin(theta) * sin(phi)}
|
||||
* </pre>
|
||||
*
|
||||
* @param radius the radius of the spherical coordinate
|
||||
* @param theta the theta angle in radians of the spherical coordinate
|
||||
* @param phi the phi angle in radians of the spherical coordinate
|
||||
* @return the corresponding CartesianUnit
|
||||
*/
|
||||
public static CartesianUnit toCartesianUnit(double radius, double theta, double phi) {
|
||||
double x = radius * Math.sin(theta) * Math.cos(phi);
|
||||
double y = radius * Math.cos(theta);
|
||||
double z = radius * Math.sin(theta) * Math.sin(phi);
|
||||
return new CartesianUnit(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a {@link CartesianUnit} to a {@link PolarUnit}.
|
||||
* This method uses the same formula as {@link #toPolarUnit(double, double)}.
|
||||
*
|
||||
* @param unit the CartesianUnit to be converted
|
||||
* @return a PolarUnit representing the same point as the input CartesianUnit
|
||||
*/
|
||||
public static PolarUnit toPolarUnit(CartesianUnit unit) {
|
||||
double radius = Math.sqrt(unit.getPoint2D().getX().get() * unit.getPoint2D().getX().get() + unit.getPoint2D().getZ().get() * unit.getPoint2D().getZ().get());
|
||||
double theta = Math.atan2(unit.getPoint2D().getX().get(), unit.getPoint2D().getZ().get());
|
||||
return new PolarUnit(radius, theta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@link CartesianUnit} to a {@link PolarUnit}.
|
||||
* This method uses the same formula as {@link #toPolarUnit(double, double)},
|
||||
* with the exception that the radius is computed using the given {@link IVector}
|
||||
* instead of the {@link IPoint2D}'s x and z coordinates.
|
||||
*
|
||||
* @param unit the {@link CartesianUnit} to convert
|
||||
* @param vector the {@link IVector} representing the radius of the resulting {@link PolarUnit}
|
||||
* @return a {@link PolarUnit} representing the same point as the given {@link CartesianUnit}
|
||||
*/
|
||||
public static PolarUnit toPolarUnit(CartesianUnit unit, IVector vector) {
|
||||
double radius = vector.length();
|
||||
double theta = Math.atan2(unit.getPoint2D().getX().get(), unit.getPoint2D().getZ().get());
|
||||
return new PolarUnit(radius, theta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link PolarUnit} representing the polar coordinates of the given 2D point in relation to the given vector.
|
||||
* <p>
|
||||
* This method uses the same formula as {@link #toPolarUnit(double, double)}.
|
||||
*
|
||||
* @param point the point to convert to polar coordinates
|
||||
* @param vector the vector used as a reference for the polar coordinates
|
||||
* @return a PolarUnit representing the polar coordinates of the given point
|
||||
*/
|
||||
public static PolarUnit toPolarUnit(IPoint2D point, IVector vector) {
|
||||
double radius = vector.length();
|
||||
double theta = Math.atan2(point.getX().get(), point.getZ().get());
|
||||
return new PolarUnit(radius, theta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a 2D point in Cartesian coordinates to a polar unit.
|
||||
* <p>
|
||||
* The conversion is based on the following formula:
|
||||
* <pre>
|
||||
* {@code radius = sqrt(x^2 + z^2)}
|
||||
* {@code theta = atan2(x, z)}
|
||||
* where:
|
||||
* x = {@link IPoint2D#getX()}
|
||||
* z = {@link IPoint2D#getZ()}
|
||||
* </pre>
|
||||
*
|
||||
* @param x the x-coordinate of the point
|
||||
* @param z the z-coordinate of the point
|
||||
* @return a {@link PolarUnit} representing the polar coordinates of the point
|
||||
*/
|
||||
public static PolarUnit toPolarUnit(double x, double z) {
|
||||
double radius = Math.sqrt(x * x + z * z);
|
||||
double theta = Math.atan2(x, z);
|
||||
return new PolarUnit(radius, theta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a {@link CartesianUnit} to a {@link SphericalUnit}.
|
||||
* <p>
|
||||
* The radius is calculated by creating a new vector based on the CartesianUnit's
|
||||
* x, y, and z coordinates, then using {@link IVector#length()} to acquire the {@link IScalar}.
|
||||
* <p>
|
||||
* The angles are then calculated from {@link IScalar#getMagnitude()}.
|
||||
* <p>
|
||||
* This method uses the same formula as {@link #toSphericalUnit(double, double, double)}.
|
||||
*
|
||||
* @param unit the CartesianUnit to be converted.
|
||||
* @return the SphericalUnit representing the same point as the input CartesianUnit.
|
||||
*/
|
||||
public static SphericalUnit toSphericalUnit(CartesianUnit unit) {
|
||||
double radius = Math.sqrt(unit.getPoint3D().getX().get()
|
||||
* unit.getPoint3D().getX().get()
|
||||
+ unit.getPoint3D().getY().get()
|
||||
* unit.getPoint3D().getY().get()
|
||||
+ unit.getPoint3D().getZ().get()
|
||||
* unit.getPoint3D().getZ().get());
|
||||
double theta = Math.acos(unit.getPoint3D().getY().get()
|
||||
/ radius);
|
||||
double phi = Math.atan2(unit.getPoint3D().getX().get(),
|
||||
unit.getPoint3D().getZ().get());
|
||||
return new SphericalUnit(radius, theta, phi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified {@link IPoint3D} to a {@link SphericalUnit} using the specified {@link IVector}.
|
||||
* <p>
|
||||
* This method uses the same formula as {@link #toSphericalUnit(double, double, double)}
|
||||
*
|
||||
* @param point the point to convert to a spherical unit
|
||||
* @param vector the vector to use for the conversion
|
||||
* @return a new {@link SphericalUnit} representing the point in spherical coordinates
|
||||
*/
|
||||
public static SphericalUnit toSphericalUnit(IPoint3D point, IVector vector) {
|
||||
double radius = vector.length();
|
||||
double theta = Math.acos(point.getY().get() / radius);
|
||||
double phi = Math.atan2(point.getX().get(), point.getZ().get());
|
||||
return new SphericalUnit(radius, theta, phi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given Cartesian coordinates (x, y, z) to spherical coordinates (radius, theta, phi).
|
||||
* <p>
|
||||
* The conversion is based on the following formula:
|
||||
* <pre>
|
||||
* {@code radius = sqrt(x^2 + y^2 + z^2)}
|
||||
* {@code theta = acos(y / radius)}
|
||||
* {@code phi = atan2(x, z)}
|
||||
* where:
|
||||
* {@code radius} is the {@link Radius} (scalar) of the spherical coordinate
|
||||
* {@code theta} is the {@link Theta} angle (zenith) in radians of the spherical coordinate
|
||||
* {@code phi} is the {@link Phi} angle (azimuth) in radians of the spherical coordinate
|
||||
* </pre>
|
||||
* <p>
|
||||
* The resulting spherical coordinates are returned as a new {@link SphericalUnit}.
|
||||
* <p>
|
||||
* The returned {@link SphericalUnit} is guaranteed to reflect the same coordinates as the input.
|
||||
*
|
||||
* @param x the x-coordinate
|
||||
* @param y the y-coordinate
|
||||
* @param z the z-coordinate
|
||||
* @return a new {@link SphericalUnit} representing the converted spherical coordinates
|
||||
*/
|
||||
public static SphericalUnit toSphericalUnit(double x, double y, double z) {
|
||||
double radius = Math.sqrt(x * x + y * y + z * z);
|
||||
double theta = Math.acos(y / radius);
|
||||
double phi = Math.atan2(x, z);
|
||||
return new SphericalUnit(radius, theta, phi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@link IQuaternion} to an {@link IAxisAngle}.
|
||||
* <p>
|
||||
* The conversion is based on the following formula:
|
||||
* <pre>
|
||||
* {@code r = (x * sin(angle/2), y * sin(angle/2), z * sin(angle/2), cos(angle/2))}
|
||||
* where:
|
||||
* sin = {@link Math#sin(double)},
|
||||
* cos = {@link Math#cos(double)},
|
||||
* x = {@link IQuaternion#getX()},
|
||||
* y = {@link IQuaternion#getY()},
|
||||
* z = {@link IQuaternion#getZ()}
|
||||
* angle = {@link IQuaternion#getW()}
|
||||
* r = {@link IAxisAngle}
|
||||
* </pre>
|
||||
*
|
||||
* @param quaternion the {@link IQuaternion} to convert
|
||||
* @return a new {@link IAxisAngle} representing the converted {@link IQuaternion}
|
||||
*/
|
||||
public static IAxisAngle toAxisAngle(IQuaternion quaternion) {
|
||||
double angle = 2 * Math.acos(quaternion.getW());
|
||||
double s = Math.sqrt(1 - quaternion.getW() * quaternion.getW());
|
||||
|
||||
double x, y, z;
|
||||
|
||||
if (s < 0.001) {
|
||||
x = quaternion.getX();
|
||||
y = quaternion.getY();
|
||||
z = quaternion.getZ();
|
||||
} else {
|
||||
x = quaternion.getX() / s;
|
||||
y = quaternion.getY() / s;
|
||||
z = quaternion.getZ() / s;
|
||||
}
|
||||
return new AxisAngle(x, y, z, () -> angle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@link IAxisAngle} to a {@link IQuaternion}.
|
||||
* <p>
|
||||
* The conversion is based on the following formula:
|
||||
* <pre>
|
||||
* {@code q = (x * sin(angle / 2), y * sin(angle / 2), z * sin(angle / 2), cos(angle / 2))}
|
||||
* where:
|
||||
* sin = {@link Math#sin(double)}
|
||||
* cos = {@link Math#cos(double)}
|
||||
* angle = {@link Theta#getZenith()}
|
||||
* x = {@link IAxisAngle#getX()}
|
||||
* y = {@link IAxisAngle#getY()}
|
||||
* z = {@link IAxisAngle#getZ()}
|
||||
* q = the resulting quaternion.
|
||||
* </pre>
|
||||
*
|
||||
* @param axisAngle the {@link IAxisAngle} to convert
|
||||
* @return a {@link IQuaternion} representing the same rotation as the given {@link IAxisAngle}
|
||||
*/
|
||||
public IQuaternion toQuaternion(IAxisAngle axisAngle) {
|
||||
double angle = axisAngle.getAngle().getZenith();
|
||||
double x = axisAngle.getX();
|
||||
double y = axisAngle.getY();
|
||||
double z = axisAngle.getZ();
|
||||
double w = Math.cos(angle / 2);
|
||||
double s = Math.sin(angle / 2);
|
||||
return new Quaternion(x * s, y * s, z * s, w);
|
||||
}
|
||||
}
|
@ -0,0 +1,194 @@
|
||||
package io.github.simplexdev.polarize.util;
|
||||
|
||||
import io.github.simplexdev.polarize.api.rotation.IQuaternion;
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint2D;
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint3D;
|
||||
import io.github.simplexdev.polarize.api.units.Point;
|
||||
import io.github.simplexdev.polarize.cartesian.Point2D;
|
||||
import io.github.simplexdev.polarize.cartesian.Point3D;
|
||||
import io.github.simplexdev.polarize.math.Quaternion;
|
||||
import io.github.simplexdev.polarize.polar.Delta;
|
||||
import io.github.simplexdev.polarize.polar.PolarUnit;
|
||||
import io.github.simplexdev.polarize.polar.SphericalUnit;
|
||||
|
||||
/**
|
||||
* A utility class for rotating points in 2d and 3d space.
|
||||
* This class supports rotations for Cartesian, Spherical, and Polar coordinates.
|
||||
* <p>
|
||||
* Typically, rotations in polar / spherical units are done with delta values.
|
||||
* The rotations in Cartesian units are done with a quaternion.
|
||||
*/
|
||||
public class Rotator {
|
||||
/**
|
||||
* This class should not be instantiated.
|
||||
*/
|
||||
private Rotator() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a point in 3d space using spherical units.
|
||||
* The returned result is a point in 3d space represented by {@link IPoint3D}.
|
||||
* This will rotate the point around the x-axis.
|
||||
*
|
||||
* @param point the point to rotate.
|
||||
* @param unit the spherical unit to rotate the point with.
|
||||
* @return the rotated point.
|
||||
*/
|
||||
public static IPoint3D rotateX(IPoint3D point, SphericalUnit unit) {
|
||||
double x = point.getX().get();
|
||||
double y = point.getY().multiply(Math.cos(unit.theta()))
|
||||
- point.getZ().multiply(Math.sin(unit.theta()));
|
||||
double z = point.getY().multiply(Math.sin(unit.theta()))
|
||||
+ point.getZ().multiply(Math.cos(unit.theta()));
|
||||
|
||||
return Point.fromDouble(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a point in 3d space using spherical units.
|
||||
* The returned result is a point in 3d space represented by {@link IPoint3D}.
|
||||
* This will rotate the point around the y-axis.
|
||||
*
|
||||
* @param point the point to rotate.
|
||||
* @param unit the spherical unit to rotate the point with.
|
||||
* @return the rotated point.
|
||||
*/
|
||||
public static IPoint3D rotateY(IPoint3D point, SphericalUnit unit) {
|
||||
double x = point.getX().multiply(Math.cos(unit.phi()))
|
||||
- point.getZ().multiply(Math.sin(unit.phi()));
|
||||
double y = point.getY().get();
|
||||
double z = point.getX().multiply(Math.sin(unit.phi()))
|
||||
+ point.getZ().multiply(Math.cos(unit.phi()));
|
||||
|
||||
return Point.fromDouble(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a point in 3d space using spherical units.
|
||||
* The returned result is a point in 3d space represented by {@link IPoint3D}.
|
||||
* This will rotate the point around the z-axis.
|
||||
*
|
||||
* @param point the point to rotate.
|
||||
* @param unit the spherical unit to rotate the point with.
|
||||
* @return the rotated point.
|
||||
*/
|
||||
public static IPoint3D rotateZ(IPoint3D point, SphericalUnit unit) {
|
||||
double x = point.getX().multiply(Math.cos(unit.theta()))
|
||||
- point.getY().multiply(Math.sin(unit.theta()));
|
||||
double y = point.getX().multiply(Math.sin(unit.theta()))
|
||||
+ point.getY().multiply(Math.cos(unit.theta()));
|
||||
double z = point.getZ().get();
|
||||
|
||||
return Point.fromDouble(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a point in 3d space using spherical units.
|
||||
* The returned result is a point in 3d space represented by {@link IPoint3D}.
|
||||
* This will rotate the point around the x-axis, y-axis, and z-axis.
|
||||
*
|
||||
* @param point the point to rotate.
|
||||
* @param delta the delta values to rotate the point with.
|
||||
* @param unit the spherical unit to rotate the point with.
|
||||
* @return the rotated point.
|
||||
*/
|
||||
public static IPoint3D fullRotation(IPoint3D point, Delta delta, SphericalUnit unit) {
|
||||
double r = unit.radius() * Math.cos(unit.theta() + delta.theta()) * Math.cos(unit.phi() + delta.phi());
|
||||
double theta = Math.atan2(point.getX().get(), point.getZ().get()) + delta.theta();
|
||||
double phi = Math.atan2(Utilities.magnitudeOf(point.getX().get(), point.getZ().get()), point.getY().get()) + delta.phi();
|
||||
|
||||
double xRot = r * Math.sin(theta) * Math.cos(phi);
|
||||
double yRot = r * Math.cos(theta);
|
||||
double zRot = r * Math.sin(theta) * Math.sin(phi);
|
||||
|
||||
return Point.fromDouble(xRot, yRot, zRot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a point in 2d space using spherical units.
|
||||
* The returned result is a point in 2d space represented by {@link IPoint2D}.
|
||||
* This will rotate the point around the x-axis.
|
||||
*
|
||||
* @param point the point to rotate.
|
||||
* @param unit the polar unit to rotate the point with.
|
||||
* @return the rotated point.
|
||||
*/
|
||||
public static IPoint2D rotateX(IPoint2D point, PolarUnit unit) {
|
||||
double x = point.getZ().multiply(Math.cos(unit.theta()))
|
||||
- point.getX().multiply(Math.sin(unit.theta()));
|
||||
double z = point.getZ().multiply(Math.sin(unit.theta()))
|
||||
+ point.getX().multiply(Math.cos(unit.theta()));
|
||||
return Point.fromDouble(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a point in 2d space using spherical units.
|
||||
* The returned result is a point in 2d space represented by {@link IPoint2D}.
|
||||
* This will rotate the point around the y-axis.
|
||||
*
|
||||
* @param point the point to rotate.
|
||||
* @param unit the polar unit to rotate the point with.
|
||||
* @return the rotated point.
|
||||
*/
|
||||
public static IPoint2D rotateZ(IPoint2D point, PolarUnit unit) {
|
||||
double x = point.getX().multiply(Math.cos(unit.theta()))
|
||||
- point.getZ().multiply(Math.sin(unit.theta()));
|
||||
double z = point.getX().multiply(Math.sin(unit.theta()))
|
||||
+ point.getZ().multiply(Math.cos(unit.theta()));
|
||||
return Point.fromDouble(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a point in 2d space using spherical units.
|
||||
* The returned result is a point in 2d space represented by {@link IPoint2D}.
|
||||
* This will rotate the point around the x-axis and z-axis.
|
||||
*
|
||||
* @param point the point to rotate.
|
||||
* @param unit the polar unit to rotate the point with.
|
||||
* @return the rotated point.
|
||||
*/
|
||||
public static IPoint2D fullRotation(IPoint2D point, SphericalUnit unit) {
|
||||
double x = point.getX().multiply(Math.cos(unit.theta()))
|
||||
- point.getZ().multiply(Math.sin(unit.theta()));
|
||||
double z = point.getX().multiply(Math.sin(unit.theta()))
|
||||
+ point.getZ().multiply(Math.cos(unit.theta()));
|
||||
return Point.fromDouble(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a point in 3d space using a quaternion.
|
||||
* The returned result is a point in 3d space represented by {@link IPoint3D}.
|
||||
*
|
||||
* @param point the point to rotate.
|
||||
* @param quaternion the quaternion to rotate the point with.
|
||||
* @return the rotated point.
|
||||
*/
|
||||
public static IPoint3D rotate(IPoint3D point, IQuaternion quaternion) {
|
||||
IQuaternion pQuat = new Quaternion(0.0, point.getX().get(), point.getY().get(), point.getZ().get());
|
||||
|
||||
IQuaternion conjugate = quaternion.conjugate();
|
||||
|
||||
IQuaternion w = conjugate.multiply(pQuat).multiply(quaternion);
|
||||
|
||||
return Point.fromDouble(w.getX(), w.getY(), w.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a point in 2d space using a quaternion.
|
||||
* The returned result is a point in 2d space represented by {@link IPoint2D}.
|
||||
*
|
||||
* @param point the point to rotate.
|
||||
* @param quaternion the quaternion to rotate the point with.
|
||||
* @return the rotated point.
|
||||
*/
|
||||
public static IPoint2D rotate(IPoint2D point, IQuaternion quaternion) {
|
||||
IQuaternion pQuat = new Quaternion(0.0, point.getX().get(), 0.0, point.getZ().get());
|
||||
|
||||
IQuaternion conjugate = quaternion.conjugate();
|
||||
|
||||
IQuaternion w = conjugate.multiply(pQuat).multiply(quaternion);
|
||||
|
||||
return Point.fromDouble(w.getX(), w.getZ());
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package io.github.simplexdev.polarize.util;
|
||||
|
||||
public class Utilities {
|
||||
/**
|
||||
* The value of pi divided by 4.
|
||||
* This represents 45 degrees in radians.
|
||||
*/
|
||||
public static final double RADIAN_45 = Math.PI / 4;
|
||||
/**
|
||||
* The value of pi divided by 2.
|
||||
* This represents 90 degrees in radians.
|
||||
*/
|
||||
public static final double RADIAN_90 = Math.PI / 2;
|
||||
/**
|
||||
* The value of pi.
|
||||
* This represents 180 degrees in radians.
|
||||
*/
|
||||
public static final double RADIAN_180 = Math.PI;
|
||||
/**
|
||||
* The value of pi multiplied by 1.5.
|
||||
* This represents 270 degrees in radians.
|
||||
*/
|
||||
public static final double RADIAN_270 = Math.PI * 1.5;
|
||||
/**
|
||||
* The value of pi multiplied by 2.
|
||||
* This represents 360 degrees in radians.
|
||||
*/
|
||||
public static final double RADIAN_360 = Math.PI * 2;
|
||||
|
||||
private Utilities() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the magnitude of a vector in 2D Cartesian coordinate system.
|
||||
*
|
||||
* @param x the x-coordinate of the vector
|
||||
* @param z the z-coordinate of the vector
|
||||
* @return the magnitude of the vector
|
||||
*/
|
||||
public static double magnitudeOf(double x, double z) {
|
||||
return Math.sqrt(x * x + z * z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the magnitude of a vector in 3D Cartesian coordinate system.
|
||||
*
|
||||
* @param x the x-coordinate of the vector
|
||||
* @param y the y-coordinate of the vector
|
||||
* @param z the z-coordinate of the vector
|
||||
* @return the magnitude of the vector
|
||||
*/
|
||||
public static double magnitudeOf(double x, double y, double z) {
|
||||
return Math.sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package io.github.simplexdev.polarize.math;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.github.simplexdev.polarize.api.spatial.IPoint3D;
|
||||
import io.github.simplexdev.polarize.cartesian.Point3D;
|
||||
import io.github.simplexdev.polarize.log.PolarizeLogger;
|
||||
import io.github.simplexdev.polarize.math.function.FibonacciLattice;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class FibonacciLatticeTest
|
||||
{
|
||||
/**
|
||||
* Method under test: {@link FibonacciLattice#populate(IPoint3D, int, double)}
|
||||
*/
|
||||
@Test
|
||||
void testDisplayPoints()
|
||||
{
|
||||
FibonacciLattice.populate(new Point3D(10,15,5), 10, 0.1)
|
||||
.forEach(point -> PolarizeLogger.info("X: " + point.getX() + " Y: " + point.getY() + " Z: " + point.getZ()));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package io.github.simplexdev.polarize.math;
|
||||
|
||||
import io.github.simplexdev.polarize.cartesian.Point3D;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class Point3DTest
|
||||
{
|
||||
/**
|
||||
* Method under test: {@link Point3D#drawLineTestMethod()}
|
||||
*/
|
||||
@Test
|
||||
void testDrawLineTestMethod()
|
||||
{
|
||||
// TODO: Complete this test.
|
||||
// Diffblue AI was unable to find a test
|
||||
|
||||
(new Point3D(2.0d, 3.0d, 10.0d)).drawLineTestMethod();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user