# Rotated entities in a circle

Discussion in 'Spigot Plugin Development' started by QuestPx, Jun 3, 2018.

1. ### QuestPx

Hello, I do not know English well, I apologize in advance.

And so, I made a receiving for each ArmorStand of its position on the circle. With the rotation of each ArmorStand, I take the cosine of x and the sine of y, but I do not understand how to do it so that all ArmorStands do not rotate in the one location.
Screenshots and code below:

Code (Text):
public class MathUtils {

public static List<Location> getRotatedLocations(Location center, double radius, int amount, boolean directionX) {
List<Location> locations = new ArrayList<Location>();
double tau = Math.PI*2;
double increment = tau / amount;
for(int i = 0; i <= amount; i++) {
double angle = i * increment;
double y = center.getY() + radius * Math.sin(angle);
double zx;
if(directionX) {
zx = center.getX() + radius * Math.cos(angle);
} else {
zx = center.getZ() + radius * Math.cos(angle);
}
}
return locations;
}

public static Location getLocationAroundCircle(Location center, double radius, double angleInRadian, boolean directionX) {
double x = center.getX();
double z = center.getZ();
if(directionX) {
} else {
}
Location loc = new Location(center.getWorld(), x, y, z);
return loc;
}

Code (Text):

public void openCase(String p) {
this.isOpen = true;
for(Location loc : locations) {
Hologram hd = HologramsAPI.createHologram(Main.getInstance(), loc);
hd.appendItemLine(new ItemStack(Material.DIAMOND));
}
for(Hologram hd : holograms) {
}
}, 20, 1);

2. ### Ignirion

If you want your ArmorStands (with I suppose are the holograms) to be in a circle you should use the getRotatedLocations method, since getLocationAroundCircle just gives you ONE Location, where you teleport all your ArmorStands to. The Code should be looking something like this:
Code (Text):

int amount = holograms.size();

List<Location> locations = getRotatedLocations(center, radius, amount, true);

for(int i = 0; i < amount; i++) {
holograms.get(i).teleport(locations.get(i));
}

}, 20, 1);

However I am not sure why you're doing this in a SyncRepeatingTask. If you want the ArmorStands to be rotating in a circle around the center you should create new or modify your MathUtils methods.

Another thing is that you are passing 360 as a angle in radian to the method. That is a thing one normally don't want since a full rotation in radian is 2*pi and 360 a full rotation in degree.

#2
Last edited: Jun 5, 2018