Sphere Generation

Discussion in 'Plugin Development' started by EvilPeanut, Oct 20, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    EvilPeanut

    Does anyone have some code to generate spheres with a certain radius and block type plz?
     
  2. Offline

    nisovin

    You could look at WorldEdit.
     
  3. Offline

    EvilPeanut

    I have, but to be honest worldedit is so unofficiant and just doesn't work well, have seen its code?
     
  4. Offline

    nisovin

    Minnymin3, bennie3211, tips48 and 4 others like this.
  5. Offline

    thehutch

    How dare you blaspheme against the great Sk89q :O
     
    Ivan, bennie3211, Neodork and 3 others like this.
  6. Offline

    croxis

  7. Offline

    pyraetos

    The basis for computer programming is mathematics. If you had knowledge of 3D geometry you could probably make a function that generated a sphere easily.
     
  8. Offline

    DrAgonmoray

    Or if you're like me, you're taking Geometry in school this year, and haven't even gotten to 3D yet :D

    ..buuuuut there's always google
     
    MCForger likes this.
  9. Offline

    EvilPeanut

    Seriously? Ive written my own //set in about 10 lines, took him hundreds
    NOTE: I ran a speed test, mine was faster by far

    I do have knoledge to:
    1. Im young
    2. Im tierd and cba to think

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  10. Offline

    mindless728

    does yours have an undo?
     
    r3Fuze likes this.
  11. Offline

    desht

    Impressive. Care to share your implementation?
     
  12. Offline

    pyraetos

    Of course you've learned it! Probably in pre-algebra.... Vsphere = 4/3pi(r^3)
     
    ChipDev likes this.
  13. Offline

    codename_B

    How about a hollow sphere? Also, I don't know anything about you other than you're completely wrong if you think your code is better than worldedit.
     
    WarmakerT, RjSowden, Sayshal and 5 others like this.
  14. Offline

    thehutch

    And if Codename_B says this then your obviously wrong :p
     
    WarmakerT, Waffletastic and r3Fuze like this.
  15. Offline

    AndrewM16921

    I haven't looked at the WorldEdit code, but I assume it's done somewhat properly. Not only does it render the sphere, but I assume it saves the changed blocks for the //undo command. Also checks if the amount of blocks changed is >100,000, I think.

    Moving away from this debate ^ I'll explain what I would do.

    Distance formula for 3D space
    distance(point1, point2) = sqrt(dx^2 + dy^2 + dz^2)
    This will give you the distance from the center point to the outside of the sphere.

    Now, what I would do is go through 3 nested forloops (one for each axis), and check for each block in that cube (where each side is 2r+1, i.e. r in each direction from the center block) is <= that distance. If it is, then we can assume it is inside the sphere, and set it to whatever block. As for hollow sphere, we can probably do something like if the block is equal to that distance +/- some offset or something. Not too sure about the hollow one.
     
    PDKnight likes this.
  16. Offline

    nisovin

    The WorldEdit code handles a lot more than your ten lines of code does. You just have a basic implementation, clearly. The WorldEdit code handles undo levels, max block changes, block placement ordering (torches placed last), setting blocks in a polygon region, and other things. Faster and shorter does not mean better. Also, here's the basic method used to set blocks in WorldEdit:
    https://github.com/sk89q/worldedit/...ava/com/sk89q/worldedit/EditSession.java#L899
    Clearly not 100 lines right there.
    So because you're young, tired, and cba to think, you expect others to think and do the hard work for you?
     
  17. Offline

    DrAgonmoray

    Nope. Education here REALLY sucks.
     
  18. Offline

    fury

    I'm young (like, 13), self-teaching myself Java, and doing everything on my own. you should learn from me.
     
    Slamakans likes this.
  19. Offline

    undeadmach1ne

    please tell me that you quoted the wrong person when you said that.
    edit - your profile "fury Member, Male, 21" hmmm
     
    thehutch likes this.
  20. Offline

    EvilPeanut

    It does have undo and max block change and all his does.

    Trust me, mine does undo and max block change just like worldedit, BUT A HELL LOT FASTER.

    Im 14, i know quite alot in java.
    Wanna team up and make a plugin?
    Got Skype?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  21. Offline

    codename_B

    Ok, so submit it in a pull request and make worldedit better, I'd love to see that.
     
    ChipDev, thehutch and r3Fuze like this.
  22. Offline

    desht

    You sound like a pretty amazing coder... so why are you asking for our help with this simple problem?
     
  23. Offline

    Lolmewn

    someone's getting angry ;O
     
  24. Wanna show us your code that is ten times shorter and A HELL LOT FASTER than WorldEdit's ? :)
     
  25. Offline

    Shamebot

    You can save performance by using the squared distance.
     
  26. Offline

    facecardz

    I'm confused, you're making a request for code that you've already written?
     
  27. Offline

    przerwap

    But we all know przerwap's code is the best
     
  28. No. He made code for setting a cuboid of blocks. What he wants is making a sphere.
     
  29. Offline

    nisovin

    I'm curious about how you determined this. Did you write test cases? Did you add timing debug statements to WorldEdit and compile it yourself? Or did you just use a stopwatch or something?
     
  30. He's 14. Nothing else to say.
    When you don't know what the "Edit" function is and when you do triple-post, you can't be serious.
     
Thread Status:
Not open for further replies.

Share This Page