need major math help!

Hi Community,

I am trying to simulate a cannon ball movement without physics in an isometric view. I don’t think I need physics, with gravity and all because I don’t need the movement to be realistic really, as long as it is parabolic it’s already enough. I have been going at this for at least 3 days straight now.

I think I am close to solving it, here have a look: http://screencast.com/t/e0pDLb88vejy , this works perfectly!

but everything starts breaking down when I change to different quadrants, the example above is on the second quadrant (where x is negative and y is positive)
Here it is in the first quadrant (where x and y are positive): http://screencast.com/t/7O7XfisdZY

Below is the code for the movement:
[lua] local start_x, start_y, end_x, end_y = 5, 5 --location of the tower/cannon
local end_x, end_y = 80, 50 --the target
local circle = display.newCircle(start_x, start_y, 5)
–vertex is basically the location of the tower but slightly higher (cannon shoots up)
local vertex_x, vertex_y = (start_x + end_x) / 2, start_y - 20

–[[
function to find the a,b,c for the quadratic formula
]]
local function interpol(start_x, start_y, vertex_x, vertex_y, end_x, end_y)
local x1, x2, x3 = start_x, vertex_x , end_x
local y1, y2, y3 = start_y, vertex_y , end_y

local d23 = x2 - x3
local d31 = x3 - x1
local d12 = x1-x2

local s23 = x2 + x3
local s31 = x3 + x1
local s12 = x1 + x2

local p23 = x2 * x3
local p31 = x3 * x1
local p12 = x1 * x2

local dy1 = d23 * y1
local dy2 = d31 * y2
local dy3 = d12 * y3

local pid = d23 * d31 * d12

local a = -( dy1 + dy2 + dy3 ) / pid
local b = ( (s23 * dy1) + (s31 * dy2) + (s12 * dy3) ) / pid
local c = -( (p23 * dy1) + (p31 * dy2) + (p12 * dy3) ) / pid
return a,b,c
end

local a,b,c = interpol(start_x, start_y, vertex_x, vertex_y, end_x, end_y)–got the a,b,c out of the 3 points
print(a,b,c)
local x, y = start_x, 0
local last_time = 0
local increment_x = 0.1
local direction = 1

if start_x > end_x then–because of different quadrants i need this
direction = -1
end

local function move(event)
if event.time - last_time < 5 then
return
end

y = (a * x^2) - (b * x) - c --quadratic formula to get the y coordinate
increment_x = increment_x + 0.3–increments so it goes faster (simulating gravity)
x = x + increment_x --move the x along
circle.x, circle.y = x * direction , y

last_time = event.time
end

local start = display.newCircle(start_x, start_y, 3)
local target = display.newCircle(end_x, end_y, 3)
local vertex = display.newCircle(vertex_x, vertex_y, 3)
vertex:setFillColor(10,10,200)
target:setFillColor(255,255, 0)
Runtime:addEventListener(‘enterFrame’, move)[/lua]

[import]uid: 11334 topic_id: 5127 reply_id: 305127[/import]

the interpol function is OK
interpol(0,1,1,3,2,7) returns 1,1,1 which is correct, because x^2+x+1 passes through the points (0,1),(1,3),(2,7)

for x=1.5, y=x^2-x-1=-0.25 instead of the correct y=x^2+x+1=4.75
try y=a*x^2+b*x+c instead of y=a*x^2-b*x-c

however, no matter what the value of y will be, according to the move function circle.x will always be negative and decreasing (for direction=-1)

[import]uid: 6459 topic_id: 5127 reply_id: 17135[/import]

Tetu
I am rather lost, so what am I supposed to be changing?
the constant b to negative? Or the direction too? [import]uid: 11334 topic_id: 5127 reply_id: 17214[/import]

y = a * x^2 +b * x+ c

x = x + direction*increment_x
circle.x, circle.y = x , y
[import]uid: 6459 topic_id: 5127 reply_id: 17257[/import]