Transition wavy line

Hello everyone!

I would like to move an object from one point( A ) to another( B ).

But I would like this movement to be curved.

I already found something here: https://forums.coronalabs.com/topic/1573-moving-object-in-a-sine-curve/

This is exactly what I want, however it does not allow you to choose two random points but only horizontal or vertical.

Can you help me find a way to move an object from one point( A ) to another( B ) with the same effect?

You will need to extend that example (the one you linked) to work in both x and y.  Shouldn’t be too tricky.

That’s what I’m trying to do.

There are two difficulties:

_start from A and finish exactly at B

_changing x and y is not simple because the body angle varies according to the rotation of the line

using vector notation… let’s define p1 and p2 as your start/end points, and what you want is pt as a function of scalar t (ie, all the in-between coordinates, as a function of the transition parametric on [0,1]).

first, the straight-line portion:  calc the delta as:  d=p2-p1

then straight-line (lerp) portion is: pt=p1+td

then, the sine-wave portion:  define some scalar function s(t) that returns your sine wave:

s=function(t) return 100*math.sin(t*math.pi*2) end – arbitrary values in italics, alter as desired

you’ll need the line’s oriented frame, calc as:  f=d/|d|

(specifically, you’ll need its perp: f=<-fy,fx>)

finally, add the oriented sin portion to the straight-line portion (as above) to get final answer:

pt=p1+td+s(t)f

I apologize if I delayed answering, I was trying to solve the problem with your tips.

 

But I still can not. 

 

Mathematics is beautiful but I still do not use it to the fullest.

I also searched for instructions on google but nothing …

 

Did you get some code ready?

 

I do not like the handed to, but I really have trouble.

 

Indeed if there was a good math site I would gladly see it

 

I hope not to ask too much…

Every now and then I’ve been trying to put together a math series, but I’ve been in one of the down periods.

That said, although I haven’t given the vector sections much love, I do have crude pictures of the perp as well as adding points and scaled vectors. So davebollinger’s example would be like that second image, except d and  f⊥ instead of v and w , and they would be at right angles to each other (basically they’re “x” and “y”, for a given angle). There’s code if you dig into the source for the figures, but it’s probably pretty obscure.

Hi maximo97.
If you need a refresh on math try searching for “coding math” channel on youtube.

those are great!  a shame the internet is so big that gems like this get lost

here’s a one-minute attempt to codify it, as a “literal” translation – ie, no attempt to make it “pretty” or optimize the (very) redundant calculations:

local function s(t) return 100\*math.sin(t\*math.pi\*2) end local function p(p1x,p1y,p2x,p2y,t) local dx, dy = p2x-p1x, p2y-p1y local m = math.sqrt(dx\*dx+dy\*dy) local fx,fy = dx/m, dy/m return p1x+t\*dx-fy\*s(t), p1y+t\*dy+fx\*s(t) end -- demo display.newLine(100,100, 200,400) for t = 0, 1.0, 0.01 do local ptx, pty = p(100,100, 200,400, t) display.newCircle(ptx,pty,2,2) end

@StarCrunch

Really incredible I like your guide. I will devote some time not being a mother tongue I go slightly slower but it is fantastic!

@Arteficio

I’ll take a look at this too

@davebollinger

thanks again for everything I try to adapt the code to make it better and to move the object on here points

Thanks to all of the support!

@davebollinger @maximo97 Thanks! It’s been a very fitful process assembling it all, especially since I keep realizing I need to back up some of the material. :slight_smile: This is where the “Preliminaries” is at right now; I know roughly what belongs there, but there’s always a lot of inertia to overcome for a first draft. (“Full Circle” is in a slightly different quandary but should go smoothly if I just shake things up a bit.) I’m hopeful the most recent restructuring will be more firm since lines are where Euclid himself took his stand.  :smiley:

You will need to extend that example (the one you linked) to work in both x and y.  Shouldn’t be too tricky.

That’s what I’m trying to do.

There are two difficulties:

_start from A and finish exactly at B

_changing x and y is not simple because the body angle varies according to the rotation of the line

using vector notation… let’s define p1 and p2 as your start/end points, and what you want is pt as a function of scalar t (ie, all the in-between coordinates, as a function of the transition parametric on [0,1]).

first, the straight-line portion:  calc the delta as:  d=p2-p1

then straight-line (lerp) portion is: pt=p1+td

then, the sine-wave portion:  define some scalar function s(t) that returns your sine wave:

s=function(t) return 100*math.sin(t*math.pi*2) end – arbitrary values in italics, alter as desired

you’ll need the line’s oriented frame, calc as:  f=d/|d|

(specifically, you’ll need its perp: f=<-fy,fx>)

finally, add the oriented sin portion to the straight-line portion (as above) to get final answer:

pt=p1+td+s(t)f

I apologize if I delayed answering, I was trying to solve the problem with your tips.

 

But I still can not. 

 

Mathematics is beautiful but I still do not use it to the fullest.

I also searched for instructions on google but nothing …

 

Did you get some code ready?

 

I do not like the handed to, but I really have trouble.

 

Indeed if there was a good math site I would gladly see it

 

I hope not to ask too much…

Every now and then I’ve been trying to put together a math series, but I’ve been in one of the down periods.

That said, although I haven’t given the vector sections much love, I do have crude pictures of the perp as well as adding points and scaled vectors. So davebollinger’s example would be like that second image, except d and  f⊥ instead of v and w , and they would be at right angles to each other (basically they’re “x” and “y”, for a given angle). There’s code if you dig into the source for the figures, but it’s probably pretty obscure.

Hi maximo97.
If you need a refresh on math try searching for “coding math” channel on youtube.

those are great!  a shame the internet is so big that gems like this get lost

here’s a one-minute attempt to codify it, as a “literal” translation – ie, no attempt to make it “pretty” or optimize the (very) redundant calculations:

local function s(t) return 100\*math.sin(t\*math.pi\*2) end local function p(p1x,p1y,p2x,p2y,t) local dx, dy = p2x-p1x, p2y-p1y local m = math.sqrt(dx\*dx+dy\*dy) local fx,fy = dx/m, dy/m return p1x+t\*dx-fy\*s(t), p1y+t\*dy+fx\*s(t) end -- demo display.newLine(100,100, 200,400) for t = 0, 1.0, 0.01 do local ptx, pty = p(100,100, 200,400, t) display.newCircle(ptx,pty,2,2) end

@StarCrunch

Really incredible I like your guide. I will devote some time not being a mother tongue I go slightly slower but it is fantastic!

@Arteficio

I’ll take a look at this too

@davebollinger

thanks again for everything I try to adapt the code to make it better and to move the object on here points

Thanks to all of the support!