There are no. of components around and on Line2D.I want to find only the overlapped ones.I tried line.getbounds().intersects(component) but it gives the rectangular area components which I don't need.Also,distance sometimes gives me a component which is very near to Line but not on line.Any solution?
Short answer: check if at least one of these two conditions is true
Detailed description: These are the possible cases:
Only the middle bullet is a bit tricky, however since you are testing only jcomponent, the life is simple, because they are rectangles aligned with the axis. You can easily compute the endpoint of the sides of the bounds of the component. The bounds are given by a point (x,y) the width w and the height h. This gives you the four sides as: