• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Quadratic Arc Math

Status
Not open for further replies.
Level 12
Joined
Aug 20, 2007
Messages
866
Ok, I have worked on making Quadratic Arcs for wc3 about a thousand times, constantly going back over my code and my math

I have figured out how to make an arc work when given

1. The arcs Max Height
2. The arcs Max Distance (or distance away form zero where the arc finishes, or the second root's x coordinate)

I have no problem with this, my problem starts when I want to define an arc when given

1. The starting height
2. The ending height
3. The arcs Max Height
4. The distance from the start of the arc, to the the distance when the arc reaches its ending height

What I have been trying to do, is find some equations to use to reconstruct where the roots are of the arc if it was to be extended, while at the same time not knowing the equation of the arc

After finding the appropriate roots, I can use that equation for the arc in the system (and simply set the start height and the end height in the system)

I was curious to see if anybody else had the time or the balls to tackle a mathematical formula such as this

I have gotten some varied results, but after testing the formulas out on real equations, they don't work as well as I wish they would >< (I don't have a scientific calculator, and my computer doesn't have the calculator program [what the fuck :ugly: ] so it takes me alot of time to check out whether or not it was because of a square root function being + or -)

If I develop a functional formula to find this, I won't post it up here, as it will be in my new spellpack I am working one, which will feature a number of spells using a quadratic arc function that has a hell of alot of editing capacity
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
I'm wondering why do you need the start/end heights ?
The physical quotation for distance (x = x0 + v0 + 0.5 * at ^ 2 if my memory doesn't fail me) uses the start height/distance (depends for which direction it was meant to) anyways, and why would you need the end height ?
 
Level 9
Joined
Mar 25, 2005
Messages
252
height(s) = a*s2 + b*s + c
where
s = current distance traveled in the xy plane
c = starting_height
b = 2*(maximum_height-starting_height)*(1+SquareRoot((ending_height-maximum_height)/(starting_height-maximum_height)))/ending_distance
a = b*b/4/(starting_height-maximum_height)
 
Level 12
Joined
Aug 20, 2007
Messages
866
I'm wondering why do you need the start/end heights ?
The physical quotation for distance (x = x0 + v0 + 0.5 * at ^ 2 if my memory doesn't fail me) uses the start height/distance (depends for which direction it was meant to) anyways, and why would you need the end height ?

It is supposed to be for things like throwing a fireball, but the fireball has a set height (so it doesn't look like its coming out of the ground), and in some rare occasion spells are cast where the fireball goes down, but not all the way, vice-versa, and at the same time it can even start at a height, and then not hit the ground

I want to make an extremely flexible Arc function, but this last piece has me perplexed ><

I will try out Disciple of Life's, it looks suprisingly close to the equation I had come up with, but I believe I had made an error or two algebraically
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
Or you could just use the awesome physical formula:

Δs = 0.5*a*Δt2 + vi*Δt

Where:
Δs is the variation in position
Δt is the time necessary until the variation in position is obtained
a is the gravitational acceleration in m/s2
vi is the initial velocity.

Of course, this would be applicable only in the Z axis, as it's the only axis that is a uniform acceleration. The X and Y axis would be uniformly rectilinear, meaning the speed applied in those directions would be constant.

I'll let you isolate the variables you need.
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
Like I said, XY axis would be uniformly rectilinear movement, which would mean:

Δsxy = vxy*Δt

Therefore:

Δsxy/vxy = Δt

Then you'd substitute that value in the previous formula, and isolate for vi:

Δsz = 0.5*a*Δt2 + vi*Δt
Δsz = 0.5*a*(Δsxy/vxy)2 + vi*Δsxy/vxy
(Δsz - 0.5*a*(Δsxy/vxy)2)/(Δsxy/vxy) = vi

Δsz*vxy/Δsxy - 0.5*a*Δsxy/vxy = vi
That would be your initial Z velocity.
XY velocity would be user-determined.

I hope I didn't do a math error in there...
 
Level 12
Joined
Aug 20, 2007
Messages
866
Heh, I greatly appreciate the help guys, except I wanted to do it old school

I believe you guys were talking about a uniform movement on the axis of an angle on the xy plane, and a little acceleration/deceleration during movement on the Z-axis

I wanted to do it with a good old trinomial

Btw, I may have worded my question improperly, or not well enough to be understood, but I did come up with a formula for what I needed

First, I needed to find when the equation of the trinomial I am basing this off of is equal to EH, which represents the end height (I use capitals because it is easier for me to see)

Variables represent:

A = A (atm)
B = B (atm)
D = Max Distance
X = Given Distance
MH = Max Height of Arc
H = Height that the equation ends at

Here is the format for my trinomial:
-Ax^2 + Bx

Forget the C at the moment, that will probably come in later (when I do equations that have a starting height)

Ok, I was able to find A and B based off the midpoint

I am not going to do all of those calculations, as I am too lazy, and they can be done easily algebraically using the quadratic formula

At the end of those calculations:

A = 4MH / D^2
B = 4MH / D

...in this format -Ax^2 + Bx

Replacing the A and B variables with that, then coming up with the quadratic solution got me here
(Btw, I used the "finding the square" method rather than the quadratic formula, both are identical, just finding the square gives me a stronger sense of the algorithm)

[Here, +- is plus or minus)
X = D * ( +- Sqrt[MH - H] + Sqrt[MH])
_____________________
2 * Sqrt[MH]

Which I was able to simplify to

D = 2x*Sqrt[MH]
_________________________
+- Sqrt[MH - H] + Sqrt[MH]

I have found that if the X is greater than the midpoint, the +- will be positive
If it is shorter, it will be negative

I was able to prove this using the quadratic

-x^2 + 10x, where
MH = 25
D = 10

...and the points
X,Y
2,16
5,25
8,16

EDIT

I was a little curious, you think I should make the XY velocity decelerating, or constant/user-defined?

EDIT 2

Another thing, moving off this a little, is it possible to specify code function that is to be called in the parameters of another function

In other words, in my quadratic function, I am going to be adding in an after effect function that can be changed up by the user, so you don't need a whole new set of functions for every time you wanna use the arc function for a spell

Is there any way it could be done???
 
Last edited:
Level 9
Joined
Mar 25, 2005
Messages
252
I wanted to do it with a good old trinomial

Isn't ax2+bx+c a trinomial?

I was a little curious, you think I should make the XY velocity decelerating, or constant/user-defined?

I want to see how you combine acceleration with the equatations you have right now so I'd vote for accelerating ones.

Another thing, moving off this a little, is it possible to specify code function that is to be called in the parameters of another function

In other words, in my quadratic function, I am going to be adding in an after effect function that can be changed up by the user, so you don't need a whole new set of functions for every time you wanna use the arc function for a spell

Is there any way it could be done???

function interfaces are usually the best way to go.
To use them you first need to declare a function interface, e.g.
function interface AfterEffectFunc takes unit source, unit target returns nothing


after that you can have your launch function take a function that extends your interface, as an argument, e.g.
function LaunchQuadraticMissile takes unit source, unit target, real sfx, real maxHeight, real speed, AfterEffectFunc func returns nothing


then you can store that 'func' somewhere (as an integer or an AfterEffectFunc) and after your missile has hit something you can execute or evaluate it, e.g.
call func.evaluate(source, target)


To use the LaunchQuadraticMissile function the user would first have to declare his own AfterEffectFunc, e.g.
JASS:
function MyFunc takes unit source, unit target returns nothing extends AfterEffectFunc
//...
endfunction

then he can call the LaunchQuadraticMissile function like this:
call LaunchQuadraticMissile(source, target, sfx, maxHeight, speed, AfterEffectFunc.MyFunc)
 
Level 12
Joined
Aug 20, 2007
Messages
866
YES!!!

Woohoo that is exactly what I needed!!!

I am so happy, this is the first time in a long time I have asked a person for help and have gotten exactly what I had wanted

Bravo! +rep

I'm a bit peeved, I didn't wanna do it in vJASS, but that is ok, far better than nothing

I liked just using globals, but if I'm gonna do vJASS, I'm gonna need to use methods, structs, probably textmacros, and maybe even a little typecasting (that one I know very little about)

You know what, I think I am going to forget making the arc via trinomial

I think an acceleration/deceleration up + down would suit just fine, although I will need to re-do my calculations a bit, and review the ones you guys have posted here

I was also going to add a few additions to the function that are very uncommon, one of them is an Z axis angle on the arc, and an XY angled arc, if you took a look at the 4 shot spell I made, that is an XY angle (or at least that is what I am calling it)

The Z anlge thing, would be like an arc, but it has been rotated so it has a different look to it, its still kinda conceptional, but I will see if I wanna keep it in or not when I finish

Now that I think about putting velocity on the XY, it should probably be a user defined constant, but I could add a little boolean and a value for acceleration / deceleration, for those who like magic xD

EDIT

Haven't posted in a while, but I finished it and I found it really would look terrible with an acceleration. I believe I could work it out using the same math concept from knockback effects, again it wouldn't be worth it.
 
Last edited:
Status
Not open for further replies.
Top