Below I have included the code I was working on.
I need to create a class that takes 3 points, and can return the side length, and angles of those points.
I am having trouble at my computeAngles
method. I am trying to call three methods there to getSide1_Length
and side2 and 3 lengths. But I am having a little trouble.
It is not finished. I still need to get angle1, and angle3, but I want to figure out angle 2 before I continue.
import java.awt.Point;
import java.lang.Math;
public class Triangle
{
// instance variables - replace the example below with your own
private Point p1, p2, p3;
private double angle1,angle2,angle3;
public Triangle(Point p1, Point p2, Point p3)
{
// initialise instance variables
p1 = p1;
p2 = p2;
p3 = p3;
}
public Point setPoint1(Point p1)
{
this.p1 = new Point();
return p1;
}
public Point setPoint2(Point p2)
{
this.p2 = new Point();
return p2;
}
public Point setPoint3(Point p3)
{
this.p3 = new Point();
return p3;
}
public Point getPoint1()
{
return p1;
}
public Point getPoint2()
{
return p2;
}
public Point getPoint3()
{
return p3;
}
public double getSide1_Length(double side1)
{
side1 = Math.sqrt(((Math.pow((p2.x - p1.x), 2)) + Math.pow((p2.y - p1.y), 2)));
return side1;
}
public double getSide2_Length(double side2)
{
side2 = Math.sqrt(((Math.pow((p3.x - p2.x), 2)) + Math.pow((p3.y - p2.y), 2)));
return side2;
}
public double getSide3_Length(double side3)
{
side3 = Math.sqrt(((Math.pow((p3.x - p1.x),2)) + Math.pow((p3.y - p1.y),2)));
return side3;
}
public double getAngle1()
{
return angle1;
}
public double getAngle2()
{
return angle2;
}
public double getAngle3()
{
return angle3;
}
private double computeAngles(double angle1, double angle2, double angle3)
{
double side1 = getSide1_Length(side1);
double side2 = getSide2_Length(side2);
double side3 = getSide3_Length(side3);
angle2 = Math.asin(((Math.pow(side3,2)) - (Math.pow(side2,2)) - (Math.pow(side1,2)) / (-2 * (side2 * side1))));
return angle2;
}
}