HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[JASS] Looking for a math formula

10-02-2008, 01:30 AM#1
Zandose
I'm sure this has been asked a hundreds times before but, I'm looking for a math formula. I tried looking but I have no clue what I'm looking for.

From the center x/y I want find all the x/y points with a distance of 256 and each x/y should be 32 apart.

Thank you.
10-02-2008, 01:39 AM#2
Bobo_The_Kodo
Collapse JASS:
    real inc=32
    real d = 512
    real x
    real y=-d/2
    loop
        exitwhen y>d/2
        x=-d/2
        loop
            exitwhen x>d/2

            //Do stuff here (x,y)
            
            set x=x+inc
        endloop
        set y=y+inc
    endloop

Edit: Lawl zerzax, we both have 57 posts ^^

also you werent clear if it was a circle or points in a rectangle so, here goes for circ

Collapse JASS:
    local real x = ?
    local real y = ?
    
    local real d = 256
    local real inc = 32
    local real i = 0
    local real tx
    local real ty

    loop
        exitwhen i > d/inc
        set i = i + 1
        set tx = x + d * Cos( 6.28328/(d/inc)*i )
        set ty = y + d * Cos( 6.28328/(d/inc)*i )

        //Do stuff here (tx,ty)
    endloop
10-02-2008, 01:47 AM#3
Zerzax
I don't have a formula for you, but I think you can find this stuff out using the circumference of your circle. If you take 2(pi)(256), you have your circumference. If you divide the circumference by 32, you should find the number of times you cross a distance of 32 in the circle (curved, at least). You can divide 2(pi) or 360 by this resulting number and you might just have your angle.

Here goes:
2(pi)(256)=1608.495439
1608/32=50.26
360/50.25=7.16

Try projecting your coordinates with:
Xcoord + Cos(7.16 * pi/180 * LoopIndex (if you're using loops))
Ycoord + Sin(7.16 * pi/180 * LoopIndex (...))



I might be using the wrong units, and this could be WAY off, but it's worth a try.

EDIT: heh guess I was too slow, do what Bobo said...
10-02-2008, 02:11 AM#4
TEC_Ghost
Not the best way to go about it, but this explains the general idea.

Collapse JASS:
function Range takes nothing returns nothing
local location loc = GetSpellTargetLoc()
local string SFX = "Abilities\\Spells\\Undead\\Curse\\CurseTarget.mdl"
local location Loc = Location(GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()))
local integer i = 1
local integer space = 32 //Space between each effect
local integer degree = 0 //Default start degree
local integer max = 360 / space //Gives the max number of points
local integer offset = 256 //Your polar offset

    loop
    exitwhen i > max
        set degree = degree + space
        call AddSpecialEffectLoc(SFX,PolarProjectionBJ(Loc, offset, degree))
    set i = i + 1
    endloop


endfunction

10-02-2008, 02:38 AM#5
Zandose
Thank you. +rep
10-02-2008, 12:40 PM#6
Deaod
Still a bad example, but this should at least be mathematically correct.

Collapse JASS:
function Range takes nothing returns nothing
local location loc = GetSpellTargetLoc()
local string SFX = "Abilities\\Spells\\Undead\\Curse\\CurseTarget.mdl"
local location Loc = Location(GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()))
local integer i = 1
local integer space = 32 //Space between each effect
local real degree = 0. //Default start degree
local integer offset = 256 //Your polar offset
local real interval = (Asin( space/(offset*2) )*2)*(180/bj_PI)
local integer max = R2I(360 / interval) //Gives the max number of points

    loop
    exitwhen i > max
        set degree = degree + interval
        call AddSpecialEffectLoc(SFX,PolarProjectionBJ(Loc, offset, degree))
    set i = i + 1
    endloop


endfunction
10-10-2008, 08:57 PM#7
Zandose
Dump. I tried this but it didn't work:
Quote:
Collapse JASS:
    local real x = ?
    local real y = ?
    
    local real d = 256
    local real inc = 32
    local real i = 0
    local real tx
    local real ty

    loop
        exitwhen i > d/inc
        set i = i + 1
        set tx = x + d * Cos( 6.28328/(d/inc)*i )
        set ty = y + d * Cos( 6.28328/(d/inc)*i )

        //Do stuff here (tx,ty)
    endloop

Recap and the trigger I tried: I want to find all the points in a circle but with a space of 64 between each point.
Collapse JASS:
    local real i = 0
    loop
        exitwhen i > 256/64
        set i = i + 1
        call CreateDestructable('0000', 0+256*Cos(6.28328/(256/64)*i), 0+256*Cos(6.28328/(256/64)*i), 0, 1, 1)
    endloop

Did I do something wrong or is the trigger wrong?
10-10-2008, 11:40 PM#8
Bobo_The_Kodo
Sorry, I messed up, try this

Collapse JASS:
    local real x = ?
    local real y = ?
    
    local real num = 5//For 5 points around the circle
    local real r = 0
    local real tx
    local real ty

    loop
        exitwhen r >= 6.28328
        set tx = x + d * Cos( r )
        set ty = y + d * Sin( r )
        set r = r + 6.28328/num
        //Do stuff here (tx,ty)
    endloop
10-12-2008, 03:11 PM#9
Zandose
Sorry I didn't reply for a while. I got a sick and couldn't really move for a day or two. Anyways, not exactly what I wanted but I've adapted it to work good enough. Thank you.