| 07-05-2007, 07:30 PM | #1 |
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... 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 | |
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:
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 |
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 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 = pointoneZ – pointtwoZ local real xyzdist = SquareRoot((xdist*xdist)+(ydist*ydist)+(zdist*zdist)) return (xyzdist/speed)+0.5 endfunction |
| 07-05-2007, 07:43 PM | #4 |
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 |
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 |
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 |
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 |
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 |
ok, thanks for the help |
| 07-05-2007, 08:18 PM | #10 |
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 |
I've found new, more efficient equations... this does more than my above posted codes in just a few lines 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 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 |
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 |
