i have Segment class who contain 2 sections , each section contain 2 point the X and Y coordinate.
Point class has getX() and getX() method.
public class Segment
{
private Point pointLeft;
private Point pointRight;
}
i want to find the overlap (is there is) between 2 sections:
public double overlap (Segment other)
{
}
how can i find it (only the X axis overlap)
the 2 sections parallel to X axis (each section has the same Y)
My understanding of your question is that you first want to project both lines on the X-axis, and then find their intersection.
That is, you want the length of the greyed out section on the X axis in the image above.
You’ll want to do it in 4 parts, like this:
Note, I’ve coded this in place, and haven’t had a chance to test it. But it should give you a basic idea of what needs to be done.