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);
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 days ago.
Improve this question
This question might sound a little bit broad, but how can I estimate the clarity of a rgb color?
I'm trying to create a function f(rgb) that returns 0 if the rgb is black (0,0,0), 1 if it is white (1,1,1) and something in between for other rgb colors.
What I'm trying is this:
f(rgb) = min(rgb) + c1r + c2g + c3b
First I take the minimum value of the rgb channels, then I add it with the products between each channel and a predefined constant.
Example: rgb = (0.4, 0.8, 0.5)
f(rgb) = min(0.4, 0.8, 0.5) + 0.4 c1 + 0.8 c2 + 0.5 c3
f(rgb) = 0.4 + 0.4 c1 + 0.8 c2 + 0.5 c3
But obviously I don't know the values of the constants, I would have to test them manually.
This is why I'm asking if there is a way already.
Got an idea: convert the color to grayscale.
Here I could find an algorithm that does that:
f(rgb) = 0.299r + 0.587g + 0.114b
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
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.
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.
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
(This question could be better off on math, but im not sure)
http://i.imgur.com/TVINP.png
This is probably very simple but the way I'm thinking of doing it doesn't seem very easy and there must be a simpler method.I've got an image and I want to find some points that fall on a line so in this example image below the starting point of my line is (39,75) and the ending point is (75,142) from there I want to find 5 points (or any number really 5 is just an example) that are all on that line.
Is there some equation I can use that will get me a certain amount of points given any start and end coordinates?
yes.
suppose (x0,y0) and (x1,y1) are the starting and ending points on the line.
t*(x0,y0) + (t-1)*(x1,y1) are also going to be points on that line where t ranges from 0 to 1.
note:
if t = 0, you get (x0,y0)
if t = 1, you get (x1,y1)
if t is any value inside (0,1) you get that "percentage" of the way from (x0,y0) to (x1,y1)
(if t = 0.5, you are halfway between the points)
this is what is often called "tweening" in computer graphics
Yes. Your line segment can be described by this equation:
x = 39 + t * (75 - 39)
y = 75 + t * (142 - 75)
where, t can take on any value between 0 and 1.
So, to get random points on the line, just choose a random value for t (between 0 and 1), and calculate what x, y are.
The idea is, x is traveling from 39 to 75, while y is traveling from 75 to 142, and t represents the fraction of travel that has been completed.
A line can be defined by the function y = mx + b where x and y are coordinates on the cartesian plane, m is the slope of the line defined by (y2 - y1)/(x2 - x1), and b is the point where the line intersects the y-axis.
Given that information and two points on the line, you can fill in the blanks with some basic algebra to determine a function that defines the line. Note that if your coordinate plane for the image places (0, 0) in the top left corner, you may have to flip the sign of the y-coordinate.