Snippet Beta: Circles

Dirac

22710180
Reaction score
147
Hello i coded this and i thought it might be useful.
JASS:
library TCircles
//**************************************************************************************************************************
//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 retrieved in radians
//  real ZRotate
//      -rotation of the circle in it's Z axis.
//  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.

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

//  method radiusVector takes real howMuch, real radians returns nothing
//          -This method reduces the radius size by a certain amount 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 moveVector 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 moveZVector takes real howMuch, boolean clockwise returns nothing
//          -This method moves the circle angle around it's radius on the Z axis depending on the amount provided

//  method setBase takes real radians returns nothing
//          -This method modifies the base angle of the circle, moving the offset location.

//**************************************************************************************************************************
    struct circle
        real x
        real y
        real z
        real radius
        
        private real xCos
        private real ySin
        private real zCos
        private real zSin
        private real base
        
        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 .xCos=1.
            set .ySin=0.
            set .zCos=1.
            set .zSin=0.
            set .base=0.
            set .radius=radius
            return this
        endmethod
        
        method setBase takes real radians returns nothing
            local real prev=.base
            set .base=radians
            set .xyangle=.xyangle+.base-prev
        endmethod
        
        method operator xyangle takes nothing returns real
            return Atan2(.ySin,.xCos)
        endmethod
        
        method operator xyangle= takes real radians returns nothing
            set .xCos=Cos(radians)
            set .ySin=Sin(radians)
        endmethod
        
        method operator offsetZ takes nothing returns real
            return .z+.radius*zSin
        endmethod
        
        method operator zRotate= takes real radians returns nothing
            set .zCos=Cos(radians)
            set .zSin=Sin(radians)
        endmethod
        
        method operator offsetX takes nothing returns real
            return .xCos*.radius*zCos+.x
        endmethod
        
        method operator offsetY takes nothing returns real
            return .ySin*.radius*zCos+.y
        endmethod

        method radiusVector takes real howMuch,real radians returns nothing
            local real A=.radius
            local real staticCos=.xCos
            local real staticSin=.ySin
            set .radius=SquareRoot(.radius*.radius+howMuch*howMuch-2*howMuch*.radius*Cos(bj_PI-radians))
            set .xCos=Cos(Atan2(staticSin,staticCos)+Acos((.radius*.radius+A*A-howMuch*howMuch)/(2*.radius*A)))
            set .ySin=Sin(Atan2(staticSin,staticCos)+Acos((.radius*.radius+A*A-howMuch*howMuch)/(2*.radius*A)))
        endmethod
        
        method moveVector takes real howMuch, boolean clockwise returns nothing
            if clockwise==false then
                set .xCos=.xCos-.ySin*2*howMuch/(bj_PI*.radius)
                set .ySin=.ySin+.xCos*2*howMuch/(bj_PI*.radius)
            else
                set .xCos=.xCos+.ySin*2*howMuch/(bj_PI*.radius)
                set .ySin=.ySin-.xCos*2*howMuch/(bj_PI*.radius)
            endif
        endmethod
        
        method moveZVector takes real howMuch, boolean clockwise returns nothing
            if clockwise==false then
                set .zCos=.zCos-.zSin*2*howMuch/(bj_PI*.radius)
                set .zSin=.zSin+.zCos*2*howMuch/(bj_PI*.radius)
            else
                set .zCos=.zCos+.zSin*2*howMuch/(bj_PI*.radius)
                set .zSin=.zSin-.zCos*2*howMuch/(bj_PI*.radius)
            endif
        endmethod
    endstruct
endlibrary

I consider myself good at english but when it comes to explaining stuff i'm a total wreck, so i draw these helpful demostrations to show how does the snippet works.

Here's a demostration of the "moveVector" method, the red dot shows the location you'll get if you use .getX() and .getY()


Here's a demostration of the "radiusVector" method


Demo Map? yes.
 

Attachments

  • TCircles.w3x
    59.8 KB · Views: 213

Rllulium

New Member
Reaction score
10
JASS uses radians for angles, don't you think that you should too?
To avoid unnecessary conversion.
 

tooltiperror

Super Moderator
Reaction score
231
Agreed. People (excluding new JASSers) generally use radians, and when people do use degrees, they have to generally convert to radians ([LJASS]bj_DEGTORAD[/LJASS])
 

Dirac

22710180
Reaction score
147
the only thing i do i my system that uses degrees is 180*bj_DEGTORAD but i guess i should just write bj_PI there (edit: already did), if you want to retrieve radians in your equations just use .xyangle as i say in the description or set .xyangle to an amount of radians. The angle operator was just added to make it more user friendly. I was thinking that maybe i would add if the system gets enough feedback and use, ellipses and spheres, but i'm really lost when it comes to drawing an ellipse with an angle in a equation : /
 

Romek

Super Moderator
Reaction score
963
The entire system itself should use radians instead of taking radians, converting to degrees to store, and then back again to use/return.

JASS:
//
            if SquareRoot(x*x+y*y)<currentdata.radius*currentdata.radius then
                return true
            endif
            return false

->
JASS:
return SquareRoot(x*x+y*y)<currentdata.radius*currentdata.radius

(I don't think that SquareRoot function should even be there, since you're squaring the radius on the other side of the operator)

JASS:
//
            call GroupClear(GROUP)
            call GroupEnumUnitsInRect(GROUP,GetWorldBounds(),function thistype.check)

Group enum functions already clear the group before adding new units.

You should use [ljass]bj_mapInitialPlayableArea[/ljass] instead of [ljass]GetWorldBounds()[/ljass] when selecting all units within the map.
 

Dirac

22710180
Reaction score
147
Thanks Romek i'll do some improvement there

as i'm trying to say my system DOES take radians, i just added the angle opeator to make it more user friendly:
circlestruct.xyangle = returns radians
circlestruct.angle = returns angles

Oh and i'll check that right away Nestharus, this is the way i've always drawn circles

EDIT: i'm loving the feedback
 

Dirac

22710180
Reaction score
147
Ok i made an update since radiusVector was really really really broken, now it works properly.

EDIT: also do does anyone else think this is ready for submission?
 

Dirac

22710180
Reaction score
147
i have to agree, i'm thinking of giving it 3d features, might include 3d ellipses. Also, updated the snippet to a version that no longer requires any kind of offset from the circle's center, lots of equations, i hope that's what you meant with the center polarization.

Fully tested, works great
 

Nestharus

o-o
Reaction score
84
Ok, here's what I want you to do..

create a unit at position 300,300 and move it 32x a second with this equation-
JASS:

set x=GetWidgetX(u)
set y=GetWidgetY(u)
call SetUnitX(u,x-y*.03125*.03125)
call SetUnitY(u,y+x*.03125*.03125)


That will move it in a circle around 0,0... now I'm going to leave it up to you to figure out how to offset it so that it's origin is wherever and so that it's radius is whatever.


The .03125*.03125 is just to slow it down.


Now, I think that what I did there is a lot less overhead than what you'd normally do with polar projections.


You learn vector fields to this level in Calculus 3 =).
 

Dirac

22710180
Reaction score
147
By experimenting with Nestharus's way i found out that bj_PI is extremely inaccurate, any fix to this?
 

Romek

Super Moderator
Reaction score
963
[ljass]bj_PI[/ljass] is a constant with the value 3.14159. It's pi to 5 decimal places - more than accurate enough for any real applications. It must be something wrong with your code.

> as i'm trying to say my system DOES take radians, i just added the angle opeator to make it more user friendly:
I'm aware of that. I'm saying that although it does take/return radians, you're converting internally to degrees to store, and then back to radians when you want to return. You should just keep everything in radians.
 

Dirac

22710180
Reaction score
147
Well i lost a chunk of my brain, but there it is: changed everything to "vector fields", happy Nestharus? :D
 

Dirac

22710180
Reaction score
147
you guys are HARD - TO - PLEASE.
anyways, just made it 3d you can now create spheres and stuff, the test map is very cool, go test it now. IT'S STILL A BETA

What needs to be done:
integrate both moveVector and moveZVector methods into one to be able to move the particle the same distance all along. Currently moves first the xy axis then the z axis
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    I ordered like five blocks for 15 dollars. They're just little aluminum blocks with holes drilled into them
  • Varine Varine:
    They are pretty much disposable. I have shitty nozzles though, and I don't think these were designed for how hot I've run them
  • Varine Varine:
    I tried to extract it but the thing is pretty stuck. Idk what else I can use this for
  • Varine Varine:
    I'll throw it into my scrap stuff box, I'm sure can be used for something
  • Varine Varine:
    I have spare parts for like, everything BUT that block lol. Oh well, I'll print this shit next week I guess. Hopefully it fits
  • Varine Varine:
    I see that, despite your insistence to the contrary, we are becoming a recipe website
  • Varine Varine:
    Which is unique I guess.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air

      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