Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating hollow circles

Comments in 'Plugin Development' started by PEMapModder, May 19, 2014.

  1. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    So if I want to create a circle solid, I'd just use this:
    PHP:
    function src(Position $centre$radiusBlock $block)
    {
        for (
    $x $centre->$radius$x <= $centre->$radius$x++) {
            
    // same for z
            
    if ($centre->distance(new Vector3($x$centre->y$z)) <= $radius) {
                
    // set block
            
    }
        }
    }

    But what about hollow spheres?
    Last edited by a moderator: May 19, 2014
  2. BlinkSun
    Offline

    BlinkSun Active Member Plugin Developer

    Joined:
    Mar 26, 2014
    Posts:
    128
    Plugins:
    4
    Minecraft User:
    BlinkSun
    I ll try to figure it out too !
  3. Xfusionios
    Offline

    Xfusionios Active Member Plugin Developer

    Joined:
    Aug 24, 2013
    Posts:
    67
    Plugins:
    2
    Minecraft User:
    XFusionios
    What about running it twice and subtracting radius by one and put block of air?
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Could you round the distance and see if it equals radius? Or something like that :)
    64FF00 likes this.
  5. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    That would work but would be very inefficient ;)
    64FF00 likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, but consider the thickness variation for larger circles. (Rounding to integer will create holes)
  7. BlinkSun
    Offline

    BlinkSun Active Member Plugin Developer

    Joined:
    Mar 26, 2014
    Posts:
    128
    Plugins:
    4
    Minecraft User:
    BlinkSun
  8. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    It shouldn't create blank spots because the distance from Center to the xMin is less than that to a corner.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Idk. I never tested. But something in my brain is itchy about blank spots.
    64FF00 likes this.
  10. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Yeah, I figure something will be wrong but it's a place to work from :)
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Spurs_Man321 and Falk like this.
  12. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    If you want a vertical circle you could use this:
    PHP:
    function circle(Position $pos$radiusBlock $block) {
        for(
    $a 0$a <= 360$a++) {
            
    $x $pos->+ (cos(deg2rad($a)) * $radius);
            
    $y $pos->+ (sin(deg2rad($a)) * $radius);
            
    $z $pos->z;
            
    // set block here
        
    }
    }
    Not sure about horizontal though.
    Falk likes this.
  13. BlinkSun
    Offline

    BlinkSun Active Member Plugin Developer

    Joined:
    Mar 26, 2014
    Posts:
    128
    Plugins:
    4
    Minecraft User:
    BlinkSun
    Switch y for z for horizontal !
  14. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    It's hard to explain it, but I'll try.
    First you generate one circle with the radius that you want the hollow sphere to have and store it into the memory.
    Then you generate and draw radius amount of circles with a radius equal to the hight of the sphere minus the y value of the first generated circle at x = number of the circle.
    I'll try to make an example code.
  15. BlinkSun
    Offline

    BlinkSun Active Member Plugin Developer

    Joined:
    Mar 26, 2014
    Posts:
    128
    Plugins:
    4
    Minecraft User:
    BlinkSun
    Btw, this thread content most of active developers plugin ;) i imagine the dream team ;) !!!
  16. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    Ok I made a hollow sphere generator, it uses the Bresenham's circle algorithm which is one of the fastest ways to generate a circle. So this should also be one of the fastest ways to generate a hollow sphere. I couldn't test it yet, but it should work.
    http://pastebin.com/j0Hr6HcC
    PEMapModder and Falk like this.
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The efficiency is too low, and gaps definitely would occur for large ones.
  18. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    I always had problems with gaps in large circles. But I never knew how to fix it. o_O
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Looks very useful.
    Adrian18 likes this.
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Anyway I don't think new Block($blockId) is correct.

Share This Page

Advertisement