Advertisement
romarioc

Triangle

Oct 9th, 2015
4,062
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. /*
  4.  * Name: Romario Coffie
  5.  * Date: 10/9/2015
  6.  * Course: CSC-111 Intro to Java Programming
  7.  * Problem: 3.27
  8.  * Description: Determine if point is in triangle
  9.  * Email: Romario.agc@gmail.com
  10. */
  11.  
  12. public class Angle{
  13.     public static void main(String[] args) {
  14.         Scanner input = new Scanner(System.in);
  15.        
  16.         System.out.println("Enter a value for X intercept then Y intercept.");
  17.         Double xinter = input.nextDouble();
  18.         Double yinter = input.nextDouble();
  19.  
  20.         System.out.println("Enter a values for a point, X then Y.");
  21.         Double xval = input.nextDouble();
  22.         Double yval = input.nextDouble();
  23.        
  24.  
  25.         double m = -(yinter-0)/(xinter-0);
  26.         double c = yval;
  27.         if (xval<=xinter && yval <=yinter  && xval>=0 && yval >=0){
  28.            
  29.             if ( xval <= (yval - c)/m)
  30.             System.out.println("The point is in the triangle");
  31.             else{
  32.                 System.out.println("The point is not in the triangle");
  33.             }
  34.         }
  35.         else{
  36.             System.out.println("The point is not in the triangle");
  37.         }
  38.         input.close();
  39.     }  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement