Skip to content

Instantly share code, notes, and snippets.

@raphaelsaunier
Created October 15, 2010 19:05
Show Gist options
  • Save raphaelsaunier/628744 to your computer and use it in GitHub Desktop.
Save raphaelsaunier/628744 to your computer and use it in GitHub Desktop.
TrigLength
import java.util.Scanner;
import java.text.DecimalFormat;
public class TrigLength
{
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
int distance_trigpoints, angle_from_trigpoint1, angle_from_trigpoint2;
double distance_point1, distance_point2;
System.out.print("Enter the distance between the trig points and then click ENTER: ");
distance_trigpoints = scan.nextInt();
System.out.print("Enter the angle in degrees from trig point 1 and then click ENTER: ");
angle_from_trigpoint1 = scan.nextInt();
System.out.print("Enter the angle in degrees from trig point 2 and then click ENTER: ");
angle_from_trigpoint2 = scan.nextInt();
distance_point1 = (distance_trigpoints * Math.sin(angle_from_trigpoint2 * Math.PI/180)) / (Math.sin((angle_from_trigpoint1 * Math.PI/180) + (angle_from_trigpoint2 * Math.PI/180)));
distance_point2 = (distance_trigpoints * Math.sin(angle_from_trigpoint1 * Math.PI/180)) / (Math.sin((angle_from_trigpoint1 * Math.PI/180) + (angle_from_trigpoint2 * Math.PI/180)));
System.out.println("The distance from point 1 is " + (new DecimalFormat("0.00")).format(distance_point1) + ": ");
System.out.println("The distance from point 2 is " + (new DecimalFormat("0.00")).format(distance_point2) + ": ");
if (distance_trigpoints < 0) // <- No semicolumn here!
System.out.println("You have entered a negative distance. Please enter a positive integer");
if (angle_from_trigpoint1 < 0)
System.out.println("Negative angle not possible. Please enter a positive integer");
if (angle_from_trigpoint2 < 0)
System.out.println("Negative angle not possible. Please enter a positive integer");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment