HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Is my math faulty?

07-05-2007, 07:30 PM#1
TheSecretArts
I have a question. Is my math for calculating vector steps correct (to some extent)? I know im using percents but im trying some things out... i use alot of debugs because i plan to test in vJASS. If i'm wrong, please correct me in a way a high school sophmore in Advance Algebra 2 could understand... This code isnt optimized because im testing the code itself then ill optimize it to a few variables. Help will be greatly appreciated...
Collapse JASS:
function numsteps takes location one, location two, real pointoneZ, real pointtwoZ, real percentperstep returns integer
    local real xdist = GetLocationX(one) - GetLocationX(two)
        local real ydist = GetLocationY(one) – GetLocationY(two)
    local real zdist = pointoneZ – pointtwoZ
    local real xydist
    local real xyzdist
        debug local real steps
        debug call DebugMsg("X Distance is: "+xdist)
     debug call DebugMsg("Y Distance is: "+ydist)
    debug call DebugMsg("Z Distance is: "+zdist)
    set xydist= SquareRoot((xdist*xdist)+(ydist*ydist))
    debug call DebugMsg("XY Distance is: "+xydist)
    set xyzdist= SquareRoot((xydist*xydist)+(zdist*zdist))
    debug call DebugMsg("XYZ Distance is: "+xyzdist)
    debug set steps=(xyzdist*(percentperstep/100))
    debug call DebugMsg("Calculated Steps: "+steps)
    debug return steps
    return (xyzdist*(percentperstep/100))
endfunction

EDIT: Changed points to locations
07-05-2007, 07:38 PM#2
TheSecretArts
Anyone know any physics that can help?
To clarify my math, i first you the distance between the x and y of points one and two to calculate the xy distance by using the pythagerean theorem, and for all of you who dont know the pythagorean theorem, here ya go...
Quote:
Originally Posted by Pythageorean Theorem
The Pythagorean Theorem dictates that on every Right Triangle, you can calculate the value of Leg C (Hypotenuse) with the following equation:
"Leg A * Leg A + Leg B * Leg B = Leg C * Leg C"
so, to find the value of leg C, you just plug in A and B and for the square root of your answer
X1-X2=A
Y1-Y2=B
A*A+B*B=C*C
SqRt(C*C)=C=XY
Then i use a similiar method to calculate the xyz distance with C as A and z1-z2 as B
XY=A
Z1-Z2=B
A*A+B*B=C*C
SqRt(C*C)=C=XYZ
Then I multiply by Percent/100
XYZ*(Percent/100)=Steps
07-05-2007, 07:42 PM#3
Fireeye
it looks fine, only the point things are distrubing, use locations please

However as you already said it can be cut down.
If xy = root(a²+b²)
and xyz = xy²+c²
then you can use xyz = root(a²+b²+c²)
due if you make root(x)² you'll get x.
The code would look like this
Collapse JASS:
function numsteps takes location x, location y, real pointoneZ, real pointtwoZ, real speed returns integer
    local real xdist = GetLocationX(x) - GetLocationX(y)
    local real ydist = GetLocationY(x) – GetLocationY(y)
    local real zdist = pointoneZpointtwoZ
    local real xyzdist = SquareRoot((xdist*xdist)+(ydist*ydist)+(zdist*zdist))
    return (xyzdist/speed)+0.5
endfunction
But i don't see any problem with your function.
07-05-2007, 07:43 PM#4
Ammorth
What exactly are you trying to achieve with this function? Are you trying to figure out the number of steps it would take or how big each step would be or something else? Please be specific.
07-05-2007, 07:46 PM#5
TheSecretArts
Trying to find the number of steps to go from point A to point B... why calculate steps, because experiance before told be that one 1x1 tile is actually 1000*1000 or something like that... so i use that to calculate steps that would be used to go from point A to point B on a given speed
07-05-2007, 07:51 PM#6
Fireeye
So you want the function to return the theoritical amount of periods needed to reach the target, right?
e.g.
xd = 100; yd= 100; zd = 100
speed = 17,3
then you want to return 10, or did i miss anything?
07-05-2007, 07:52 PM#7
TheSecretArts
pretty much... thats the idea... then i would use other functions to control movement and such... pretty much im making a simple retrofitted physics system for my map that does the few basic things i need so it wont lag like crap but it will give me enough to make my project look good.
07-05-2007, 07:54 PM#8
Fireeye
Alright, edited the function i wrote in my first post, the +0.5 is used to round the numbers correctly up and down.
07-05-2007, 07:55 PM#9
TheSecretArts
ok, thanks for the help
07-05-2007, 08:18 PM#10
Ammorth
I found that trying to calculate the distance each step is required (before hand) and then increasing each value by the distance each step yielding horrible rounding errors. If you are looking for exact values, I would suggest using a formula to calculate the change from the base value, based on the duration. This is nullify any rounding errors since each calculation before is discarded and a new value is calculated, but it adds a bit of over-head.
07-05-2007, 11:25 PM#11
TheSecretArts
I've found new, more efficient equations... this does more than my above posted codes in just a few lines
Collapse JASS:
function Move takes real mass, real z, unit target returns unit
     local real vforce = initzforce()
     local real hforce = inithforce()
     local real zval = z
     set vforce=vforce-gravity(mass)
     set hforce=hforce-drag()
     if hforce<=0 then
          set hforce=0
     endif
     set zval=zval+vforce
     if zval<=0 then
          set z=0
     endif
     if zval==0 and hforce==0 then
          return target
     endif
     //Movement Code
endfunction
Functions Gravity and Drag would return the drag and gravity values and the init<n>forces would create a force between some two random numbers. And the move, all i would have to do is move the unit forward hforce and vertically vforce...
I was bored so I was trying to figure out ways for my previous solution to work, then I was pondering and I came upon this idea... I can use steps as small as i want and can create nice clean angles and such without things like sin and cos... this is all in theory of course
07-05-2007, 11:59 PM#12
TheSecretArts
I have a question... how do you calculate the drag coefficient of a sphere... same with it's unit vector... im new to drag physics so i have no idea how to calculate the drag coefficient, the unit vector, or the reference area of a sphere about the size of your palm...
I know its something like:

Fd=-1/2(1.293)(v*v)ACdV

Note: the V is actually a v-hat