mirror of
https://github.com/SimplexDevelopment/Polarize.git
synced 2024-12-21 20:17:37 +00:00
New polar coordinates library
This commit is contained in:
commit
043fbfeeb6
44
.gitignore
vendored
Normal file
44
.gitignore
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
.gradle
|
||||
/gradle
|
||||
.idea
|
||||
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
|
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
42
Commons/.gitignore
vendored
Normal file
42
Commons/.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
|
10
Commons/build.gradle
Normal file
10
Commons/build.gradle
Normal file
@ -0,0 +1,10 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'io.github.simplexdev'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package io.github.simplexdev.polarize.api;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
double getX();
|
||||
|
||||
/**
|
||||
* Returns the Z coordinate of the point.
|
||||
*
|
||||
* @return The Z coordinate of the point.
|
||||
*/
|
||||
double getZ();
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package io.github.simplexdev.polarize.api;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
double getX();
|
||||
|
||||
/**
|
||||
* Returns the Y coordinate of this point.
|
||||
*
|
||||
* @return The Y coordinate of this point.
|
||||
*/
|
||||
double getY();
|
||||
|
||||
/**
|
||||
* Returns the Z coordinate of this point.
|
||||
*
|
||||
* @return The Z coordinate of this point.
|
||||
*/
|
||||
double getZ();
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package io.github.simplexdev.polarize.api;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
double getW();
|
||||
|
||||
double getX();
|
||||
|
||||
double getY();
|
||||
|
||||
double getZ();
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package io.github.simplexdev.polarize.api;
|
||||
|
||||
/**
|
||||
* 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,153 @@
|
||||
package io.github.simplexdev.polarize.api;
|
||||
|
||||
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));
|
||||
*
|
||||
* @see #distanceSquared(IVector)
|
||||
*
|
||||
* @param vector The vector to get the distance between.
|
||||
* @return The distance between this vector and the vector passed in.
|
||||
*/
|
||||
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);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
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();
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
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();
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package io.github.simplexdev.polarize.api.units;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Theta {
|
||||
double getZenith();
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package io.github.simplexdev.polarize.cartesian;
|
||||
|
||||
import io.github.simplexdev.polarize.api.IPoint2D;
|
||||
import io.github.simplexdev.polarize.api.IPoint3D;
|
||||
import io.github.simplexdev.polarize.math.Point2D;
|
||||
import io.github.simplexdev.polarize.math.Point3D;
|
||||
|
||||
/**
|
||||
* 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 = new Point3D(x, y, z);
|
||||
this.point2d = new Point2D(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.IQuaternion;
|
||||
import io.github.simplexdev.polarize.api.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,24 @@
|
||||
package io.github.simplexdev.polarize.math;
|
||||
|
||||
import io.github.simplexdev.polarize.api.IPoint2D;
|
||||
|
||||
public class Point2D implements IPoint2D {
|
||||
|
||||
private final double x;
|
||||
private final double z;
|
||||
|
||||
public Point2D(double x, double z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZ() {
|
||||
return this.z;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package io.github.simplexdev.polarize.math;
|
||||
|
||||
import io.github.simplexdev.polarize.api.IPoint3D;
|
||||
|
||||
public class Point3D implements IPoint3D {
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
|
||||
public Point3D(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package io.github.simplexdev.polarize.math;
|
||||
|
||||
import io.github.simplexdev.polarize.api.IQuaternion;
|
||||
|
||||
public class Quaternion implements IQuaternion {
|
||||
private double w, x, y, 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,30 @@
|
||||
package io.github.simplexdev.polarize.polar;
|
||||
|
||||
import io.github.simplexdev.polarize.api.units.Phi;
|
||||
import io.github.simplexdev.polarize.api.units.Theta;
|
||||
|
||||
public class Delta {
|
||||
private final Theta theta;
|
||||
private final Phi phi;
|
||||
|
||||
public Delta(double theta, double phi) {
|
||||
this.theta = () -> theta;
|
||||
this.phi = () -> phi;
|
||||
}
|
||||
|
||||
public Theta getTheta() {
|
||||
return theta;
|
||||
}
|
||||
|
||||
public Phi getPhi() {
|
||||
return phi;
|
||||
}
|
||||
|
||||
public double theta() {
|
||||
return theta.getZenith();
|
||||
}
|
||||
|
||||
public double phi() {
|
||||
return phi.getAzimuth();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package io.github.simplexdev.polarize.polar;
|
||||
|
||||
import io.github.simplexdev.polarize.api.units.Radius;
|
||||
import io.github.simplexdev.polarize.api.units.Theta;
|
||||
|
||||
public class PolarUnit {
|
||||
private final Radius radius;
|
||||
private final Theta theta;
|
||||
|
||||
public PolarUnit(double radius, double theta) {
|
||||
this.radius = () -> radius;
|
||||
this.theta = () -> theta;
|
||||
}
|
||||
|
||||
public Radius getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public Theta getTheta() {
|
||||
return theta;
|
||||
}
|
||||
|
||||
public double radius() {
|
||||
return radius.length();
|
||||
}
|
||||
|
||||
public double theta() {
|
||||
return theta.getZenith();
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package io.github.simplexdev.polarize.polar;
|
||||
|
||||
import io.github.simplexdev.polarize.api.IQuaternion;
|
||||
import io.github.simplexdev.polarize.api.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,41 @@
|
||||
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;
|
||||
|
||||
public class SphericalUnit {
|
||||
private final Radius radius;
|
||||
private final Theta theta;
|
||||
private final Phi phi;
|
||||
|
||||
public SphericalUnit(double radius, double theta, double phi) {
|
||||
this.radius = () -> radius;
|
||||
this.theta = () -> theta;
|
||||
this.phi = () -> phi;
|
||||
}
|
||||
|
||||
public Radius getRadius() {
|
||||
return this.radius;
|
||||
}
|
||||
|
||||
public Theta getTheta() {
|
||||
return this.theta;
|
||||
}
|
||||
|
||||
public Phi getPhi() {
|
||||
return this.phi;
|
||||
}
|
||||
|
||||
public double radius() {
|
||||
return this.radius.length();
|
||||
}
|
||||
|
||||
public double theta() {
|
||||
return this.theta.getZenith();
|
||||
}
|
||||
|
||||
public double phi() {
|
||||
return this.phi.getAzimuth();
|
||||
}
|
||||
}
|
@ -0,0 +1,422 @@
|
||||
package io.github.simplexdev.polarize.util;
|
||||
|
||||
import io.github.simplexdev.polarize.api.IScalar;
|
||||
import io.github.simplexdev.polarize.api.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,235 @@
|
||||
package io.github.simplexdev.polarize.util;
|
||||
|
||||
import io.github.simplexdev.polarize.api.IPoint2D;
|
||||
import io.github.simplexdev.polarize.api.IPoint3D;
|
||||
import io.github.simplexdev.polarize.api.IScalar;
|
||||
import io.github.simplexdev.polarize.api.IVector;
|
||||
import io.github.simplexdev.polarize.api.units.Phi;
|
||||
import io.github.simplexdev.polarize.api.units.Theta;
|
||||
import io.github.simplexdev.polarize.cartesian.CartesianUnit;
|
||||
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).
|
||||
*
|
||||
* @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}.
|
||||
*
|
||||
* @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() * unit.getPoint2D().getX()
|
||||
+ unit.getPoint2D().getZ() * unit.getPoint2D().getZ());
|
||||
double theta = Math.atan2(unit.getPoint2D().getX(), unit.getPoint2D().getZ());
|
||||
return new PolarUnit(radius, theta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@link CartesianUnit} to a {@link PolarUnit} using the magnitude of the given {@link IVector} as
|
||||
* the radius. The angle theta is calculated from the x and z components of the CartesianUnit using the {@link Math#atan2(double, double)} method.
|
||||
*
|
||||
* @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(), unit.getPoint2D().getZ());
|
||||
return new PolarUnit(radius, theta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link PolarUnit} representing the polar coordinates of the given 2D point in relation to the given vector.
|
||||
*
|
||||
* @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(), point.getZ());
|
||||
return new PolarUnit(radius, theta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a 2D point in Cartesian coordinates to a polar unit.
|
||||
*
|
||||
* @param x the x-coordinate of the point
|
||||
* @param z the z-coordinate of the point
|
||||
* @return a {@code 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 CartesianUnit to a SphericalUnit.
|
||||
*
|
||||
* @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() * unit.getPoint3D().getX()
|
||||
+ unit.getPoint3D().getY() * unit.getPoint3D().getY()
|
||||
+ unit.getPoint3D().getZ() * unit.getPoint3D().getZ());
|
||||
double theta = Math.acos(unit.getPoint3D().getY() / radius);
|
||||
double phi = Math.atan2(unit.getPoint3D().getX(), unit.getPoint3D().getZ());
|
||||
return new SphericalUnit(radius, theta, phi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified {@link IPoint3D} to a {@link SphericalUnit} using the specified {@link IVector}.
|
||||
*
|
||||
* @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() / radius);
|
||||
double phi = Math.atan2(point.getX(), point.getZ());
|
||||
return new SphericalUnit(radius, theta, phi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given Cartesian coordinates (x, y, z) to spherical coordinates (radius, theta, phi).
|
||||
*
|
||||
* @param x the x-coordinate
|
||||
* @param y the y-coordinate
|
||||
* @param z the z-coordinate
|
||||
* @return a new {@code 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);
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package io.github.simplexdev.polarize.util;
|
||||
|
||||
import io.github.simplexdev.polarize.api.IPoint2D;
|
||||
import io.github.simplexdev.polarize.api.IPoint3D;
|
||||
import io.github.simplexdev.polarize.api.IQuaternion;
|
||||
import io.github.simplexdev.polarize.math.Point2D;
|
||||
import io.github.simplexdev.polarize.math.Point3D;
|
||||
import io.github.simplexdev.polarize.math.Quaternion;
|
||||
import io.github.simplexdev.polarize.polar.Delta;
|
||||
import io.github.simplexdev.polarize.polar.SphericalUnit;
|
||||
|
||||
public class Rotator {
|
||||
private Rotator() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static IPoint3D rotateX(IPoint3D point, SphericalUnit unit) {
|
||||
double x = point.getX();
|
||||
double y = point.getY() * Math.cos(unit.theta()) - point.getZ() * Math.sin(unit.theta());
|
||||
double z = point.getY() * Math.sin(unit.theta()) + point.getZ() * Math.cos(unit.theta());
|
||||
|
||||
return new Point3D(x, y, z);
|
||||
}
|
||||
|
||||
public static IPoint3D rotateY(IPoint3D point, SphericalUnit unit) {
|
||||
double x = point.getX() * Math.cos(unit.phi()) - point.getZ() * Math.sin(unit.phi());
|
||||
double y = point.getY();
|
||||
double z = point.getX() * Math.sin(unit.phi()) + point.getZ() * Math.cos(unit.phi());
|
||||
|
||||
return new Point3D(x, y, z);
|
||||
}
|
||||
|
||||
public static IPoint3D rotateZ(IPoint3D point, SphericalUnit unit) {
|
||||
double x = point.getX() * Math.cos(unit.theta()) - point.getY() * Math.sin(unit.theta());
|
||||
double y = point.getX() * Math.sin(unit.theta()) + point.getY() * Math.cos(unit.theta());
|
||||
double z = point.getZ();
|
||||
|
||||
return new Point3D(x, y, z);
|
||||
}
|
||||
|
||||
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(), point.getZ()) + delta.theta();
|
||||
double phi = Math.atan2(Utilities.magnitudeOf(point.getX(), point.getZ()), point.getY()) + 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 new Point3D(xRot, yRot, zRot);
|
||||
}
|
||||
|
||||
public static IPoint2D rotateX(IPoint2D point, SphericalUnit unit) {
|
||||
double x = point.getZ() * Math.cos(unit.theta()) - point.getX() * Math.sin(unit.theta());
|
||||
double z = point.getZ() * Math.sin(unit.theta()) + point.getX() * Math.cos(unit.theta());
|
||||
return new Point2D(x, z);
|
||||
}
|
||||
|
||||
public static IPoint2D rotateZ(IPoint2D point, SphericalUnit unit) {
|
||||
double x = point.getX() * Math.cos(unit.theta()) - point.getZ() * Math.sin(unit.theta());
|
||||
double z = point.getX() * Math.sin(unit.theta()) + point.getZ() * Math.cos(unit.theta());
|
||||
return new Point2D(x, z);
|
||||
}
|
||||
|
||||
public static IPoint2D fullRotation(IPoint2D point, SphericalUnit unit) {
|
||||
double x = point.getX() * Math.cos(unit.theta()) - point.getZ() * Math.sin(unit.theta());
|
||||
double z = point.getX() * Math.sin(unit.theta()) + point.getZ() * Math.cos(unit.theta());
|
||||
return new Point2D(x, z);
|
||||
}
|
||||
|
||||
public static IPoint3D rotate(IPoint3D point, IQuaternion quaternion) {
|
||||
IQuaternion pQuat = new Quaternion(0.0, point.getX(), point.getY(), point.getZ());
|
||||
|
||||
IQuaternion conjugate = quaternion.conjugate();
|
||||
|
||||
IQuaternion w = conjugate.multiply(pQuat).multiply(quaternion);
|
||||
|
||||
return new Point3D(w.getX(), w.getY(), w.getZ());
|
||||
}
|
||||
|
||||
public static IPoint2D rotate(IPoint2D point, IQuaternion quaternion) {
|
||||
IQuaternion pQuat = new Quaternion(0.0, point.getX(), 0.0, point.getZ());
|
||||
|
||||
IQuaternion conjugate = quaternion.conjugate();
|
||||
|
||||
IQuaternion w = conjugate.multiply(pQuat).multiply(quaternion);
|
||||
|
||||
return new Point2D(w.getX(), w.getZ());
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package io.github.simplexdev.polarize.util;
|
||||
|
||||
public class Utilities
|
||||
{
|
||||
private Utilities() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
42
Paper/.gitignore
vendored
Normal file
42
Paper/.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
|
22
Paper/build.gradle
Normal file
22
Paper/build.gradle
Normal file
@ -0,0 +1,22 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'io.github.simplexdev'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "spigot-repo"
|
||||
url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.19.2-R0.1-SNAPSHOT'
|
||||
implementation project(':Commons')
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package io.github.simplexdev.paper;
|
||||
|
||||
import io.github.simplexdev.polarize.api.IPoint2D;
|
||||
import io.github.simplexdev.polarize.api.IPoint3D;
|
||||
import io.github.simplexdev.polarize.api.IScalar;
|
||||
import io.github.simplexdev.polarize.api.IVector;
|
||||
import io.github.simplexdev.polarize.cartesian.CartesianVector;
|
||||
import io.github.simplexdev.polarize.math.Point2D;
|
||||
import io.github.simplexdev.polarize.math.Point3D;
|
||||
import io.github.simplexdev.polarize.polar.Scalar;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class DataConverter {
|
||||
|
||||
public static Vector toBukkitVector(IVector vector) {
|
||||
return new Vector(vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
|
||||
public static IVector toPolarizeVector(Vector vector) {
|
||||
return new CartesianVector(vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
|
||||
public static Location toBukkitLocation(World world, IPoint3D point) {
|
||||
return new Location(world, point.getX(), point.getY(), point.getZ());
|
||||
}
|
||||
|
||||
public static Location toBukkitLocation(World world, double y, IPoint2D point) {
|
||||
return new Location(world, point.getX(), y, point.getZ());
|
||||
}
|
||||
|
||||
public static IPoint3D to3DPoint(Location location) {
|
||||
return new Point3D(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public static IPoint2D to2DPoint(Location location) {
|
||||
return new Point2D(location.getX(), location.getZ());
|
||||
}
|
||||
|
||||
public static IScalar getScalar(Location location, Vector vector) {
|
||||
return new Scalar(vector.length(), Math.sqrt(
|
||||
location.getX() * location.getX()
|
||||
+ location.getZ() * location.getZ()));
|
||||
}
|
||||
|
||||
public static IScalar getScalar(Location location) {
|
||||
return new Scalar(location.getDirection().length(),
|
||||
Math.sqrt(location.getX() * location.getX()
|
||||
+ location.getZ() * location.getZ()));
|
||||
}
|
||||
|
||||
public static Vector fromScalar(IScalar scalar, Location location) {
|
||||
double magnitude = scalar.getMagnitude();
|
||||
|
||||
double x = location.getX(),
|
||||
y = location.getY(),
|
||||
z = location.getZ();
|
||||
|
||||
double length = magnitude / Math.sqrt(x * x + y * y + z * z);
|
||||
|
||||
double xMod = x * length,
|
||||
yMod = y * length,
|
||||
zMod = z * length;
|
||||
|
||||
return new Vector(xMod, yMod, zMod);
|
||||
}
|
||||
|
||||
public static IScalar toScalar(Vector vector, double origin) {
|
||||
double magnitude = Math.sqrt(vector.getX() * vector.getX() + vector.getY() * vector.getY() + vector.getZ() * vector.getZ());
|
||||
|
||||
double magnitudeDiff = magnitude - vector.length();
|
||||
double originMod = origin - magnitudeDiff;
|
||||
|
||||
return new Scalar(magnitude, originMod);
|
||||
}
|
||||
}
|
28
build.gradle
Normal file
28
build.gradle
Normal file
@ -0,0 +1,28 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'io.github.simplexdev'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
subprojects {
|
||||
apply plugin: 'java'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.jetbrains:annotations:24.0.0'
|
||||
testImplementation platform('org.junit:junit-bom:5.9.1')
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
}
|
||||
}
|
||||
|
||||
tasks.build {
|
||||
dependsOn(":Commons:build", ":Paper:build")
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
#Sun Apr 16 19:06:47 CDT 2023
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
234
gradlew
vendored
Normal file
234
gradlew
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
89
gradlew.bat
vendored
Normal file
89
gradlew.bat
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
4
settings.gradle
Normal file
4
settings.gradle
Normal file
@ -0,0 +1,4 @@
|
||||
rootProject.name = 'Polarize'
|
||||
include 'Commons'
|
||||
include 'Paper'
|
||||
|
Loading…
Reference in New Issue
Block a user