Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6aae1a
commit e9932e2
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/org/auioc/mcmod/arnicalib/game/world/phys/ShapeUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.auioc.mcmod.arnicalib.game.world.phys; | ||
|
||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
public class ShapeUtils { | ||
|
||
public static Vec3[] getPointsOnLine(Vec3 start, Vec3 end, double stepLength) { | ||
double dX = (end.x - start.x); | ||
double dY = (end.y - start.y); | ||
double dZ = (end.z - start.z); | ||
|
||
double lineLength = Mth.length(dX, dY, dZ); | ||
|
||
int pointCount = (int) (lineLength / stepLength); | ||
var points = new Vec3[pointCount]; | ||
|
||
double stepLengthX = dX / pointCount; | ||
double stepLengthY = dY / pointCount; | ||
double stepLengthZ = dZ / pointCount; | ||
for (int i = 0; i < pointCount; i++) { | ||
double x = start.x + stepLengthX * i; | ||
double y = start.y + stepLengthY * i; | ||
double z = start.z + stepLengthZ * i; | ||
points[i] = new Vec3(x, y, z); | ||
} | ||
|
||
return points; | ||
} | ||
|
||
public static Vec3[] createRegularPolygon(Vec3 centre, Vec3 normalVector, double circumradius, double centralAngle) { | ||
var base = VectorUtils.getBaseVector(normalVector); | ||
|
||
int pointCount = (int) (360.0D / centralAngle); | ||
var vertexes = new Vec3[pointCount]; | ||
for (int i = 0; i < pointCount; ++i) { | ||
double t = Math.toRadians(i * centralAngle); | ||
double sinT = Math.sin(t); | ||
double cosT = Math.cos(t); | ||
vertexes[i] = centre | ||
.add(VectorUtils.multiply(VectorUtils.multiply(base.getLeft(), circumradius), cosT)) | ||
.add(VectorUtils.multiply(VectorUtils.multiply(base.getRight(), circumradius), sinT)); | ||
} | ||
|
||
return vertexes; | ||
} | ||
|
||
} |