# Snippet Beta: Circles

#### Dirac

##### 22710180
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 xyangle
//      -current angle retrieved in radians
//  real ZRotate
//      -rotation of the circle in it&#039;s Z axis.
//  real offsetX
//      -the X depending on the circle&#039;s radius and current angle
//  real offsetY
//      -the Y depending on the circle&#039;s radius and current angle
//  real offsetZ
//      -the Z depending on the circle&#039;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

//          -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&#039;s radius depending on the amount provided
//          -This is a very good way to avoid polar offset when you wan&#039;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&#039;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

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.
return this
endmethod

method setBase takes real radians returns nothing
local real prev=.base
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
endmethod

method operator offsetZ takes nothing returns real
endmethod

method operator zRotate= takes real radians returns nothing
endmethod

method operator offsetX takes nothing returns real
endmethod

method operator offsetY takes nothing returns real
endmethod

local real staticCos=.xCos
local real staticSin=.ySin
endmethod

method moveVector takes real howMuch, boolean clockwise returns nothing
if clockwise==false then
else
endif
endmethod

method moveZVector takes real howMuch, boolean clockwise returns nothing
if clockwise==false then
else
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: 221

#### Rllulium

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

#### tooltiperror

##### Super Moderator
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
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
The entire system itself should use radians instead of taking radians, converting to degrees to store, and then back again to use/return.

JASS:
``````//
return true
endif
return false``````

->
JASS:
``return SquareRoot(x*x+y*y)&lt;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)``````

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

#### Dirac

##### 22710180
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.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
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
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
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
By experimenting with Nestharus's way i found out that bj_PI is extremely inaccurate, any fix to this?

#### Romek

##### Super Moderator
[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
Well i lost a chunk of my brain, but there it is: changed everything to "vector fields", happy Nestharus?

#### Sevion

##### The DIY Ninja
All this 3D Vector stuff looks like fun. I'll have to give this a try

#### Nestharus

##### o-o
Well, without modifying the Z, it's a 2D vector field =p.

#### Dirac

##### 22710180
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.

### Members online

No members online now.