• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Circles.

Status
Not open for further replies.
Level 6
Joined
Jul 18, 2009
Messages
200
New spell on turn!

I wanted to create a circle with units advancing out, then in to the caster. ( Plasma Field DotA someone? )
So, the problem is that i dont know how to create this circle( at all, dont ask me for an idea, cause i got no freaking idea. )

Can someone provide me a nippet with code? Thanks

EDIT: 200 Posts!
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
You utalize roots of circles principles from an offset point.
Make the immaginary axcess y and the real axcess x.
Thats all there is to it.

Basically e^i2pi represents a full rotation and brings you back to where you started.
Due to the forumal e^iangle = cos(angle)+isin(angle) you can break it appart using what I orignally said (angle represents theta or a variable in radians).
Thus as x is real, x = cos(angle) and as y is imaginary (iy), iy = isin(angle) which is the same as y = sin(angle).

But how do we get the radius into this?
Well simple, as |e^iangle| = 1 , that means that the radius of the circle is always 1. If we want a circle with a larger radius, we simply multiply e^iangle by a scalar. Thus re^iangle where r is radius.
This translates directly to our equations.
x = rcos(angle)
y = rsin(angle)

But you do not want the circle always in the middle of the map, thus offsets are needed.
x = rcos(angle)+xoff
y = rsin(angle)+yoff
Where x/yoff are the offsets to where you want the circle midpoint to be.

This gives you the formula for how to a point on a circle, but not how to arrange points evenly around a circle.
For that we use the roots of a circle theory which basically lets you generate points in a circle with a fixed angle offset from each other with a common midpoint.
(e^(iu))^n where u is the unity angle and n is the unity number.
e^(iun) means the same thing due to properties of indicies.
so how do we calculate u, as a circle is 2pi radians and we want points evenly spaced out, logically we divide it by the number of points we want to have (the root of the circle). Thus e^(i2pin/root) where root is the number of points on the circle you want.
Due to you also wanting it to spin, we must add some form of offset to the equation like e^(i2pin/root) * e^(ioff) where off is the offset angle which turns into e^(i(2pin/root+off)).
Due do subsitutation of angle with 2pin/root+off we get.
x = rcos(2pin/root+off)+xoff
y = rsin(2pin/root+off)+yoff

Or in computer form
x = r*cos(2*pi*n/root+off)+xoff
y = r*sin(2*pi*n/root+off)+yoff
for n, use any root (the value root in the formula) number of consecutive numbers with an interval of 1. Eg for root = 4, n ={0,1,2,3} or n ={4,3,2,1} or even n ={1337,1338,1339,1340} as long as the numbers are consecutive. I advise using eithor 1 or 0 and incrimenting upwards as that is the easiest and most logical to do as you can use root as part of the loop termination condtion.
You incriment offset (off) and radius (r) every time you regenerate the circle to get it to move. yoff and xoff should be the mid point of the circle, and if that is a unit you should perodically update it to be the units current position.

For more vluid moving points around a circle, you have to impliment a buffer movement layer which aims to move them into the positions calculated above but does so only at a certain rate, this would allow the points to gradually realign im the case of root being decrimented by 1 instead of instantly changing shape to match the new roots of the circle.
 
Level 6
Joined
Jul 18, 2009
Messages
200
Its only first year university mathimatics, nothing to complex at all.

However using trigonometry taught in highschool is all you really need. Think of a tri angle and how the cos and sin relate to a circle. You can see that from the formula I made.

Its only first year university mathimatics, nothing to complex at all.

The problem is that im 11 years old.. :p
 
Here's an example.

JASS:
function Circle takes real locX, real locY returns nothing
    local integer i = 0
    local real x
    local real y
    loop
        exitwhen i > 360
        set x = locX + 100 * Cos(i * bj_DEGTORAD)
        set y = locY + 100 * Sin(i * bj_DEGTORAD)
        //-------------------------
        // Do what you want with x, y here.
        // Ex: call CreateUnit(Player(0), 'hfoo', x, y, 0)
        // Will create a circle of footman.
        //-------------------------
        set i = i + 100
    endloop
endfunction
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
Well the age on your profile says you are 20, most confusing.

Basically, you get your standard Right angled triangle.
|\
|_\

From the angle of a corner with a right angled triangle you can tell the length of one of the sides using the trig and cos functions.

sohcahtoa
Sin = Opposite/Hypotonuse (the longest side)
Cos = Ajacent/Hypotonuse
Tan = Opposite/Ajacent

By these I mean the lenghts of each if they were in a 2D plane like universe.

The simple way to look at what cos(angle) and sin(angle) give you is imagine a right angled triangle with a hypotonuse (the longest side) with length 1.
Cos(angle) will give you the length of the side which makes up the angle inputed when compred to the hypotonuse.
Sin(angle) will give tou the length of the side which is not used to build the angle (the sie opposite the angle).

These only work like this on right angled triangles, although there obviously is maths for non right angled ones.

Honestly, its a huge subject that cant be learned in one day. I seriously advise asking teachers about it, looking up wikipedia and stuff. It is the key for any game programming due to how they relate to real life.
 
Level 6
Joined
Jul 18, 2009
Messages
200
Here's an example.

JASS:
function Circle takes real locX, real locY returns nothing
    local integer i = 0
    local real x
    local real y
    loop
        exitwhen i > 360
        set x = locX + 100 * Cos(i * bj_DEGTORAD)
        set y = locY + 100 * Sin(i * bj_DEGTORAD)
        //-------------------------
        // Do what you want with x, y here.
        // Ex: call CreateUnit(Player(0), 'hfoo', x, y, 0)
        // Will create a circle of footman.
        //-------------------------
        set i = i + 100
    endloop
endfunction

Thanks.

@Dr_Super_Good

The profile says that because i didnt come in as 11 years old. So instead of 98, i took 89. :S
 
Status
Not open for further replies.
Top