programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Distance between a point and a cubic curve

Ranch Hand
Posts: 41
• Number of slices to send:
Optional 'thank-you' note:
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
Posts: 41
• Number of slices to send:
Optional 'thank-you' note:
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.

Ranch Hand
Posts: 342
• Number of slices to send:
Optional 'thank-you' note:
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

 Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad: a bit of art, as a gift, the permaculture playing cards https://gardener-gift.com