This commit is contained in:
Paul Reilly 2023-06-20 09:24:49 -05:00
parent d18c552af0
commit c68a344a39
55 changed files with 1325 additions and 188 deletions

View File

@ -14,7 +14,7 @@ repositories {
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.19.2-R0.1-SNAPSHOT'
implementation project(':Commons')
implementation project(':Converter')
}
test {

View File

@ -1,12 +1,12 @@
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.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.cartesian.CartesianVector;
import io.github.simplexdev.polarize.math.Point2D;
import io.github.simplexdev.polarize.math.Point3D;
import io.github.simplexdev.polarize.cartesian.Point2D;
import io.github.simplexdev.polarize.cartesian.Point3D;
import io.github.simplexdev.polarize.polar.Scalar;
import org.bukkit.Location;
import org.bukkit.World;

19
Caravan/build.gradle Normal file
View File

@ -0,0 +1,19 @@
plugins {
id 'java'
}
group = 'io.github.simplexdev'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
}
test {
useJUnitPlatform()
}

View File

@ -0,0 +1,5 @@
package io.github.simplexdev.caravan;
public interface CaravanAPI {
}

View File

@ -0,0 +1,4 @@
package io.github.simplexdev.caravan.api;
public interface Graph {
}

View File

@ -0,0 +1,12 @@
package io.github.simplexdev.caravan.api;
import io.github.simplexdev.caravan.api.curve.GenericCurve;
import io.github.simplexdev.caravan.spatial.Point;
import java.util.Set;
public interface Mapper {
<T extends GenericCurve> Set<Point> generateCurve(T curve);
}

View File

@ -0,0 +1,31 @@
package io.github.simplexdev.caravan.api.curve;
import io.github.simplexdev.caravan.spatial.Point;
import java.util.LinkedHashSet;
public interface GenericCurve {
LinkedHashSet<Point> linkedPoints();
default void addPoint(Point point) {
linkedPoints().add(point);
}
default void removePoint(Point point) {
linkedPoints().remove(point);
}
default void clearPoints() {
linkedPoints().clear();
}
default boolean containsPoint(Point point) {
return linkedPoints().contains(point);
}
default void addPoints(Point... points) {
for (Point point : points) {
addPoint(point);
}
}
}

View File

@ -0,0 +1,25 @@
package io.github.simplexdev.caravan.api.curve;
import io.github.simplexdev.caravan.spatial.Point;
public interface Helix extends GenericCurve {
double getRadius();
double getDistance();
default double getX(double pos) {
return getRadius() * Math.cos(pos);
}
default double getY(double pos) {
return getRadius() * Math.sin(pos);
}
default double getZ(double pos) {
return getDistance() * pos;
}
default Point toPoint(double pos) {
return new Point(getX(pos), getY(pos), getZ(pos));
}
}

View File

@ -0,0 +1,11 @@
package io.github.simplexdev.caravan.api.curve;
public interface Torus {
double getDistanceFromCenter();
double getRadius();
default double getX() {
}
}

View File

@ -0,0 +1,11 @@
package io.github.simplexdev.caravan.base;
import io.github.simplexdev.caravan.CaravanAPI;
public final class Caravan implements CaravanAPI {
private static final CaravanAPI api = new Caravan();
public static CaravanAPI getAPI() {
return api;
}
}

View File

@ -0,0 +1,65 @@
package io.github.simplexdev.caravan.spatial;
public class Point {
private final double x;
private final double y;
private final double z;
private double xOffset;
private double yOffset;
private double zOffset;
public Point(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
this.xOffset = 0;
this.yOffset = 0;
this.zOffset = 0;
}
public Point(double x, double y, double z, double xOffset, double yOffset, double zOffset) {
this.x = x;
this.y = y;
this.z = z;
this.xOffset = xOffset;
this.yOffset = yOffset;
this.zOffset = zOffset;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getZ() {
return z;
}
public double getXOffset() {
return xOffset;
}
public void setXOffset(double xOffset) {
this.xOffset = xOffset;
}
public double getYOffset() {
return yOffset;
}
public void setYOffset(double yOffset) {
this.yOffset = yOffset;
}
public double getZOffset() {
return zOffset;
}
public void setZOffset(double zOffset) {
this.zOffset = zOffset;
}
}

View File

@ -1,10 +0,0 @@
plugins {
id 'java'
}
group = 'io.github.simplexdev'
version = '1.0-SNAPSHOT'
test {
useJUnitPlatform()
}

View File

@ -1,30 +0,0 @@
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();
}

View File

@ -1,24 +0,0 @@
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;
}
}

View File

@ -1,30 +0,0 @@
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;
}
}

42
Converter/.gitignore vendored Normal file
View 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
View 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()
}

View File

@ -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();
}

View File

@ -1,4 +1,6 @@
package io.github.simplexdev.polarize.api;
package io.github.simplexdev.polarize.api.rotation;
import io.github.simplexdev.polarize.api.spatial.IVector;
/**
* Represents the rotation of an object in 3D space.

View File

@ -1,4 +1,7 @@
package io.github.simplexdev.polarize.api;
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.
@ -11,12 +14,12 @@ public interface IPoint2D {
*
* @return The X coordinate of the point.
*/
double getX();
X getX();
/**
* Returns the Z coordinate of the point.
*
* @return The Z coordinate of the point.
*/
double getZ();
Z getZ();
}

View File

@ -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);
}

View File

@ -1,4 +1,6 @@
package io.github.simplexdev.polarize.api;
package io.github.simplexdev.polarize.api.spatial;
import io.github.simplexdev.polarize.api.rotation.IQuaternion;
/**
* Represents a scalar value.

View File

@ -1,5 +1,8 @@
package io.github.simplexdev.polarize.api;
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;
/**
@ -149,4 +152,32 @@ public interface IVector {
* @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()
);
}
}

View File

@ -0,0 +1,5 @@
package io.github.simplexdev.polarize.api.spatial;
public interface IVertex {
}

View File

@ -20,4 +20,12 @@ public interface Phi {
* @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;
}
}

View File

@ -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();
}
}

View File

@ -19,4 +19,12 @@ public interface 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);
}
}

View File

@ -11,4 +11,12 @@ public interface Theta {
* @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;
}
}

View File

@ -1,9 +1,8 @@
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;
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
@ -21,8 +20,8 @@ public class CartesianUnit {
* @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);
this.point3d = Point.fromDouble(x, y, z);
this.point2d = Point.fromDouble(x, z);
}
/**

View File

@ -1,7 +1,7 @@
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.api.rotation.IQuaternion;
import io.github.simplexdev.polarize.api.spatial.IVector;
import io.github.simplexdev.polarize.math.Quaternion;
import org.jetbrains.annotations.NotNull;

View File

@ -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;
}
}

View File

@ -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()));
}
}

View File

@ -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();
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -1,6 +1,6 @@
package io.github.simplexdev.polarize.math;
import io.github.simplexdev.polarize.api.IQuaternion;
import io.github.simplexdev.polarize.api.rotation.IQuaternion;
public class Quaternion implements IQuaternion {
private final double w;

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -1,7 +1,7 @@
package io.github.simplexdev.polarize.polar;
import io.github.simplexdev.polarize.api.IQuaternion;
import io.github.simplexdev.polarize.api.IScalar;
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;

View File

@ -106,7 +106,7 @@ public class SphericalUnit {
*/
public double adjacent() {
CartesianUnit unit = Polarizer.toCartesianUnit(this);
return unit.getPoint3D().getX();
return unit.getPoint3D().getX().get();
}
/**
@ -119,6 +119,6 @@ public class SphericalUnit {
*/
public double opposite() {
CartesianUnit unit = Polarizer.toCartesianUnit(this);
return unit.getPoint3D().getZ();
return unit.getPoint3D().getZ().get();
}
}

View File

@ -1,7 +1,7 @@
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.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;

View File

@ -1,12 +1,17 @@
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.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;
@ -107,6 +112,16 @@ public class Polarizer {
/**
* 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
@ -122,21 +137,22 @@ public class Polarizer {
/**
* 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() * unit.getPoint2D().getX()
+ unit.getPoint2D().getZ() * unit.getPoint2D().getZ());
double theta = Math.atan2(unit.getPoint2D().getX(), unit.getPoint2D().getZ());
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} 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.
* 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}
@ -144,12 +160,14 @@ public class Polarizer {
*/
public static PolarUnit toPolarUnit(CartesianUnit unit, IVector vector) {
double radius = vector.length();
double theta = Math.atan2(unit.getPoint2D().getX(), unit.getPoint2D().getZ());
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
@ -157,16 +175,25 @@ public class Polarizer {
*/
public static PolarUnit toPolarUnit(IPoint2D point, IVector vector) {
double radius = vector.length();
double theta = Math.atan2(point.getX(), point.getZ());
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 {@code PolarUnit} representing the polar coordinates 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);
@ -175,23 +202,36 @@ public class Polarizer {
}
/**
* Converts a CartesianUnit to a SphericalUnit.
* 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() * 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());
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
@ -199,18 +239,33 @@ public class Polarizer {
*/
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());
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 {@code SphericalUnit} representing the converted spherical coordinates
* @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);
@ -218,4 +273,70 @@ public class Polarizer {
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);
}
}

View File

@ -1,10 +1,11 @@
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.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;
@ -35,11 +36,13 @@ public class Rotator {
* @return the rotated point.
*/
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());
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 new Point3D(x, y, z);
return Point.fromDouble(x, y, z);
}
/**
@ -52,11 +55,13 @@ public class Rotator {
* @return the rotated point.
*/
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());
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 new Point3D(x, y, z);
return Point.fromDouble(x, y, z);
}
/**
@ -69,11 +74,13 @@ public class Rotator {
* @return the rotated point.
*/
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();
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 new Point3D(x, y, z);
return Point.fromDouble(x, y, z);
}
/**
@ -88,14 +95,14 @@ public class Rotator {
*/
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 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 new Point3D(xRot, yRot, zRot);
return Point.fromDouble(xRot, yRot, zRot);
}
/**
@ -108,9 +115,11 @@ public class Rotator {
* @return the rotated point.
*/
public static IPoint2D rotateX(IPoint2D point, PolarUnit 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);
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);
}
/**
@ -123,9 +132,11 @@ public class Rotator {
* @return the rotated point.
*/
public static IPoint2D rotateZ(IPoint2D point, PolarUnit 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);
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);
}
/**
@ -138,9 +149,11 @@ public class Rotator {
* @return the rotated point.
*/
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);
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);
}
/**
@ -152,13 +165,13 @@ public class Rotator {
* @return the rotated point.
*/
public static IPoint3D rotate(IPoint3D point, IQuaternion quaternion) {
IQuaternion pQuat = new Quaternion(0.0, point.getX(), point.getY(), point.getZ());
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 new Point3D(w.getX(), w.getY(), w.getZ());
return Point.fromDouble(w.getX(), w.getY(), w.getZ());
}
/**
@ -170,12 +183,12 @@ public class Rotator {
* @return the rotated point.
*/
public static IPoint2D rotate(IPoint2D point, IQuaternion quaternion) {
IQuaternion pQuat = new Quaternion(0.0, point.getX(), 0.0, point.getZ());
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 new Point2D(w.getX(), w.getZ());
return Point.fromDouble(w.getX(), w.getZ());
}
}

View File

@ -26,6 +26,7 @@ public class Utilities {
* This represents 360 degrees in radians.
*/
public static final double RADIAN_360 = Math.PI * 2;
private Utilities() {
throw new AssertionError();
}

View File

@ -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()));
}
}

View File

@ -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();
}
}

View File

@ -20,7 +20,7 @@ subprojects {
}
tasks.build {
dependsOn(":Commons:build", ":Paper:build")
dependsOn(":Converter:build", ":Bukkit:build")
}
test {

View File

@ -1,4 +1,6 @@
rootProject.name = 'Polarize'
include 'Commons'
include 'Paper'
include 'Converter'
include 'Bukkit'
include 'Caravan'
include 'Caravan'