Chapter 3 Exercise 34 Introduction to Java Programming Tenth
Chapter 3 Exercise 34, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.
*3.34 (Geometry: point on line segment) Programming Exercise 3.32 shows how to test whether a point is on an unbounded line. Revise Programming Exercise 3.32 to test whether a point is on a line segment. Write a program that prompts the user to enter the three points for p0, p1, and p2 and displays whether p2 is on the line segment from p0 to p1. Here are some sample runs:
 
 Enter three points for p0, p1, and p2: 1 1 2.5 2.5 1.5 1.5
 (1.5, 1.5) is on the line segment from (1.0, 1.0) to (2.5, 2.5)
 
 Enter three points for p0, p1, and p2: 1 1 2 2 3.5 3.5
 (3.5, 3.5) is not on the line segment from (1.0, 1.0) to (2.0, 2.0)
Solution
Lets take it step by step
(x2 < x1 && x2 > x0) || (X2<x0 && x2 > x1)
this checks whether point lies between the two end of line segment in terms of x coordinate as any point on this line will be between x coordinate of extreme point of line segment.
similarly condition for y is checking whether point lies between y coordinate of line segment.
Deteminant is used to find area of a traingle when 3 coordinates are given.
Discriminant is used to check if three point form a triangle if not then they need to be consecutive and as we have already determined that point needs to lie on line if they are consecutive then point will lie on the line.
So discriminant 0 indicate that point lies on the line segment.

