HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Use of Matrix?

08-05-2008, 09:20 AM#1
Na_Dann_Ma_GoGo
Hi,
I think I've read several times, that I'm able to use a Matrix through doing some struct stuff or whatever.
If it is possible to use them... could someone show me how I can calculate with them in JASS?

Why I want to know this is... for leap / throw spells which have certain conditions I need to know the correct term for the unit's fly height.
E.g. I want the max. height to be 250 and at half the leap duration, the start height to be 100 and at the end of the leap / throw the height must be 0.
Now I could easily do this for one certain distances... however I want it to be dynamic and thus must calculate the terms each time the spell is cast.

So this is what I am doing with my pocket calculator and calculate afterwards. Note: x = time here 1 second is full time of the leap/throw

f(x) = ax³+bx²+cx+d

(start height = 0)| f(0) = 100 -> 0 + 0 + 0 + 1 = 100
(half time height)| f(0.5) = 250 -> 0.125 + 0.25 + 0.5 + 1 = 250
(end time height)| f(1) = 0 -> 1 + 1 + 1 + 1 = 0
(max at haf time)| f'(0.5) = 0 -> 0.75 + 1 + 1 + 0 = 0

result -> f(x) = -400X³ -200X² + 500X + 100

Now since the distance and hence the time (x) differs each time the Spell is used... I need to do calculate this stuff within my JASS Script... which I dunno how to do^^

Thanks in Advance!

Edit: Or did I get this wrong and something like this is impossible? :-(
08-05-2008, 04:20 PM#2
d07.RiV
It has nothing to do with matrices, and I highly doubt matrices will ever be used in maps.

First, if start height is different from end height then max. height will not be at the middle of the jump duration.

Let's see. You should have a set gravity value, e.g 800 units/sq. second. To make it realistic you will probably have to use a fixed starting speed so you actually just have one variable - pitch. Thus you cannot even control max. height. Say you need your object to travel x units horizontally and y units vertically (the difference between end and start heights), with speed v and gravity g. Let the angle be a.
Hidden information:

Horizontal speed = v * cos (a)
Leap time t = x / (v * cos (a))
Starting vertical speed = v * sin (a)
Final vertical speed = v * sin (a) - g * t
Average vertical speed = v * sin (a) - g * t / 2
y = vertical distance traveled = (v * sin (a) - g * t / 2) * t

Now we got the equation:
y = (v * sin (a) - g * t / 2) * t = x * tg (a) - g * x^2 / (2 * (v cos a)^2) = x * tg (a) - (g * x ^ 2 / 2v^2) * (tg(a)^2 + 1)

You could have skipped everything
But now you get a quadratic equation:
Code:
tg^2(a) * (g * x ^ 2 / 2v^2) +
tg(a) * x + 
g * x ^ 2 / 2v^2 - y
= 0
I suppose you know how to solve these.
But really, just make the unit move up at constant speed for the first half of the flight and then down for the second half, it looks fine enough.
08-05-2008, 05:39 PM#3
Na_Dann_Ma_GoGo
I'm not really sure what you're talking about.
On my calculator there you can use a certain "matrix" function to get the correct function term for a graph that has specific conditions. I had this at school the last a year ago, dunno if you ever had this.

If you've got any calculator and/or programme you can create graphs try the term I gave you. "f(x) = -400X³ -200X² + 500X + 100"
You will see that for the x value 0 y = 100 for 0.5 y = 250 for 1 y = 0

Seems though that it is impossible to do this within a Wc3 Trigger :-(
08-05-2008, 06:31 PM#4
moyack
What Na_Dann_Ma_GoGO needs is to model a parametric system equation.

Matrix calculation can be implemented with vJASS thanks to the new features offered like operator overloading and such. BUT (there's always a but) I don't recommend it because matrix calculations implies too much calculations which can be saved defining properly the requirements.

EDIT: I was writing a full compendium about modeling a parametric system but seeing your case I realized that you need is the following: http://www.wc3campaigns.net/showthre...=parabolic+arc

Quote:
Originally Posted by Malf
I can't brain.

I need help with my maths, I need to know what should x be. h is the max height and d is the distance.

Collapse JASS:
function ParabolicMovement takes real h, real d, real x returns real
    // thanks to moyack for this func!
    local real a = -4*h/(3*d*d)
    local real b = 4*h/(3*d)
    return a*x*x + b*x
endfunction
Quote:
Originally Posted by moyack
no, x is a distance, in WC3meters :P

This function takes as a parameters the the distance that the parabolic movement should move (d) and the maximum height the projectile will flight (h).

So x is a value between 0 and d, and the function will return the height for that value.

As a side note, if x < 0 or x > d then this function will return negative values.

EDIT: Here's a picture:

Zoom (requires log in)
08-05-2008, 07:45 PM#5
Na_Dann_Ma_GoGo
Oh that sounds promising. I'm sorry if I couldn't tell you exactly what I want... but I don't know the correct English terms concerning maths^^. Got no time now, will look at it tomorrow.
08-05-2008, 09:07 PM#6
d07.RiV
BTW I'm pretty sure WC3meters are actually centimeters. At least it helps coming up with ranges etc.

\As I said, fixing points on the path would mean the starting speed and gravity may vary drastically and I wouldn't recommend that. Choosing a constant speed/gravity would be more "realistic" but it would also put a limit on possible ranges (max range = speed^2 / gravity).
08-06-2008, 07:14 AM#7
Na_Dann_Ma_GoGo
Okay your parabolicMovement formula works great Moyack although I think now that a greater max height for greater distances etc. would look better^^. Since especially things thrown closely look kinda dumb since they raise/fall very rapid.
Is guess you guys know another function for parabolic movement whose max height depends on the distance?
Edit: I think I just do s.th. like Max heigh = 0.5 * distance and use your function.


And d007.RIV I now seem to understand what you wanted to tell me. Using gravity etc. , that would probably look the best and I'll come back on this another day.
08-07-2008, 02:54 AM#8
Jazradel
You could look at the Jump map I wrote. It's not exactly what you need, but it should be start.