How to go about using tangents in Java? -


i bored , wanted practice java coding skills. made program finds area of polygon based on know (radius, perimeter, apothem).

here's portion:

static void pentagon() {     system.out.println("select know");     system.out.println("[1]perimeter\n[2]apothem\n[3]radius");     info = input.nextint();      if (info == 1) {         system.out.println("what perimeter of pentagon?");         double per = input.nextdouble();         double apothem = per * .137638192;         double answer = apothem * per * .5;         system.out.println("the area of pentagon " + answer + " square units.");     } else if (info == 2) {         system.out.println("what apothem of pentagon?");         double apothem = input.nextdouble();         double per = apothem / .137638192;         double answer = apothem * per * .5;         system.out.println("the area of pentagon " + answer + " square units.");     } else if (info == 3) {         system.out.println("what radius of pentagon?");         double rad = input.nextdouble();         double per = rad / .1701301617;         double apothem = per * .137638192;         double answer = apothem * per * .5;         system.out.println("the area of pentagon " + answer + " square units.");     } } 

due problem decimals (ratio of apothem perimeter) had figure out myself, code few useful ones.

if knew how use tangents, figure out.

ex: double apothem = length / tan(360/10/2)

(an apothem of decagon) can show me how code previous line?

the recomended way use java.lang.math.tan(double a)

double apothem = 1 / java.lang.math.tan( (2*java.lang.math.pi)/(10*2)) 

unless there reason why need extraordinary precision , not provide it. may able find third party alternative.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -