TiagoM
TiagoM

Reputation: 187

Check if a Point is inside a line2D

I didn't find any method on java api to do this... there is one like : line.contains(point).. but it says that line2d doesn't have any area so it will return always false.. Any idea ?

Upvotes: 2

Views: 784

Answers (2)

fly
fly

Reputation: 57

Compare point by point and see if the cursor matches it.

You can do the search using the for each loop described here.

Upvotes: 2

coffee_machine
coffee_machine

Reputation: 1223

You should compute the distance from the point to the line, and if it is sufficiently small, then consider the point being on the line.

Google "distance point to line" or "distance point to segment".

Upvotes: 1

Related Questions