Snippet vCircles

Dirac

22710180
Reaction score
147
vCircles is a very useful snippet for spinning points around bidimensional cicles or tridimensional spheres. It's very fast and has the capacity of calculating distances across the circle's perimeter, so if you want to move a projectile for, lets say, 40 units around a perimeter, with vCircles you can.
JASS:
library vCircles
//**************************************************************************************************************************
//Snippet made by Dirac to avoid polar offset positioning
//  This creates a circle around a point with a base angle 0. this angle determines the offset location
//  of the point you might need to move or create something.

//Variables:
//  real x
//      -center X
//  real y
//      -center Y
//  real radius
//      -radius of the circle
//  real xyangle
//      -current angle in the x axis
//  real zangle
//      -current angle in the z axis

//Read only values:
//  real offsetX
//      -the X depending on the circle's radius and current angle
//  real offsetY
//      -the Y depending on the circle's radius and current angle
//  real offsetZ
//      -the Z depending on the circle's height.
//  real xyspin
//      -the amount of spins done in the x axis.
//  real zspin
//      -the amount of spins done in the z axis.

//Setting up values
//  set baseX=radians
//      -Sets the xyangle base rotation to a value

//Methods:
//  static method create takes real x, real y, real z, real radius returns thistype
//          -Imput here the center x,y,z and radius, default angle is 0, you can change that later

//  method radiusVector takes real howMuch, real radians returns nothing
//          -This method reduces or increases the radius lenght towards an angle
//          -The angle is measured starting from the edge of the circle, a few examples:
//            if the angle provided is 0 the radius would increase exactly by the amount provided,
//            if the angle provided is 180 the radius would decrease exactly by the amount provided,
//            if the angle provided is 90 the radius would increase sightly

//  method polarVector2d takes real howMuch, boolean clockwise returns nothing
//          -This method moves the circle angle around it's radius depending on the amount provided
//          -This is a very good way to avoid polar offset when you wan't to move something exactly
//          by an amount of distance around a point, not an angle.

//  method polarVector3d takes real howMuch, real radians returns nothing
//          -This method moves the offset of the point by the amount provided towards the angle
//          provided around the sphere. Use this if you care about the distance the point moves

//  method polarSpin3d takes real radiansX, real radiansZ returns nothing
//          -This method spins the offset of the point around the X and Z axis towards the angle
//          provided. Use this to give a smooth movement around the circle.

//**************************************************************************************************************************
    struct circle
        real x
        real y
        real z
        real radius
        real xyangle
        real zangle
        readonly real xyspin
        readonly real zspin
        
        private real xBase
        
        static method create takes real x, real y,real z, real radius returns thistype
            local thistype this=thistype.allocate()
            set .x=x
            set .y=y
            set .z=z
            set .xyangle=0
            set .zangle=0
            set .xyspin=0
            set .zspin=0
            set .xBase=0
            set .radius=radius
            return this
        endmethod
        
        method operator baseX= takes real radians returns nothing
            set .xyangle=.xyangle+radians-.xBase
            set .xBase=radians
        endmethod
        
        method operator offsetZ takes nothing returns real
            return .z+.radius*Sin(.zangle)
        endmethod
        
        method operator offsetX takes nothing returns real
            return .radius*Cos(.xyangle)*Cos(.zangle)+.x
        endmethod
        
        method operator offsetY takes nothing returns real
            return .radius*Sin(.xyangle)*Cos(.zangle)+.y
        endmethod

        method radiusVector takes real howMuch,real radians returns nothing
            local real A=.radius
            set .radius=SquareRoot(.radius*.radius+howMuch*howMuch-2*howMuch*.radius*Cos(bj_PI-radians))
            set .z=.z+.radius-A
        endmethod
        
        method polarVector2d takes real howMuch, boolean clockwise returns nothing
            local real a=2*Asin(howMuch/(2*.radius))/RAbsBJ(Cos(.zangle))
            if clockwise==false then
                set .xyangle=.xyangle+a
            else
                set .xyangle=.xyangle-a
            endif
            set .xyspin=.xyspin+a
        endmethod
        
        method polarVector3d takes real howMuch, real radians returns nothing
            local real a=2*Asin(howMuch/(2*.radius))*Cos(radians)/RAbsBJ(Cos(.zangle))
            local real b=2*Asin(howMuch/(2*.radius))*Sin(radians)
            set .xyangle=.xyangle+a
            set .zangle=.zangle+b
            set .xyspin=.xyspin+a
            set .zspin=.zspin+b
        endmethod
        
        method polarSpin3d takes real radiansX, real radiansZ returns nothing
            set .xyangle=.xyangle+radiansX
            set .zangle=.zangle+radiansZ
            set .xyspin=.xyspin+radiansX
            set .zspin=.zspin+radiansZ
        endmethod
        
    endstruct
endlibrary


Graphical explanations of how to use it coming soon. Enjoy!
 

Attachments

Nestharus

o-o
Reaction score
83
You know, it'd be cooler if you had an x radius, y radius, and z radius, or you allowed for horizontal and vertical eccentricity. This upgrade this resource from supporting just circles and spheres to ellipses and ellipsoids.


Another cool thing would be to be able to base the x,y coords off of a widget or location =P.
 

Dirac

22710180
Reaction score
147
Well i tried to add the Y radius before, but didn't get the math though. Ellipses would be very cool yes, but i feel i'm not skilled enought to do it yet, i'll keep working on that. (So far the only thing i can do is add the Z ellipse option that would be very easy)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • jonas jonas:
    where did you go?
  • The Helper The Helper:
    Jefferson TX on a Paranormal Investigation of a haunted bed and breakfast - I got some friends that are paranormal investigators and they have an RV and do YouTubes
    +1
  • The Helper The Helper:
    It was a lot of fun. The RV was bad ass
  • jonas jonas:
    That sounds like fun!
    +1
  • The Helper The Helper:
    it was a blast!
  • The Helper The Helper:
    I am going to post the Youtube of the investigation in the forums when it is ready
    +1
  • jonas jonas:
    cool!
  • vypur85 vypur85:
    Sounds cool TH.
  • tom_mai78101 tom_mai78101:
    I was on a Legend of Zelda marathon...
  • tom_mai78101 tom_mai78101:
    Am still doing it now
    +1
  • jonas jonas:
    which one(s) are you playing?
  • jonas jonas:
    I played a little bit of the switch title two weeks ago and found it quite boring
  • The Helper The Helper:
    just got back from San Antonio this weekend had the best Buffalo Chicken Cheesesteak sandwhich in Universal City, TX - place was called Yous Guys freaking awesome! Hope everyone had a fantastic weekend!
    +1
  • The Helper The Helper:
    Happy Tuesday!
  • The Helper The Helper:
    We have been getting crazy numbers reported by the forum of people online the bots are going crazy on us I think it is AI training bots going at it at least that is what it looks like to me.
  • The Helper The Helper:
    Most legit traffic is tracked on multiple Analytics and we have Cloud Flare setup to block a ton of stuff but still there is large amount of bots that seem to escape detection and show up in the user list of the forum. I have been watching this bullshit for a year and still cannot figure it out it is drving me crazy lol.
    +1
  • Ghan Ghan:
    Beep boop
    +1
  • The Helper The Helper:
    hears robot sounds while 250 bots are on the forum lol
  • The Helper The Helper:
    Happy Saturday!
    +1
  • The Helper The Helper:
    and then it was Thursday...
    +2
  • tom_mai78101 tom_mai78101:
    And then Monday
    +1
  • The Helper The Helper:
    I got the day off today!
    +1
  • tom_mai78101 tom_mai78101:
    How...? (T-T)
  • The Helper The Helper:
    I took the day off. I work for myself so I can do that.
    +1
  • Varine Varine:
    Well I'm already over summer

    The Helper Discord

    Members online

    No members online now.

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top