Created
December 16, 2019 22:42
-
-
Save Crypnotic/b988f62617fc75f4211ea28f073e69bb to your computer and use it in GitHub Desktop.
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
@RequiredArgsConstructor | |
public class Circle { | |
@Getter | |
private final double radius; | |
@Getter | |
private final Vector3d center; | |
@Getter | |
private final int shardCount; | |
@Getter | |
private final double degreeIncrease; | |
@Getter | |
private Set<CircleShard> shards; | |
public Set<CircleShard> tick() { | |
if (shards.isEmpty()) { | |
this.shards = Sets.newHashSetWithExpectedSize(shardCount); | |
double delta = 360.0 / shardCount; | |
for (int i = 0; i < shardCount; i++) { | |
shards.add(new CircleShard(this, delta * i)); | |
} | |
return shards; | |
} | |
shards.forEach(CircleShard::tick); | |
return shards; | |
} | |
public static class CircleShard { | |
private Circle circle; | |
private double index; | |
@Getter | |
private MuVector3d location; | |
public CircleShard(Circle circle, double index) { | |
this.circle = circle; | |
this.index = index; | |
this.location = MuVector3d.of(circle.center); | |
} | |
public void tick() { | |
index += circle.getDegreeIncrease(); | |
if (index > 360) { | |
index -= 360; | |
} | |
double theta = Math.toRadians(index); | |
double x = circle.radius * Math.cos(theta) + circle.center.x(); | |
double z = circle.radius * Math.sin(theta) + circle.center.z(); | |
location.set(x, location.y(), z); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment