Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Help with Math.tan and Math.atan

  1. #1
    Member
    Join Date
    Jun 2012
    Location
    Uppsala, Sweden
    Posts
    36
    Thanks
    10
    Thanked 1 Time in 1 Post

    Post Help with Math.tan and Math.atan

    I am pretty new to math and wanted to find out how to calculate the angle between the hypotenuse and the adjacent side, with only knowing the adjacent side and the abutting catheter.
    I know that tan is abutting catheter divided by adjacent side. But that gives my a double.
    How to I cast that number to degrees.

    Here's my code:

    import java.util.Scanner;
     
     
    public class Matte {
     
    	public static void main(String[] args) {
    		Scanner in = new Scanner(System.in);
    		System.out.println("Enter abutting catheter: ");
    		double par1 = in.nextDouble();
    		System.out.println("Enter adjacent side: ");
    		double par2 = in.nextDouble();
     
    		System.out.println("calculating...");
    		double deci = Math.tan(par1 / par2);
    		System.out.println("The answer is: " + Double.toString(deci));
    	}
    }

    Please help me!

  2. #2
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Help with Math.tan and Math.atan

    Hello Dr Code!
    What is returned by the tan method? I know it's a double but what is the unit of measurement? Is it radians? If so, there is a toDegrees method in the Math class which is converting radians to degrees.

  3. #3
    Member
    Join Date
    Jun 2012
    Location
    Uppsala, Sweden
    Posts
    36
    Thanks
    10
    Thanked 1 Time in 1 Post

    Default Re: Help with Math.tan and Math.atan

    That's the problem, I have no idea what it returns, but I will try the toDegrees method.

  4. #4
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Help with Math.tan and Math.atan

    Quote Originally Posted by Dr.Code View Post
    That's the problem, I have no idea what it returns, but I will try the toDegrees method.
    It won't work.
    From the API, the tan(double a) method Returns the trigonometric tangent of an angle. Therefore it should be measured as length (mm, cm, etc) - if I'm not mistaken.
    And also it takes one parameter: a - an angle, in radians.
    Are you passing the method a parameter in radians?
    Hope this helps.

  5. #5
    Member
    Join Date
    Jun 2012
    Location
    Uppsala, Sweden
    Posts
    36
    Thanks
    10
    Thanked 1 Time in 1 Post

    Default Re: Help with Math.tan and Math.atan

    Well what I'm trying to do is to calculate an angle with only knowing the abutting catheter and the adjacent side.
    I do not know how to do that. I think it is something with arctan(Math.atan()), but don't know what.

  6. #6
    Member
    Join Date
    Jun 2012
    Location
    Uppsala, Sweden
    Posts
    36
    Thanks
    10
    Thanked 1 Time in 1 Post

    Default Re: Help with Math.tan and Math.atan

    Wait, solved it, I should use Math.atan instead of tan and then convert the radians i get from that to degrees. And I get the correct output.

    Here's my final code:

    import java.util.Scanner;
     
     
    public class Matte {
     
    	public static void main(String[] args) {
    		Scanner in = new Scanner(System.in);
    		System.out.println("Enter abutting catheter: ");
    		double par1 = in.nextDouble();
    		System.out.println("Enter adjacent side: ");
    		double par2 = in.nextDouble();
     
    		System.out.println("calculating...");
    		double deci = par1 / par2;
    		double radians = Math.atan(deci);
    		double degrees = Math.toDegrees(radians);
    		long answer = Math.round(degrees);
    		System.out.println("The answer is: " + Long.toString(answer) + " degrees.");
    	}
    }

  7. #7
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Help with Math.tan and Math.atan

    Glad you got it work. Make sure you mark the thread as solved.

Similar Threads

  1. Math.pow
    By britton33 in forum What's Wrong With My Code?
    Replies: 30
    Last Post: July 1st, 2012, 04:42 PM
  2. For the Math Majors
    By mszyndlar in forum Java Theory & Questions
    Replies: 0
    Last Post: October 18th, 2011, 04:40 PM
  3. Confusion with Math.toDegrees() and Math.toRadians(). Please help.
    By marksquall in forum Java Theory & Questions
    Replies: 3
    Last Post: June 23rd, 2011, 01:28 AM
  4. Math Drill
    By Java Neil in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 5th, 2011, 12:12 AM
  5. Math in Java?
    By [Kyle] in forum Java Theory & Questions
    Replies: 3
    Last Post: September 23rd, 2009, 12:21 PM

Tags for this Thread