Skip to content

Instantly share code, notes, and snippets.

@Crypnotic
Created December 16, 2019 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Crypnotic/b988f62617fc75f4211ea28f073e69bb to your computer and use it in GitHub Desktop.
Save Crypnotic/b988f62617fc75f4211ea28f073e69bb to your computer and use it in GitHub Desktop.
@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