Snippet Movement Calculation

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
/////////////////////////////////////////////////////////////////////////////////////////////
//  Functions :
//
//  GetDisplacementLoc(locationA,locationB) -> real(Distance Between 2 points)
//  GetDisplacement(x1,y1,x2,y2) -> real(Distance Between 2 points)
//  GetVelocityLoc(locationA,locationB,time) -> real(X range/second)
//  GetVelocity(x1,y1,x2,y2,time) -> real(X range/second)
//  GetAcceleration(final velocity, initial velocity, time) -> range/second-1
//
//  Recommended using XY since it is faster.
//  P/S : I found the the unit does not move unitformly in warcraft engine.
//        They have acceleration and decceleration
/////////////////////////////////////////////////////////////////////////////////////////////
library MovementCalculating

    function GetDisplacementLoc takes location locA, location locB returns real
        local real locAX = GetLocationX(locA)
        local real locAY = GetLocationY(locA)
        local real locBX = GetLocationX(locB)
        local real locBY = GetLocationY(locB) 
        return SquareRoot((locBX - locAX) * (locBX - locAX) + (locBY - locAY) * (locBY - locAY))
        //Return distance between 2 points
    endfunction

    function GetDisplacement takes real x1, real y1, real x2, real y2 returns real 
        return SquareRoot((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
        //Return distance between 2 points
    endfunction
    
    function GetVelocityLoc takes location locA, location locB, real time returns real
        return GetDisplacementLoc(locA, locB)/time
        //Return Velocity
    endfunction
    
    function GetVelocity takes real x1, real y1, real x2, real y2, real time returns real 
        return GetDisplacement(x1, y1, x2, y2)/time
        //Return Velocity
    endfunction
    
    function GetAcceleration takes real v, real u, real time returns real
        //V = Final Velocity
        //U = Initial Velocity
        return (v-u)/time
        //Return acceleration
        //If returned value is negative, then it is decceleration
        //If returned value is 0, then it is neither accelerates or decelerates but is constant velocity
    endfunction
   
   
endlibrary


Hmm, i think it is useful in calculating APM(s).
I have attached a map here for u guys to test it! :D
 

Trollvottel

never aging title
Reaction score
262
Looks kind of useless to me. Every 12 year old child would be able to do this (if it knows jass and is not too stupid).

Also:
JASS:
 function GetDisplacementLoc takes location locA, location locB returns real
        local real locAX = GetLocationX(locA)
        local real locAY = GetLocationY(locA)
        local real locBX = GetLocationX(locB)
        local real locBY = GetLocationY(locB) 
        return SquareRoot((locBX - locAX) * (locBX - locAX) + (locBY - locAY) * (locBY - locAY))
        //Return distance between 2 points
    endfunction


this looks like crap to me, its like the DistanceBetweenPoints BJ-function but worse, since it uses more calculations and more variables.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
So I recommended use XY. The Location is slower but I made it also for location users easy to use it.
 

Trollvottel

never aging title
Reaction score
262
But why do you even implement a function if Blizzard provides a better version of it?
 

_whelp

New Member
Reaction score
54
How do I use this?

According to Trollvottel, I wouldn't understand this because I'm ten.
 

_whelp

New Member
Reaction score
54
Can't you just write down the formula?
It's pretty easy to remember an write anyways.
 

Flare

Stops copies me!
Reaction score
662
How do I use this?

According to Trollvottel, I wouldn't understand this because I'm ten.
He said 12, not 10 (although you might do this sort of math at that age anyway) :p

Overall, it's just basic math and not hard for anyone to do. The location one is pointless since the BJ function already exists and most people who use JASS would be using coordinates anyway
 

wraithseeker

Tired.
Reaction score
122
JASS:
function GetDisplacement takes real x1, real y1, real x2, real y2 returns real 
        return SquareRoot((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
        //Return distance between 2 points
    endfunction


JASS:
 return SquareRoot((locBX - locAX) * (locBX - locAX) + (locBY - locAY) * (locBY - locAY))


Identical and totally the same.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Is this faster?

JASS:
function GetDisplacement takes real x1, real y1, real x2, real y2 returns real 
        return x1*x1 -2*x1*x2 +x2*x2 + y1*y1-2*y1*y2+y2*y2
endfunction


Any ideas?
 

Trollvottel

never aging title
Reaction score
262
@Flare

It was

"wouldn't",

not "would".

And i didnt say 10 year olds couldnt understand. but have you done linear functions or pythagoras? (This system is only pythagoras and linear functions)

Is this faster?

JASS:
function GetDisplacement takes real x1, real y1, real x2, real y2 returns real 
        return x1*x1 -2*x1*x2 +x2*x2 + y1*y1-2*y1*y2+y2*y2
endfunction


Any ideas?

Does it even work? Looks weird to me, which formula did you use to make this?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top