के भीतर है या नहीं, मैं घंटों तक इस पर रहा हूं, हर प्रश्न के बारे में विभिन्न विधियों को देखने का प्रयास कर रहा हूं। शायद मेरे पास यह पूरी तरह गलत है, लेकिन मुझे लगता है कि मेरे पास इसका गणित सही है, लेकिन इससे कोई फर्क नहीं पड़ता कि मैं कितनी संख्या में इनपुट करता हूं, मुझे एक ही आउटपुट मिलता है। मेरा कोड कहीं से दूर है और मुझे इसे मध्यरात्रि में बदलना है।यह पता लगाना कि कोई बिंदु त्रिभुज
यह सब इतना मजेदार है: पता लगाएं कि कोई बिंदु त्रिकोण कोड के भीतर है या नहीं। (शुरुआती के लिए)
import java.util.Scanner;
public class PointsTriangle {
// checks if point entered is within the triangle
//given points of triangle are (0,0) (0,100) (200,0)
public static void main (String [] args) {
//obtain point (x,y) from user
System.out.print("Enter a point's x- and y-coordinates: ");
Scanner input = new Scanner(System.in);
double x = input.nextDouble();
double y = input.nextDouble();
//find area of triangle with given points
double ABC = ((0*(100-0 )+0*(0 -0)+200*(0-100))/2.0);
double PAB = ((x*(0 -100)+0*(100-y)+0 *(y- 0))/2.0);
double PBC = ((x*(100-0 )+0*(0 -y)+200*(y-100))/2.0);
double PAC = ((x*(0 -100)+0*(100-y)+200*(y- 0))/2.0);
boolean isInTriangle = PAB + PBC + PAC == ABC;
if (isInTriangle)
System.out.println("The point is in the triangle");
else
System.out.println("The point is not in the triangle");
}//end main
}//end PointsTriangle
यह शायद मूल्यों आपको लगता है कि आप डीबगिंग के भाग के रूप में पढ़ा outputting के लायक है ... – Floris