Solved Diagonal Circle Calculations

Discussion in 'Spigot Plugin Development' started by Phloxz, Jun 6, 2016.

Thread Status:
Not open for further replies.
  1. Hey poeple!

    I have a question about some math calculations,

    currently i'm trying to get a diagonal circle that won't expand at very high values,

    Example:
    I tryed to create a diagonal circle with 12 minecarts

    The diagonal circle looks like this at the moment (Front view)

    [​IMG]

    So how you see, the carts aren't very close to each other some are spinning a round at the top and the middle theems to be smaller because the top has been moved out of the radius (2.75)

    Another image (Side view)

    [​IMG]
    Here you can see the 12 carts again, now you may see what i mean its a diagonal circle how i wanted, but it moved to the top again

    So my question is, how can i create a diagonal circle with a static radius (2.75) that won't change at the angle value

    Code at the moment:

    Code (Text):


    for (double i = 0.0; i < 360.0; i += 0.1) {

    double angle = i * Math.PI / 180;
    double x = (center.getX() + radius * Math.cos(angle));
    double y = (center.getY() + radius * Math.cos(angle));
    double z = (center.getZ() + radius * Math.sin(angle));

    Location location = new Location(world, x, y, z);

    }


     
    Example on how the diagonal circle should look :

    [​IMG]
    and yes i know this looks more like a vertical circle but its a diagonal later with a different angle (high)
    here's a better one:

    [​IMG]
    so the radius is static and not moving / spinning around

    [​IMG]
     
    #1 Phloxz, Jun 6, 2016
    Last edited: Jun 6, 2016
    • Like Like x 1
  2. @finnbon
    You should find this interesting
     
  3. Just use a simple rotation matrix. https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions

    Here is a code example:
    Code (Java):
        public void example() {
            circle(new Location(Bukkit.getWorlds().get(0), 200, 100, 300), 3.0, 12, Math.PI / 4, Math.PI / 4, 0);
        }
     
        public void circle(Location origin, double radius, int points, double rotX, double rotY, double rotZ) {
            for (int i = 0; i < points; i ++) {
                double angle = i * 2 * Math.PI / points;
                Vector point = new Vector(radius * Math.cos(angle), 0, radius * Math.sin(angle));
                rotX(point, rotX);
                rotY(point, rotY);
                rotZ(point, rotZ);
                origin.add(point);
                // spawn something at origin
                origin.getWorld().spawnParticle(Particle.REDSTONE, origin, 10);
                origin.subtract(point);
            }
        }
     
        public static void rotX(Vector point, double angle) {
            double y = point.getY();
            point.setY(y * Math.cos(angle) - point.getZ() * Math.sin(angle));
            point.setZ(y * Math.sin(angle) + point.getZ() * Math.cos(angle));
        }
     
        public static void rotY(Vector point, double angle) {
            double z = point.getZ();
            point.setZ(z * Math.cos(angle) - point.getX() * Math.sin(angle));
            point.setX(z * Math.sin(angle) + point.getX() * Math.cos(angle));
        }
     
        public static void rotZ(Vector point, double angle) {
            double x = point.getX();
            point.setX(x * Math.cos(angle) - point.getY() * Math.sin(angle));
            point.setY(x * Math.sin(angle) + point.getY() * Math.cos(angle));
        }
    [​IMG]

    @md_5 It would be nice if you can include these rotation functions (rotX, rotY, rotZ) as methods to the Vector class.
     
    #3 stonar96, Jun 6, 2016
    Last edited: Jun 6, 2016
    • Like Like x 2
    • Winner Winner x 1
  4. thanks that helped me!
     
    • Friendly Friendly x 2
  5. MiniDigger

    Supporter

    just pr them and he will review them.
     
    • Informative Informative x 1
Thread Status:
Not open for further replies.