When velocity becomes 0 and how to recalculate acceleration for final position can be whole number by rounding off? [closed] - algorithm

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
Position P is start with 7.56m and velocity V is 6(m/s). Acceleration A is -2 (m/s): How to get P when V becomes 0 and how to recalculate acceleration A for final P can be whole number by rounding off?

use equations of motion.
v2 = u2 + 2as
here,
v=0, u=6m/s and a=-2m/s2
So,
s = 9m
So, final position will be 7.56 + 9 = 16.56m
and since acceleration does not change, final acceleration = initial acceleration = -2m/s2
EDIT:
In that case, again use the same equation. Changed values will be:
v=0, u=6, s=9.44
So,
a = -1.907m/s2

Related

Holding a max value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I need to code a function with two inputs (x,Tau). Let's suppose that the vector is a simple x=sin(t). The function must detect the local maximum. If a local max is spotted, it should deteriorate from there with the exp(-t/Tau) until the sin(x) is greater again. From there, the x should be followed until the next local max. It is a kind of a low pass filter, but I cannot code it properly in Octave.
Here is a sample picture drawn by hand:
This question is more mathematics than computing. The following solution will work when your first curve is a smooth function, but I'm not sure how well it would work if your input is a set of experimentally measured values with a high degree of scatter. In that case you might need something more sophisticated.
I assume you want to make the decay curve deviate from the underlying curve not at the maximum but at the point slightly past the maximum where the downward slope of the underlying curve first exceeds that of exponential decay with time constant tau. This seems like a much more physical situation. Switching to exponential decay at the literal maximum could/would result in the decay curve actually crossing the underlying curve.
If your 'sine' function is x(t), and if the decay constant is tau, then you need a new symbol for the red curve in your graph. Call this y(t). Representing the time axis by a vector of numbers t = [t(1), t(2), ..., t(n)] and the corresponding values of your 'sine' function by a vector x = [x(1), x(2), ..., x(n)] and setting y(1) = x(1), then the (i > 1)th member of the vector y is given by max(x(i), y(i-1) exp(-(t(i) - t(i-1))/tau)).
Implementing this in Octave is straightforward:
clear
t = linspace(0, 6*pi, 1000); %Or whatever
x = sin(t); %Could be any function
function y = decay(x, t, tau)
y = zeros(1, length(t));
y(1) = x(1);
for i = 2:length(t)
y(i) = max(x(i), y(i-1)*exp(-(t(i)-t(i-1))/tau));
endfor
endfunction
tau = 10;
y = decay(x, t, tau);
clf
hold on
plot(t, x)
plot(t, y)
hold off
If you want to use the above function regularly it would probably be a good idea to add checks to make sure that the correct number of arguments are passed, that x and t are the same length and that tau is a scalar.

how to calculate shortest distance between two moving objects [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
the question is simple one object is moving from east-west with a velocity of v1 and another from south-north with velocity v2.
I just need the algorithm(formula) to calculate the shortest distance between them so I can write a program for it.
I do have distance between them and the meting point of their paths they are d1 and d2.
Assuming you are asking for 2-d space, at t=0, let the starting points be (d1,0) and (0,d2) on the coordinate axes. We can assume this because one object is always moving horizontally (E-W direction, along X-axis) and other vertically (S-N direction, along Y-axis). Now, after some time t, their positions will be,(d1-t*v1) and (0,d2-t*v2). (Speed-Distance-Time relation).
Now, distance between them at this time t will be,
D = d^2 = (d1-t*v1)^2 + (d2-t*v2)^2
So, differentiating both sides wrt t,
dD/dt = 2(-v1)(d1-t*v1) + 2(-v2)(d2-t*v2) ....(1)
For D to be minimum, dD/dt = 0 and second differential must be positive. Now, second differential :
d2D/dt2 = 2*v1^2 + 2*v2^2 which is positive for all real v1/v2. So, if `dD/dt = 0`, distance will be minimum.
So, equating (1) = 0, we get
t = (d1v1 + d2v2)/(v1^2 + v2^2)
So, get sqrt(D) at t = --above value-- and that shall be your answer.
PS: ask these type of questions on mathematics stackexchange.

Gnuplot: how to plot max and /or min value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How can I show the max. and/or the min. value(s) of of a graph in a plot at their appropriate position automatically?
You can do this "semi-automatically" using the stats command. This command can extract some statistical values from a data set, but requires some reworking:
Extract the minimum and maximum y-values, assuming that your data file has two columns, the x-value in the first, the y-values in the second column
stats 'file.dat' using 2 nooutput name 'Y_'
This gives you the min/max y-values in the variables Y_min and Y_max, but not the corresponding x-value.
The previous step gives you only get the respective indices, which requires you to run stats again in order to get the x-values:
stats 'file.dat' using 1 every ::Y_index_min::Y_index_min nooutput
X_min = STATS_min
stats 'file.dat' using 1 every ::Y_index_max::Y_index_max nooutput
X_max = STATS_max
Set labels and/or points at the respective coordinates
set label 1 sprintf("%.2f", Y_min) center at first X_min,Y_min point pt 7 ps 1 offset 0,-1.5
set label 2 sprintf("%.2f", Y_max) center at first X_max,Y_max point pt 7 ps 1 offset 0,1.5
...
plot ...

Cocos2d Sprite Movement Speed [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a class which creates a sprite at a random point on the screen, this sprite then moves to the center of the screen.
How can I make it so that it always travels at the same speed?
obviously
CCMoveTo* move = [CCMoveTo actionWithDuration:5 position: ccp(screenWidth/2, screenHeight/2)];
Will always mean the duration is 5 seconds regardless of the distance. But I want the speed to be constant if its travelling 50 pixels or 500 pixels.
Any Help much appreciated
Calculate the duration from the distance to the center.
duration = distance / rate;
Say that moving 50 pixels in 5 seconds is okay. Then your rate is 10 pixels/second.
rate = 10;
If your sprite is at (x,y) then distance is by the pythagorean theorem
dx = x - screenWidth / 2;
dy = y - screenHeight / 2;
distance = sqrt(dx * dx + dy * dy);

Algorithmical issue with point inside circle [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I have a question [ silly - I admit ] about finding wherether the point is in the circle or not, I have a coordinates of the center of circle, and I know the equation, but I'm having the problem with radius, let say it is 2 km, so I have x:46.123654 y: 15.789456 and r=2 or 200 or 2000? What should be the value of R?
For clarity, the units of r should almost certainly be the same as the units of x and y. If, for instance x = 46.123654 means 46.123654 meters, and the radius of your circle is two kilometers, then the value of r should be 2000.0, meaning two thousand meters. You should also be explicit in some comment about what the units are, i.e. x = 46.123654 //meters. If the units are the same, you can apply formulas without confusing conversions, for instance:
//determines whether a point (x, y) is in the circle of radius r centered at (0, 0)
bool isInCircle(double x, double y, double r)
{
return x * x + y * y <= r * r; //pythagorian theorem!
}
This isn't really programming, just middle-school math and common sense.

Resources