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
At X minutes (say 360 mins) angle of gameobject is 0 degrees.
At Y minutes (say 1200 mins) angle of gameobject should reach 180
degrees.
My question is, what is the angle for each minute (X -> Y), so the gameobject updates its rotation based on the angle from the result, each minute.
Thanks in advance
I think it is not that difficult. You can easily find the distribution. Lets take actual duration which is 1200 - 360 = 840.
Actually the maths you can apply for such kind of problems is like,
X * 840 = 180
X will be the value which will multiplied 840 times to get the value of 180.
X = 180/840 => X = 0.214285
That'd be the per minute degree change in order to get 180 degrees in 840 minutes.
So you'd change the angle by 0.214285 degrees per minute in order to get it. :)
Similarly apply the same formula for any duration like, from 1000 to 1200, you can do it as,
1200-1000 = 200
180/200 = 0.9
So the new change in angle required per minute is 0.9.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
So I'm trying to make an animation of 2 objects orbiting around one object that we will call the sun. The distance from object 1 to the sun is 2 units and that has a constant angle at which it turns and moves on.
I assume that the farther away from the sun it is the smaller the angle so the bigger the circle, but how would you calculate this angle depending on the distance? Here is a picture:
So let's just talk about how to calculate the X, Y coordinates of an object moving around the origin at a constant distance D and with angular velocity W (angular velocity is the number of degrees per second).
The angle Q that our object will make with the ray beginning at the origin and pointed at the positive X-axis is given by Q(t) = Q0 + Wt, where Q0 is the angle the object makes at time t = 0 (the initial condition). If we assume that the object begins immediately to the right of the origin, Q0 = 0, for instance.
The X, Y coordinates of the object at time t can be found using trigonometry on Q(t):
X(t) = D * cos(Q(t)) = D * cos(Q0 + Wt)
Y(t) = D * sin(Q(t)) = D * sin(Q0 + Wt)
If you have two objects at different distances from the origin/sun, then for the same angular velocity W, the object closer to the origin/sun will move with a slower speed than the one farther away. This is because to move the same number of degrees around a larger circle, the object farther away has longer actual distance to go in the same time. Assuming that the angular velocity is being measured in degrees per second, the object's speed in D's distance units per second can be found as follows:
V = (angular velocity / 360 degrees) * (circumference of circle)
= (W/360) * (2*PI*D)
= 2*PI*D*W/180
So, if you wanted V to be constant rather than W, you could solve this for W in terms of your desired V and D.
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 4 years ago.
Improve this question
I'm working on a missile command like game for an arduboy.
The Bombs fall from the top of the screen Y = 0 and hit the "ground" at Y = 63. The bombs come in at angles, so I can calculate it with a bit of trig:
BombX = initialBombX - bombDistanceTraveled * cos(bombTheta)
BombY = 0 - bombDistanceTraveled * sin(bombTheta)
This works great, but I want to randomize the Theta. However, I want the bomb to always hit the "ground" (y = 63) before it goes off screen (x < 0 or x > 128).
See this drawing for a visual (White lines = good, Red Lines = bad)
Could someone help me come up with an equation to limit the theta with the constraints:
Initial X will be between 0 and 128
Initial Y will always be 0
if Y <= 63 Then X > 0 && X < 128
Thank You!
Simple trigonometry:
tan(theta) = x/y
so theta must be between
-arctan(x/63)
and
arctan((128-x)/63)
for an arbitrarily chosen x between 0 and 128, assuming that straight downward is theta=0
Probably you can simplify things a bit. Sine and cosine calculation may appear slow, so we can initially randomize x start coordinate, as well as x approaching coordinate. Then:
xDelta = approachX - initialX;
bombX = initialX + ((( bombY + 1 ) * xDelta ) >> 6);
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 5 years ago.
Improve this question
I believe this is a simple question.
Given I have a rectangle rotated 45 deg, what would be the correct method to calculate the distance of the blue line shown in the image?
It doesn't need to be language specific. Just interested to know in what is the arithmetic I should follow.
If your rectangle is rotated 45 degrees, then your distance is simply 1/sqrt(2) times 600px.
This is given by
a^2 + b^2 = c^2
Where a = b and is your blue line. C is simply 600 px. Simple algebra yealds:
2a^2 = c^2
sqrt(2)*a = c
a = c * 1/sqrt(2)
On the other side it would be 350 times 1/sqrt(2). Note this only applies to a rectangle rotated 45 degrees.
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 8 months ago.
Improve this question
Given (x,y) that is (3,4) , velocity is 1 m/sec and given angle is 15 degree. what will be next coordinate (x', y') after 1 sec ?
Anyone please help!
Assuming the angle is measure w.r.t. the x-axis, then:
the total distance is v*t = 1m
displacement in x-direction: cos(15)*1m=.97m
displacement in y-direction: sin(15)*1m=.25m
So the new location is (3.97, 4.25).
#Alexander-Vogt's answer is close but I think it is missing a conversion from angles to radians. Here is matlab code that provides the answer:
pi=3.1415926535897932384626433832795028841971;
x=3;y=4;
t=1; % time
s=1*t; % speed * time
a=15; % angle of movement
a=a/360 * pi*2; % convert to radians
x=cos(a)*s+x;
y=sin(a)*s+y;
fprintf("%f %f\n",x,y);
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
For a particle moving about in a Cartesian coordinate system (neglecting the z-axis), how can the angle of travel be computed given the x and y components of the velocity?
Before anyone says this isn't programming related, I am programming this right now, however, I don't know vector math.
For example, suppose the x and y values of the velocity are respectively 5.0 and -1.5, how would I compute the angle?
In Javascript, I'd use Math.atan2(1.5, 5.0). To convert to degrees, use Math.atan2(1.5, 5.0)/(Math.PI/180). On Wikipedia: http://en.wikipedia.org/wiki/Atan2
You need atan2:
For any real arguments x and y not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it.
The angle in radians from the x-axis is given by:
arctan(vy / vx); // vx > 0
You also need to handle the case vx < 0.
If you want the bearing versus true north, then you might want:
double bearing = 90 - arctan(vy / vx) * 360 / 2 / M_PI;
The angle is the arctangent of y / x. Many languages have a 4-quadrant arctangent function in the math library that takes x and y arguments.
You have to be careful about what the angles are between. Arctangent, atan(y / x), will give you the angle relative to the positive x-axis, but make sure that's what you need.
The arc-tangent of the slope will give you what you want.