What is wrong with following piece of code
import math
n = input ()
l = int(round((n*180)/math.pi))
print l
Gives wrong answer.
if n = 0.707106781187, then it gives l = 41. It should be 45.
I think you mixed up degrees and gradians. A corner of 45 gradians is equal to about 41 degrees, a corner of 50 gradians is exactly 45 degrees. The program itself is correct. The entered input value for 45 degrees should be 0.785398, which is pi divided by 4.
More about degrees, radians and gradians can be found here:
https://en.wikipedia.org/wiki/Gradian
Related
Here is a matrix:
A = reshape(collect(1:81), (9, 9))
How may I rotate this matrix in +/- radians/degrees?
Lets say I wish to do a 45 degree rotation
I guess imagine all the 1's in the middle lining up at a 45 degree angle...
Any packages to recommend?
This code is supposed to calculate and return the real part of a complex number with magnitude a and angle b in degrees. It gives me wrong numbers.
x = (a*(cos(b*(180/pi))));
This however, gives me the right numbers if the angle is given in radians.
x = (a*(cos(b)));
pi is defined as const double pi = 3.142
Any thoughts? I cannot see why the x should be wrong in the first but correct in the second example.
Since 180 degrees is 1 pi radian. The formula for degrees to radians should be
radian = (degree / 180) pi.
Thus the first formula should be
x = (a*(cos((b / 180)*pi))));
You have the conversion backwards: your formula changes b from radians to degrees before calculating its cosine. But you want to convert from degress to radians. The correct formula is
x = (a*(cos(b*(pi/180)));
though you could use fewer parentheses and use more spacing:
x = a * cos(b * pi / 180);
You are not using formula correctly
this can be written as:
x = (a*cos((b * pi)/180));
in this question- a motorboat is racing towards north at 25 km/hr and the water current in that region is 10 km/hr in a direction 60 degrees east of south. find the resultant velocity and direction of resultant velocity of the boat.
For getting the velocity i just used the cosin formula and got 22 km/hr approx but i cant seem to understand how to calculate the direction when the angle between the vectors is 120. it is easy when the angle is less that or equal to 90 when we just find tan theta where theta is the angle between the vectors. but how do we go about doing this?
The velocity is as actually a vector with a direction. If you sketch this you will have a vector addition (build a parallelogram) of The boats speed vector and the water flows speed vector. The directions of the vectors you can extract from the given direction. For example take north as (1,0) direction and draw an arrow in the correct length (speed).
v_boat = 25 * (1,0)
v_flow = 10 * ...
v_sum = v_boat + v_flow
v_sum_magnitude = magnitude of v_sum
For the background:
Velocity is working with the principle of superposition.
I'm using google calculator for an equation. The number sixty is a degree.
If I put it in like this, I get:
80 * cos(60) = -76.1930384
But if I put the word 'degrees' I get this:
80 * cos(60degrees) = 40
Which one is the right answer?
If you do not specify it to be actual degrees, it will assume it is in PI. Once around the sphere equals 2* PI, which means that your 60 equals 19.09 PI, meaning you got the cosinus for 1.09 PI, or 196 degrees.
Both answers are correct - first one calculates cosinus of 60 radians and the second of 60 degrees.
By default the 60 alone will be considered 60 radians, so that's why you get a different result
80 * cos(60) uses Radians
80 * cos(60degrees) uses Degrees
Since your value (60) is in Degrees, add the keyword 'degrees'
The first calculation is in Radians, the second is (obviously) in Degrees.
Math escapes me today.
How do I find the X speed and the Y speed of an object if it is going at a defined speed (say, 5 pixels/second) at a 45 degree angle?
So always 5 pixels/sec and always 45 degrees?
The general case is
velx=cos(a)*vel;
vely=sin(a)*vel;
a is angle, usually in radians, so convert from degrees, and the signs (positive/negative) will depend on your coordinate system.
Crazy fact from the 1980s: In the old days, we used lookup tables for sin and cos!
Edited: Made my axes more conventional thanks to comment below. x is positive to your right. y is positive up. 45 degrees is to the northeast. If you have something else, let me know.
It will be
Vx=VCos#
Vy=Vsin#
So in your case it will be Vx=5*cos45 and Vy=5*sin45
At 45 angle value of Cos & Sin is same i.e 1/root 2.
Note: If you are doing any math stuff in programming then have a look at Vecmath lib.
At a 45 degree angle, an object is going sqrt(2)/2 of the speed along each axis. Generally, you can do it with sin and cosine, but for specific angles like this you can do it just by knowing pythagorean triangles.
In a right triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides. You know the hypotenuse is V. You also know that the other two sides equal each other. That means that V^2 = Vx^2 * 2. This means that Vx = sqrt(V^2/2), which equals V * sqrt(1/2).