# Thread: Math.atan --- To Degrees Help

1. Member 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

}```
I'm trying to convert (180/n) to degrees and then take the tangent of it for use in the equation TotalArea. I've been at it for a solid 30 minutes and just can't get it to work. I'm new to java and this is my first time using any of the Math methods (besides Math.pow). The double "TotalArea" has already been predefined earlier, as well as the String "d".
The program compiles without error, i'm just getting the wrong output.

ps. the code is to calculate the area of an N-sided regular polygon where s is the side length and n is the number of sides, if that helps.  Reply With Quote

2. Moderator   Join Date
Feb 2009
Location
New Zealand
Posts
4,716
Rep Power
18

## Re: Math.atan --- To Degrees Help

the code is to calculate the area of an N-sided regular polygon where s is the side length and n is the number of sides
That would mean that 180/n is twice the angle subtended at the centre by a side in degrees. If you want to find its tangent you would convert it to radians.

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; 03-07-2012 at 06:58 AM.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•