java 判断点是否在一条线段上

public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Point point1 = new Point();
		Point point2 = new Point();
		double x, y;
		point1.setLocation(5.0, 5.0);
		point2.setLocation(1.0, 1.0);
		System.out.println("请分别输入点x,y的坐标:");
		x = scan.nextDouble();
		y = scan.nextDouble();
		boolean pdline = (x - point1.getX()) * (point1.getY() - point2.getY()) == (point1.getX() - point2.getX())
				* (y - point1.getY());
		if (pdline) {
			System.out.println("您输入的点在该条直线上");
		} else {
			System.out.println("您输入的点不在该条直线上");
		}
		scan.close();
	}

posted on 2019-01-11 13:59  疯狂的小萝卜头  阅读(1438)  评论(0编辑  收藏  举报