Results 1 to 3 of 3
  1. #1
    Lach is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Law of cosines help to find angles URGENT!

    Hello and thanks for stopping by to help me, ive been stumped on this for an hour and a half now. I have this program here :


    Java Code:
    import java.util.Scanner;
    import javax.swing.JOptionPane;
    import java.lang.Math;
    
    public class Triangle
    { 
     
     double x1 = 0;
     double x2 = 0;
     double y1 = 0;
     double y2 = 0;
     double z1 = 0;
     double z2 = 0;
     double sideA = 0;
     double sideB = 0;
     double sideC = 0;
     double area = 0;
     double perimeter = 0;
     double angleA = 0;
     double angleB = 0;
     double angleC = 0;   
       
       public Triangle(int x1, int x2, int y1, int y2, int z1, int z2)
       {
          this.x1 = x1;
          this.x2 = x2;
          this.y1 = y1;
          this.y2 = y2;
          this.z1 = z1;
          this.z2 = z2;
       }
      
       public double getX1()
       {
          return x1;
       }
       
       public double getX2()
       {
          return x2;
       }
       
       public double getY1()
       {
          return y1;
       }
       
       public double getY2()
       {
          return y2;
       }
       
       public double getZ1()
       {
          return z1;
       }
       
       public double getZ2()
       {
          return z2;
       }
      
       public double getLengthA()
       {
          sideA = Math.sqrt(Math.pow((z1-y1)+(z2-y2),2));
          return sideA;
       }
       
       public double getLengthB()
       {
          sideB = Math.sqrt(Math.pow((z1-x1),2) + Math.pow((z2-x2),2));
          return sideB;
       }
       
       public double getLengthC()
       {
          sideC = Math.sqrt(Math.pow((y1-x1),2) + Math.pow((y2-x2),2));
          return sideC;
       }
       
       public double getHeight()
       {
          return z2;
       }
       
       public double getArea()
       {
          area = (y1*z2)/2;
          return area;
       } 
       
       public double getPerimeter()
       {
          perimeter = getLengthA() + getLengthB() + getLengthC();
          return perimeter;
       }
       
       public double getAngleA()
       {
          
       }
       
       public double getAngleB()
       {
          
        }
    
       public double getAngleC()
        {
       
        }  
       
       
    }
    This program takes user input and makes some calculations such as area perimeter and angles. Assume the user enter x1=0, x2=0, y1=3, y2=0, z1=3, and z2=4. If a user inputes these numbers when they are callled to do so, all the proper calculations will be made except for angles. I have been stuck on the angle part for an hour and a half trying all different variations of the law of cosines in my code, which is, cos C = (a + b - c)/2ab. I cant get it to work at all though. If anyone could just write it out in code for me for just one of the angels, that would be great, as i could modify it accordingly to find the other ones by myself. Like i said ive been at this for hours and i cant get it to work so its becoming really frustrating. Please help if you can. Thanks!

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Law of cosines help to find angles URGENT!

    Law of cosines help to find angles URGENT!

    Duplicate post and its still not urgent!

  3. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,917
    Rep Power
    5

    Default Re: Law of cosines help to find angles URGENT!

    So, you have the cos C and you want C. Every heard of the inverse trigonometric functions? You can look it up on the internet for details. But just
    like cos theta gives the cosine of the angle theta, the arccos (old term) or inverse cosine gives the angle when supplied with the cosine value.
    They are also in the JDK Math class. Just don't forget about radians vs degrees. And a couple other things you may want to think about.
    You should make certain that no single side of your triangle is greater than the sum of the other two. And I believe your area method could use
    some work. The area of a triangle is .5 x base x height. Just using a single coordinate won't cut it. What if my base goes from 200,200 to 202,200.
    The base is length 2. The base of a triangle is somewhat abstract anyway and depends on the perspective of the observer.
    The actual area of a triangle is .5 x "one side" x "the altitude perpendicular to that side." You could also use Heron's formula to calculate the area.

    Regards,
    Jim
    Last edited by jim829; 10-03-2013 at 04:00 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 10
    Last Post: 09-03-2012, 07:22 PM
  2. Problem with angles
    By Dirnol in forum Java Gaming
    Replies: 0
    Last Post: 10-22-2011, 02:55 AM
  3. Urgent: Cannot Find Symbol!
    By helpme123 in forum New To Java
    Replies: 2
    Last Post: 11-21-2010, 01:34 AM
  4. [URGENT]SHA Encryption System...need urgent helps
    By java_idiot in forum New To Java
    Replies: 6
    Last Post: 05-02-2010, 11:04 AM
  5. Urgent!!!
    By winnie99 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 12-18-2009, 04:17 PM

Posting Permissions

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