Results 1 to 2 of 2
Thread: Math.atan  To Degrees Help
 03072012, 07:42 AM #1Member
 Join Date
 Mar 2012
 Posts
 2
 Rep Power
 0
Math.atan  To Degrees Help
Hi, I've hit a snag. I've got this rather long piece of code that I'm working on, here's the issue area
Java Code:else { //input number of sides and side length int n = Integer.parseInt(d); //number of sides String Ss = JOptionPane.showInputDialog(null, "Enter the length of the side: ", n + "GON", JOptionPane.QUESTION_MESSAGE); double s = Double.parseDouble(Ss); //side length //calculate area and perimeter begin problem area double deg = (Math.toDegrees(180 / n)); //converts radians to degrees double part = Math.atan(deg); //part is a part of the equation that deals with the tangent of some angle (180/n) TotalArea = (((s * s) * n)/ (4 * (part))); System.out.println(TotalArea); //end problem area }
The program compiles without error, i'm just getting the wrong output.
ps. the code is to calculate the area of an Nsided regular polygon where s is the side length and n is the number of sides, if that helps.
Thanks in advance!
 03072012, 07:54 AM #2Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,609
 Rep Power
 12
Re: Math.atan  To Degrees Help
the code is to calculate the area of an Nsided regular polygon where s is the side length and n is the number of sides
Also notice that atan() finds the arctangent (aka inverse tangent  it finds an angle whose tangent is equal to the argument). The comment in the code would indicate you want Math.tan(). But trigonometry would indicate that Math.sin() would be more useful.Last edited by pbrockway2; 03072012 at 07:58 AM.
Similar Threads

Rotating an image 90 Degrees
By cvillejin in forum New To JavaReplies: 4Last Post: 04032011, 07:56 PM 
Radians to Degrees issue?
By Joey Gobert in forum Advanced JavaReplies: 5Last Post: 12152010, 09:41 PM 
Create Math.sin without math.sin
By vudoo in forum New To JavaReplies: 11Last Post: 12072010, 07:23 AM 
help w/ conversion of degrees(CtoF, FtoC)
By clemsontigers in forum New To JavaReplies: 11Last Post: 11082010, 10:57 PM 
[j2me] sprite rotation with degrees
By Rooneyz in forum CLDC and MIDPReplies: 0Last Post: 07062009, 03:40 PM
Bookmarks