Curve Movement

Ayanami

칼리
Reaction score
288
I've been pondering on creating a curve movement. Please note that this isn't a jump spell and everything is on the 2D plane. So, I've been trying to create a basic parabola (quadratic) curve. The only information I have is the starting point, end point and the maximum point. Is there a way to create this curve movement with only this 3 points?
 

Endless_Trev

New Member
Reaction score
5
Just for simplicity I would say you should use the local maxima or minima as the centre of the of the parabola's x and y axis. Also try to come up with a standard form for your parabola, say y=x^2/8 or something, depending on what curvature you want to achieve. Since you know the general equation the derivative would be x/4, so you would just have to sub in the x value of a co-ordinate into x/4 and that would give you the gradient of the tangent at that line, so you can move the unit in the direction of the tangent. Of course this is all using the maxima or minima as (0,0), meaning you will always have to treat the differing positions in relation to the origin of the graph you are basing around the parabola. Ive tried myself using things like leap, but I get lazy and revert to primitive versions of creating parabolic motion.

Yes it should be relatively easy if you know what you're doing, which I assume you do.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
Bleh, he's not asking how to move something along a curve, he's asking how to interpolate using 3 points.

If you want the formula in terms of x and y, of the form y=ax^2+bx+c, and one of your points is the parabolic vertex, you can only really use 2 points, since parabolas of that form are symmetric. In this case, you can use:
Y=AX^2+AB(B-2X)+C
(This is a parabolic form such that B is the vertex's x, C is the vertex's y, and A is what it is in standard parabolic form)
Using this formula, if the vertex is (U,V) and the other point is (J,K), then:
A=(K-V)/(J-U)^2
B=U
C=V



However, this sort of math is kind of limited. If you're interested in interpolating 3 points along a second-degree curve, for many purposes Bezier Curves work very well.
They can be applied to any number of dimensions with little pain (note how wiki gives the formula for a single dimension, with coordinate components given as 'P0', 'P1', and 'P2'), are neato in that they're always parameterized by t from t=0 to t=1, and they have the interesting property that their gradient approaches the slope from the center point to each endpoint at the respective endpoints.
 

Never_Quit

New Member
Reaction score
16
parametric would be easiest when dealing with unit position.

y = (t^2)(height constant)
x = (t+1)(distance constant)

where t is the phase of the movement.

EDIT: The higher number of loops for t that you run, the smoother the animation. The smother then animation, the lower the distant and height constant must be relative to the same path of movement. Pretty basic really. You would make the unit instantaneously move to a point (unit's starting position) with offset: x and y.
 

Ayanami

칼리
Reaction score
288
Bleh, he's not asking how to move something along a curve, he's asking how to interpolate using 3 points.

If you want the formula in terms of x and y, of the form y=ax^2+bx+c, and one of your points is the parabolic vertex, you can only really use 2 points, since parabolas of that form are symmetric. In this case, you can use:
Y=AX^2+AB(B-2X)+C
(This is a parabolic form such that B is the vertex's x, C is the vertex's y, and A is what it is in standard parabolic form)
Using this formula, if the vertex is (U,V) and the other point is (J,K), then:
A=(K-V)/(J-U)^2
B=U
C=V

However, this sort of math is kind of limited. If you're interested in interpolating 3 points along a second-degree curve, for many purposes Bezier Curves work very well.
They can be applied to any number of dimensions with little pain (note how wiki gives the formula for a single dimension, with coordinate components given as 'P0', 'P1', and 'P2'), are neato in that they're always parameterized by t from t=0 to t=1, and they have the interesting property that their gradient approaches the slope from the center point to each endpoint at the respective endpoints.

Would you mind elaborating more on Bezier Curves?
 

13lade619

is now a game developer :)
Reaction score
398
may I ask what level of education you're in now? (Middle school / high school / college).

i'll try to elaborate... well yeah, if i can remember how to convert parametric to cartesian which i learned last semester.. *EDIT*

Basically, what you need is the Quadratic Bezier Curve.

Equation
2d5e5d58562d8ec2c35f16df98d2b974.png


you'll need the points P0, P1 and P2. and find the values from t=0 to t=1.
it's neat that it's in parametric so you can use them in x-y coords or even x-y-z.

240px-Bezier_2_big.gif
 

Never_Quit

New Member
Reaction score
16
may I ask what level of education you're in now? (Middle school / high school / college).

i'll try to elaborate... well yeah, if i can remember how to convert parametric to cartesian which i learned last semester.. *EDIT*

Basically, what you need is the Quadratic Bezier Curve.

Equation
2d5e5d58562d8ec2c35f16df98d2b974.png


you'll need the points P0, P1 and P2. and find the values from t=0 to t=1.
it's neat that it's in parametric so you can use them in x-y coords or even x-y-z.

240px-Bezier_2_big.gif

so if I understand correctly, using this function, for a loop in code, you would have t equal 1/a where:
for each int a from DEGREE_OF_ACCURACY to 1

the loop would run from the smallest values to the largest values.
 

Ayanami

칼리
Reaction score
288
may I ask what level of education you're in now? (Middle school / high school / college).

i'll try to elaborate... well yeah, if i can remember how to convert parametric to cartesian which i learned last semester.. *EDIT*

Basically, what you need is the Quadratic Bezier Curve.

Equation
2d5e5d58562d8ec2c35f16df98d2b974.png


you'll need the points P0, P1 and P2. and find the values from t=0 to t=1.
it's neat that it's in parametric so you can use them in x-y coords or even x-y-z.

240px-Bezier_2_big.gif

From this, I can see that the curve does not pass through P1 right? Is there a solution if I require the curve to pass through all 3 points?
 

13lade619

is now a game developer :)
Reaction score
398
i think you cant.. why do you want such precision?

i managed to use the function to create effects in a loop, i'm sure you can use it for unit movement.

JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local unit u = gg_unit_Hpal_0000
    
    //origin
    local real p0x = GetUnitX(u)
    local real p0y = GetUnitY(u)
    
    //outer point
    local real p1x = p0x + 700*CosBJ(GetUnitFacing(u)+80)
    local real p1y = p0y + 700*SinBJ(GetUnitFacing(u)+80)
    
    //destination
    local real p2x = p0x + 1000*CosBJ(GetUnitFacing(u))
    local real p2y = p0y + 1000*SinBJ(GetUnitFacing(u))
    
    //parameter
    local real t = 0
    
    
    local real X
    local real Y
    loop
        exitwhen t>1
        
        // B(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
        set X = (((1-t)*(1-t))*p0x)+(2*(1-t)*t*p1x)+(t*t*p2x)
        set Y = (((1-t)*(1-t))*p0y)+(2*(1-t)*t*p1y)+(t*t*p2y)
        
        call DestroyEffect(AddSpecialEffect("units\\nightelf\\Wisp\\Wisp.mdl",X,Y))
        
        // Speed / Frequency of Transition
        set t = t+.05
    endloop
    
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterPlayerKeyEventBJ( gg_trg_Untitled_Trigger_001, Player(0), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_LEFT )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction
 

Attachments

  • untitled.JPG
    untitled.JPG
    32.3 KB · Views: 199

Never_Quit

New Member
Reaction score
16
From this, I can see that the curve does not pass through P1 right? Is there a solution if I require the curve to pass through all 3 points?

You will need to use a parametric equation with distance constants for that.
You solve for your distance constants by putting in the max variables you want.

Btw ^^^ pic up there is neat :)
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
From this, I can see that the curve does not pass through P1 right? Is there a solution if I require the curve to pass through all 3 points?
Sure. Use 2 Bezier curves to go through all 3 points. To make sure the spline stays smooth through the middle point, the midpoints of each curve will have to be generated points equidistant and at opposite angles from the middle point, like so, where the black points are the 3 points being interpolated and the maroon points are the "generated" midpoints of each curve:
bezierexample.png


How you set up those midpoints is arbitrary, but for the curve to be entirely smooth (smoothness to the first degree, that is. Maintaining both curvature smoothness AND directional smoothness on second-degree Bezier splines of arbitrary shape is impossible, but you shouldn't worry about that unless you're running a camera eye tangent to the curve), the two red points must:
1) Be the SAME distance from the middle point.
2) Be extrapolated from the middle point at opposite angles.


Since this leaves much stuff arbitrary, here is an example of some guidelines which should create OK-looking curves under most circumstances:
Let's call the 3 points being interpolated points 1, 3, and 5. The red points will be points 2 and 4. Let's call the angle from point 1 to point 5 "T" and the distance between points 1 and 5 "D". Point 4 will be projected from point 3 by distance D/4 in direction T. Point 2 will be projected from point 3 by distance D/4 in direction T+180.

Damn..
I so have to bookmark this page.
Hardly. So far this is a relatively boring interpolation discussion. If we want to make it more exciting, we can bring up stuff like polynomial interpolation. EG:

Given points (X0,Y0),(X1,Y1),(X2,Y2), to interpolate them on a curve of form Y=Ax^2+Bx+C, you do:
linearalgebra.png


Anyway, that's why we aren't using straight polynomial interpolation, in case anyone was wondering.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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