# Solved Relative Pitch Yaw and Roll With Circle Methods

Discussion in 'Spigot Plugin Development' started by zebotc, Jul 1, 2016.

1. So I have a circle method that takes a location, a radius, and pitch, yaw and roll to return a list of points on a circle in a 3d space with the specified rotation. Right now I am trying to make a circle that appears on a player with a specific angle relative to their position. However it doesn't seem to work properly. The circle randomly moves around and changes its angle very randomly whenever the player moves their head.

Here is a simplified version of my code.
Code (Text):

public void Ring(Player player) {
Location ploc = player.getLocation();
ploc = ploc.add(0, 1, 0);

new BukkitRunnable() {
Methods methods = new Methods(main);
Location pl = player.getLocation();
Vector dir = player.getEyeLocation().getDirection().normalize();
int count = 0;
int[] revolve = new int;
int counter = 0;

pl = player.getLocation();
pl.setYaw(pl.getYaw()+45);
ArrayList<Location> blocks = methods.circle(player.getLocation().add(0,1,0), 2, 30, pl.getYaw(), 0, pl.getPitch());//methods.getCircle(player.getLocation(), 2, 30);
for (int x = 0; x < blocks.length; x++) {
//do something like particle effects
}

count++;

if (count >= 600 || player.isSneaking()) {
cancel();
}

}
}.runTaskTimer(main, 2, 1);
return;

}

Is there a way to just get a relative vector based on the players position that will only change when the players body and not head changes facing and then use that to create a circle with a specific angle that changes its rotation relative to the players facing?

#1
Last edited: Jul 1, 2016
2. ### 567legodude

Someone on another forum had a question about rotating particle shapes in 3d space. I pretty much taught myself all about 3 dimensional rotation when helping them. The answer to this is to use a 3d rotation matrix.

This is the method I made which took the points of a shape and rotated it in 3d space.
Code (Text):
// The class Point is simply a class that holds x, y, and z values.
// The list of points should be all the points
// of the shape relative to the center of rotation.
// All the points of the shape should be unit points
// meaning min point (-1, -1, -1) max point (1, 1, 1)
private List<Location> transformPoints(Location center, List<Point> points, double yaw, double pitch, double roll, double scale) {
// Convert to radians
yaw = Math.toRadians(yaw);
pitch = Math.toRadians(pitch);
roll = Math.toRadians(roll);
List<Location> list = new ArrayList<>();
// Store the values so we don't have to calculate them again for every single point.
double cp = Math.cos(pitch);
double sp = Math.sin(pitch);
double cy = Math.cos(yaw);
double sy = Math.sin(yaw);
double cr = Math.cos(roll);
double sr = Math.sin(roll);
double x, bx, y, by, z, bz;
for (Point point : points) {
x = point.getX();
bx = x;
y = point.getY();
by = y;
z = point.getZ();
bz = z;
x = ((x*cy-bz*sy)*cr+by*sr)*scale;
y = ((y*cp+bz*sp)*cr-bx*sr)*scale;
z = ((z*cp-by*sp)*cy+bx*sy)*scale;
list.add(new Location(center.getWorld(), (center.getX()+x), (center.getY()+y), (center.getZ()+z)));
}
return list;
// list contains all the locations of the rotated shape at the specified center
}

I hope rotating a shape in 3d space is what you were looking for. If you have a question I will do my best to explain it.

• Useful x 1
• Optimistic x 1
3. I can already rotate shapes, the problem I'm having is I can't seem to keep the shape rotated in a specific direction that is relative to the player. For example if I have a circle around a player I want the circle to always be tilted down on the left side of the player no matter what direction they are facing.

4. ### 567legodude

If you want to make it the same regardless of their direction, then simply use their location and a fixed value for the tilt.

• Optimistic x 1
5. I've tried doing that but it just won't work correctly, the circle will just randomly move around whenever the player changes facing and will go to a some different rotation for basically every facing.

*Edit
Instead of using my method I tried using your method with a Unit circle and it worked perfectly thanks!

#5
Last edited: Jul 1, 2016
6. ### 567legodude

There had to be some spot in the code that took the player's rotation.
But yeah like I said I did a ton of research on 3d rotation to make that method. Glad it worked out.

• Optimistic x 1