• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Distance between a point and a cubic curve

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic