Calculate curve between two points...

Get help using Construct 2

Post » Mon Jun 24, 2013 5:50 pm

I am looking for an equation to calculate the parabolic curve between two points...or just a nice gradual curve that works would suffice!

Efforts so far have been far from perfect...

I am not using a behavior so just the maths will do...

Thanks.
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,270

Post » Mon Jun 24, 2013 6:40 pm

With just two points all you exactly have defined is a line. You'll need three points to define a curve.

The standard formula for a parabola is the following:
y=a*x^2+b*x+c

Plugging in the x,y positions for the three points into the formula will give you three equations where the only unknowns are a,b and c. Then it's just a matter of using standard algebra to solve for the unknowns.

If that doesn't help, do you have more info about what you're trying to do?

In general the process is called curve fitting:
http://en.wikipedia.org/wiki/Curve_fittingR0J0hound2013-06-24 18:46:22
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Mon Jun 24, 2013 7:22 pm

@rojohound Thanks for the response,Ah the third point is probably what I'm missing...

I am trying to calculate the trajectory of a missile/artillery

I have the projectiles origin x,and the target x,the "ceiling" of the curve may have to be squashed down to keep it in the constraints of the layout,but if that is not possible I could probably work around that..

Your equation may help, however I am unsure how to calculate that third point...

Maths and algebra are not my strong point...

Again thanks...Pixel perfick2013-06-24 19:23:19
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,270

Post » Mon Jun 24, 2013 7:43 pm

There have actually been a few threads about projectile tracking in the past, try using the search tool.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,699

Post » Mon Jun 24, 2013 8:08 pm

@squiddster There is very little on this, that I can find, most involve bullet or physics behaviors ...

But thanks for help...
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,270

Post » Mon Jun 24, 2013 10:58 pm

This topic is relevant:
http://www.scirra.com/forum/parabola-tracjectory-tracing-with-physics-box2d_topic61895_page2.html

But you're right it does use the physics behavior so here is a capx the behavior replaced by four actions:
https://dl.dropboxusercontent.com/u/5426011/examples18/proj_path_no_phys.capx

It has the math worked out so the initial launch angle points somewhere above the target and from that a speed is calculated so the target is reached. It's a sightly different approach than what I outlined before. The initial angle can be anywhere in the range of the angle to the target and straight up.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Tue Jun 25, 2013 3:16 am

@rojohound Thanks for taking the time to help, I really appreciate it...

This pretty much covers exactly what I wanted...

One question though,and apologies as I failed to mention this in my initial post, how would I get the object to fix it's angle to the blue line, like a javelin?

Again many thanks for this...
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,270

Post » Tue Jun 25, 2013 6:13 am

While there are ways to calculate the slope on any point on a parabola I find a simpler method is to save the old position of the objects and set the angle from the old to current position. The event would look like this:

+every tick
set angle to angle(self.old_x, self.old_y, self.x, self.y)
set old_x to self.x
set old_y to self.y

This method has the added benefit that it can be used with any motion.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Tue Jun 25, 2013 12:33 pm

Yup, that makes sense, I was expecting more complex!, but if it works, great, again thanks...
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,270


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests