I'm trying to figure how to make ellptical motion in following path:

I've uploaded a .capx here, but it does circular motion, not ellitpical with offset, I'm looking a solution, thanks!

8 posts
• Page **1** of **1**

I'm trying to figure how to make ellptical motion in following path:

I've uploaded a .capx here, but it does circular motion, not ellitpical with offset, I'm looking a solution, thanks!

I've uploaded a .capx here, but it does circular motion, not ellitpical with offset, I'm looking a solution, thanks!

You do not have the required permissions to view the files attached to this post.

Last edited by Joannesalfa on Mon Feb 16, 2015 12:24 am, edited 1 time in total.

**Posts:**3,139**Reputation:**28,236

B

96
S

34
G

29
Like this? I'm still on r195 I'll need to upgrade

https://dl.dropboxusercontent.com/u/139 ... cle_e.capx

https://dl.dropboxusercontent.com/u/139 ... cle_e.capx

**Posts:**202**Reputation:**1,545

B

10
S

2
G

1
i think you could make it using standard "circular" motion with sin and cos and little switch. When object is on top just move it forward and after some time turn on circular motion. After reaching bottom turn it off and let it go forward. Then turn it on again etc.

**Posts:**2,589**Reputation:**34,613

B

156
S

64
G

41
**Posts:**8,178**Reputation:**103,452

B

167
S

50
G

160
Attached is a exact way to do a rounded path like the op.

You can think of each piece of the path like a lerp from one point to another.

left side:

x = center.x - space/2 + radius*cos(90+180*t)

y = center.y + radius*sin(90+180*t)

top:

x = center.x + 0.5*space*lerp(-1,1, t)

y = center.y - radius

right side:

x = center.x + space/2 + radius*cos(-90+180*t)

y = center.y + radius*sin(-90+180*t)

bottom:

x = center.x + 0.5*space*lerp(1,-1, t)

y = center.y + radius

where t is a number from 0 to 1.

Now all that needs to be done is depending on the distance traveled choose the correct equations and t value.

We first start with the distance traveled:

distance = speed * time

Next we need to know the lengths of the pieces.

The top and bottom are easy with a length of "space".

The left and right can be found with the following equation:

arc length = radius * (angle in radians)

Which ends up as pi*radius for each.

With the above the total length = 2*pi*radius+2*space

To choose the correct equations we compare the distance traveled,

0 to pi*radius is the left side.

pi*radius to pi*radius+space is the top.

pi*radius+space to 2*pi*radius+space is the right.

2*pi*radius+space to 2*pi*radius+2*space is the bottom.

Then we find a t (0..1) value for the side with:

If left then t = distance/pi*radius

If top then t = (distance-pi*radius)/space

If right then t = (distance-pi*radius+space)/(pi*radius)

If bottom then t = (distance-2*pi*radius+space)/space

As a final step we want it to loop so we can use the % operator with the total length to do that.

distance = (speed*time)%(2*pi*radius+2*space)

If speed is negative then we need to do effectively this:

((a%b)+b)%b

In the capx I used a function for that.

- Code: Select all
`* |* * * * * *| *`

* | | *

* | o | *

* | | *

* | | *

* |* * * * * *| *

| |\ |

+-----+ +--------------+

radius space

You can think of each piece of the path like a lerp from one point to another.

left side:

x = center.x - space/2 + radius*cos(90+180*t)

y = center.y + radius*sin(90+180*t)

top:

x = center.x + 0.5*space*lerp(-1,1, t)

y = center.y - radius

right side:

x = center.x + space/2 + radius*cos(-90+180*t)

y = center.y + radius*sin(-90+180*t)

bottom:

x = center.x + 0.5*space*lerp(1,-1, t)

y = center.y + radius

where t is a number from 0 to 1.

Now all that needs to be done is depending on the distance traveled choose the correct equations and t value.

We first start with the distance traveled:

distance = speed * time

Next we need to know the lengths of the pieces.

The top and bottom are easy with a length of "space".

The left and right can be found with the following equation:

arc length = radius * (angle in radians)

Which ends up as pi*radius for each.

With the above the total length = 2*pi*radius+2*space

To choose the correct equations we compare the distance traveled,

0 to pi*radius is the left side.

pi*radius to pi*radius+space is the top.

pi*radius+space to 2*pi*radius+space is the right.

2*pi*radius+space to 2*pi*radius+2*space is the bottom.

Then we find a t (0..1) value for the side with:

If left then t = distance/pi*radius

If top then t = (distance-pi*radius)/space

If right then t = (distance-pi*radius+space)/(pi*radius)

If bottom then t = (distance-2*pi*radius+space)/space

As a final step we want it to loop so we can use the % operator with the total length to do that.

distance = (speed*time)%(2*pi*radius+2*space)

If speed is negative then we need to do effectively this:

((a%b)+b)%b

In the capx I used a function for that.

You do not have the required permissions to view the files attached to this post.

**Posts:**5,199**Reputation:**65,684

B

91
S

31
G

99
**Posts:**3,139**Reputation:**28,236

B

96
S

34
G

29
8 posts
• Page **1** of **1**