0
public class PolarCoordinates {

    public static void main(String[] args){

        int r=10;
        double x=0,y=0,theta=30;
     x=r*Math.cos(theta);
    y=r*Math.sin(theta);

        System.out.println("The value of x is :" +x);
        System.out.println("The value of y is :" +y);



}
}

help please?
it gives me wrong answer.
10cos(30) should equal to 8.7, but it gives me 11.7 ans.
10sin(30) should equal to 5, and it gives me 2.63 ans.
whats wrong with my code?

3
Contributors
7
Replies
42
Views
3 Years
Discussion Span
Last Post by reincom
0

what's wrong with my formula?

sin. cos etc use angles in radians (Google it), you have supplied an angle in degrees

Pi radians is 180 degrees, so ddanbe' formula should be theta = theta * Math.PI / 180;
(sorry ddanbe)

Edited by JamesCherrill

0

Oops!!! Thanks for correcting me JamesCherrill, 2*pi rad = 360° and not pi rad = 360° of course!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.