Cartesian Point Class
Explore how to implement the Cartesian Point class and use vector cross products to calculate the position of a point relative to a line segment. Understand the findPosition() method and how to work with coordinates and vectors in Java to solve geometric problems programmatically.
Introduction to the Cartesian system
Let’s dive into the discrete mathematical concept of vector space. In computer science, vectors represent a couple of things, such as lists of only rows or of rows and columns. Sometimes, we can place a vector point with two coordinates, x and y, and find the direction of the point concerning a line segment.
This algorithm is used in producing maps and directions, finding the area of polygons, and much more using vector cross products.
“How do we get the direction of a point on a map? Should we turn right or left? We can figure that out using the x- and y-coordinates: x for right, y for left. We can also move forward if that point lies on the same line.”
In geometry, three concepts are vital: point, line, and plane. To understand these concepts, let’s first see the illustration below.
Using the cross product for the position of points
Looking ...
In our next Java program, let’s calculate the direction of C from line segment AB.
Take a look at the output of the OnLeftSide.java file:
The point C is on the left of line AB.
Next, let’s change all the coordinates of C ...