Math smoothing position of two objects
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am search a math formula to solve this problem, preferably in C#
- A object should be to near smooth an other object and stop if reached the position of the destination object.
- The destination object can change the position before the second object reach and yet the moving is smooting again if possible.
- I need a min and max acceleration config
code example without smoothing
var x1 = 100;
var x2 = 50;
while (x1 >= x2)
x2++;
update example base on the answer of vadim123
var minimum = 0.5;
var maximum = 5.0;
var frac = 1 / 20.0;
var x1 = 100.0;
var x2 = 50.0;
while (x1 >= x2)
x2 = x2 + Math.Min(maximum, Math.Max(minimum, (x1 - x2) * frac));
functions
add a comment |Â
up vote
1
down vote
favorite
I am search a math formula to solve this problem, preferably in C#
- A object should be to near smooth an other object and stop if reached the position of the destination object.
- The destination object can change the position before the second object reach and yet the moving is smooting again if possible.
- I need a min and max acceleration config
code example without smoothing
var x1 = 100;
var x2 = 50;
while (x1 >= x2)
x2++;
update example base on the answer of vadim123
var minimum = 0.5;
var maximum = 5.0;
var frac = 1 / 20.0;
var x1 = 100.0;
var x2 = 50.0;
while (x1 >= x2)
x2 = x2 + Math.Min(maximum, Math.Max(minimum, (x1 - x2) * frac));
functions
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am search a math formula to solve this problem, preferably in C#
- A object should be to near smooth an other object and stop if reached the position of the destination object.
- The destination object can change the position before the second object reach and yet the moving is smooting again if possible.
- I need a min and max acceleration config
code example without smoothing
var x1 = 100;
var x2 = 50;
while (x1 >= x2)
x2++;
update example base on the answer of vadim123
var minimum = 0.5;
var maximum = 5.0;
var frac = 1 / 20.0;
var x1 = 100.0;
var x2 = 50.0;
while (x1 >= x2)
x2 = x2 + Math.Min(maximum, Math.Max(minimum, (x1 - x2) * frac));
functions
I am search a math formula to solve this problem, preferably in C#
- A object should be to near smooth an other object and stop if reached the position of the destination object.
- The destination object can change the position before the second object reach and yet the moving is smooting again if possible.
- I need a min and max acceleration config
code example without smoothing
var x1 = 100;
var x2 = 50;
while (x1 >= x2)
x2++;
update example base on the answer of vadim123
var minimum = 0.5;
var maximum = 5.0;
var frac = 1 / 20.0;
var x1 = 100.0;
var x2 = 50.0;
while (x1 >= x2)
x2 = x2 + Math.Min(maximum, Math.Max(minimum, (x1 - x2) * frac));
functions
edited Aug 7 at 18:56
asked Aug 7 at 18:34
Tom Baires
83
83
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
I don't know C#, but here is some pseudocode. Let $MIN_V$ and $MAX_V$ be the minimum and maximum velocity, respectively. Let $FRAC$ be a smoothing coefficient, between $0$ and $1$, to be chosen for desired level of smoothing.
$$x2 = x2 + min(MAX_V, max(MIN_V, (x1-x2)*FRAC ))$$
Explanation: We will add $(x1-x2)*FRAC$ to $x1$ at each time step; if $FRAC=1/3$, then we will close one third of the distance at each time step. However, this is clipped to be within the max and min velocity. Without clipping, we go too fast at the start, and very very slow at the end (never arriving).
If you really want max and min acceleration (not velocity), the problem is impossible to solve exactly -- a plan to approach $x2$ at maximal speed, slowing down as fast as possible, could be ruined by $x2$ suddenly coming closer.
How i can start slow and increase the speed to the end?
â Tom Baires
Aug 7 at 18:57
Don't you want to start fast and decrease the speed as they get closer?
â user1949350
Aug 7 at 19:13
@user1949350 i want start and stop slow and the time between fast.
â Tom Baires
Aug 7 at 19:31
If you increase FRAC, you will increase speed.
â vadim123
Aug 7 at 19:57
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I don't know C#, but here is some pseudocode. Let $MIN_V$ and $MAX_V$ be the minimum and maximum velocity, respectively. Let $FRAC$ be a smoothing coefficient, between $0$ and $1$, to be chosen for desired level of smoothing.
$$x2 = x2 + min(MAX_V, max(MIN_V, (x1-x2)*FRAC ))$$
Explanation: We will add $(x1-x2)*FRAC$ to $x1$ at each time step; if $FRAC=1/3$, then we will close one third of the distance at each time step. However, this is clipped to be within the max and min velocity. Without clipping, we go too fast at the start, and very very slow at the end (never arriving).
If you really want max and min acceleration (not velocity), the problem is impossible to solve exactly -- a plan to approach $x2$ at maximal speed, slowing down as fast as possible, could be ruined by $x2$ suddenly coming closer.
How i can start slow and increase the speed to the end?
â Tom Baires
Aug 7 at 18:57
Don't you want to start fast and decrease the speed as they get closer?
â user1949350
Aug 7 at 19:13
@user1949350 i want start and stop slow and the time between fast.
â Tom Baires
Aug 7 at 19:31
If you increase FRAC, you will increase speed.
â vadim123
Aug 7 at 19:57
add a comment |Â
up vote
0
down vote
accepted
I don't know C#, but here is some pseudocode. Let $MIN_V$ and $MAX_V$ be the minimum and maximum velocity, respectively. Let $FRAC$ be a smoothing coefficient, between $0$ and $1$, to be chosen for desired level of smoothing.
$$x2 = x2 + min(MAX_V, max(MIN_V, (x1-x2)*FRAC ))$$
Explanation: We will add $(x1-x2)*FRAC$ to $x1$ at each time step; if $FRAC=1/3$, then we will close one third of the distance at each time step. However, this is clipped to be within the max and min velocity. Without clipping, we go too fast at the start, and very very slow at the end (never arriving).
If you really want max and min acceleration (not velocity), the problem is impossible to solve exactly -- a plan to approach $x2$ at maximal speed, slowing down as fast as possible, could be ruined by $x2$ suddenly coming closer.
How i can start slow and increase the speed to the end?
â Tom Baires
Aug 7 at 18:57
Don't you want to start fast and decrease the speed as they get closer?
â user1949350
Aug 7 at 19:13
@user1949350 i want start and stop slow and the time between fast.
â Tom Baires
Aug 7 at 19:31
If you increase FRAC, you will increase speed.
â vadim123
Aug 7 at 19:57
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I don't know C#, but here is some pseudocode. Let $MIN_V$ and $MAX_V$ be the minimum and maximum velocity, respectively. Let $FRAC$ be a smoothing coefficient, between $0$ and $1$, to be chosen for desired level of smoothing.
$$x2 = x2 + min(MAX_V, max(MIN_V, (x1-x2)*FRAC ))$$
Explanation: We will add $(x1-x2)*FRAC$ to $x1$ at each time step; if $FRAC=1/3$, then we will close one third of the distance at each time step. However, this is clipped to be within the max and min velocity. Without clipping, we go too fast at the start, and very very slow at the end (never arriving).
If you really want max and min acceleration (not velocity), the problem is impossible to solve exactly -- a plan to approach $x2$ at maximal speed, slowing down as fast as possible, could be ruined by $x2$ suddenly coming closer.
I don't know C#, but here is some pseudocode. Let $MIN_V$ and $MAX_V$ be the minimum and maximum velocity, respectively. Let $FRAC$ be a smoothing coefficient, between $0$ and $1$, to be chosen for desired level of smoothing.
$$x2 = x2 + min(MAX_V, max(MIN_V, (x1-x2)*FRAC ))$$
Explanation: We will add $(x1-x2)*FRAC$ to $x1$ at each time step; if $FRAC=1/3$, then we will close one third of the distance at each time step. However, this is clipped to be within the max and min velocity. Without clipping, we go too fast at the start, and very very slow at the end (never arriving).
If you really want max and min acceleration (not velocity), the problem is impossible to solve exactly -- a plan to approach $x2$ at maximal speed, slowing down as fast as possible, could be ruined by $x2$ suddenly coming closer.
answered Aug 7 at 18:41
vadim123
73.8k895184
73.8k895184
How i can start slow and increase the speed to the end?
â Tom Baires
Aug 7 at 18:57
Don't you want to start fast and decrease the speed as they get closer?
â user1949350
Aug 7 at 19:13
@user1949350 i want start and stop slow and the time between fast.
â Tom Baires
Aug 7 at 19:31
If you increase FRAC, you will increase speed.
â vadim123
Aug 7 at 19:57
add a comment |Â
How i can start slow and increase the speed to the end?
â Tom Baires
Aug 7 at 18:57
Don't you want to start fast and decrease the speed as they get closer?
â user1949350
Aug 7 at 19:13
@user1949350 i want start and stop slow and the time between fast.
â Tom Baires
Aug 7 at 19:31
If you increase FRAC, you will increase speed.
â vadim123
Aug 7 at 19:57
How i can start slow and increase the speed to the end?
â Tom Baires
Aug 7 at 18:57
How i can start slow and increase the speed to the end?
â Tom Baires
Aug 7 at 18:57
Don't you want to start fast and decrease the speed as they get closer?
â user1949350
Aug 7 at 19:13
Don't you want to start fast and decrease the speed as they get closer?
â user1949350
Aug 7 at 19:13
@user1949350 i want start and stop slow and the time between fast.
â Tom Baires
Aug 7 at 19:31
@user1949350 i want start and stop slow and the time between fast.
â Tom Baires
Aug 7 at 19:31
If you increase FRAC, you will increase speed.
â vadim123
Aug 7 at 19:57
If you increase FRAC, you will increase speed.
â vadim123
Aug 7 at 19:57
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2875251%2fmath-smoothing-position-of-two-objects%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password