aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Distance between a point and a cubic curve Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Distance between a point and a cubic curve" Watch "Distance between a point and a cubic curve" New topic
Author

Distance between a point and a cubic curve

Veronique Kus
Ranch Hand

Joined: Jun 13, 2010
Posts: 41
Hi,
I need to implement a function that makes a cubic curve "selected" when the user clicks on it. In order to do that, I need to detect whether the mouse click happened on the cubic curve (or within a very short distance from it). So I need a function which, using pseudo-code would look like this:

if(distance between mouseClick and cubicCurve < 10){
make cubic curve selected
}else{
do not select curve
}

Unlike Line2D, cubic curve does not have a function that would tell the distance between a certain point (e.g. mouse event) and the curve. I was wondering how I could implement this myself? I found this thread. It seems relevant but I don't fully understand what this code does and how it could help me. Can anyone please give me some advice and/or help me with this example code???
Veronique Kus
Ranch Hand

Joined: Jun 13, 2010
Posts: 41
OK so I decided to implement it using a simpler method, I create a small rectangle around the click point and test whether any of the cubic curve drawn instersect this rectangle.
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
Hi Veronique,

I think that sounds like a good solution. As a general comment, in case you do not know about it, if you are doing a lot of work with 2D geometry - testing for distances, intersections, point-on-line etc) - there is quite a lot of functionality in the Java Topology Suite that you might find useful.

http://tsusiatsoftware.net/jts/main.html

cheers,
Ben


SCJP 1.4, www.gsi3d.org.uk
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Distance between a point and a cubic curve