Dirac
22710180
- Reaction score
- 147
Hello i coded this and i thought it might be useful.
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.
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.