Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:37:09+00:00 2026-06-14T22:37:09+00:00

I find out that the GeneralPath class in Java only provides methods to check

  • 0

I find out that the GeneralPath class in Java only provides methods to check if a point is inside a general path (to be specific, a polygon with straight line segments). Does someone know how to efficiently check if a point is on the boundary of a general path or not?

Thanks

Dummy solution 1: We can define a circle with radius $\epsilon$ ($\epsilon$ is a very small positive real value). And then, we check a sufficient number of points on the circle to see if one/some of them falls into the general path or not. However, such a dummy method may require a considerable amount of computational effort, which is not very desirable.

Dummy solution 2: We can compute the distances from the point (on the boundary) to every side of the polygon. If the minimal distance is sufficiently small, this point is on the boundary; otherwise, it is not. Again, this method can still be computationally intensive.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:37:11+00:00Added an answer on June 14, 2026 at 10:37 pm

    I haven’t come across a library method … or potted solution to the problem. I think that the reason is that the problem is fundamentally impossible to solve exactly.

    The GeneralPath class inherits a method called getPathIterator from Shape2D. If you look at the javadoc, you will see that the PathIterator object models the path as a sequence of straight line segments. And the getPathIterator method takes a flatness parameter specified as follows:

    “flatness – the maximum distance that the line segments used to approximate the curved segments are allowed to deviate from any point on the original curve.”

    Now, if the shape you are looking at consists of straight line segments, there is a good chance that the path iterator will give you those line segments. But if the shape has curved segments, then the line segments are only an approximation. And it is clearly impossible to test if a point is exactly on a boundary if you don’t know what the exact boundary is.

    Even assuming that the line segments exactly model the real curve, you still have the problem that (except for special cases), most of the points on the real curve cannot be represented exactly using Java primitive datatypes (int, double, etc). So once again “exactness” is problematic.

    I think that the best you can hope for is to test whether your point is within some small delta of the boundary … and choose a flatness value that is less than that delta, iterate the path line segments, and test the tangential distance of the point from each segment.

    Note: if you make flatness very small, you can expect to have to test a very large number of line segments. I don’t think there is any way around this computational concern while sticking to the GeneralPath API.


    If you restrict the problem to true (i.e. straight-sided) polygons, then you simply need to iterate the line segments, and for each one test to see if the distance from the point to the line is less than some suitable epsilon. This Wikipedia entry gives you the mathematics. Note that exactness is still going to be a concern here …

    You don’t have an enormously costly computation, but computing an accurate square-root doesn’t come for free, and you have to do it up to N times for an N-sided polygon.

    Doing better than that (i.e. getting better than O(N)) is going to be difficult. However, if the polygon is fixed and you are going to be testing a huge number of points against it, then you could consider using a pre-computing a quad-tree data structure to do the resolution. Precomputing the quad-tree will be expensive, but if N is large enough testing a a point will be cheaper. (Roughly O(log(1/epsilon)) in the worst case, instead of O(N) on average. And the further away from the boundary a point is, the cheaper the answer.)

    But as I said, quad-trees will only help in limited situations …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was surprised to find out that the parameter-less constructor of my base class
For example, is there a way to find out that this class has a
I setup an AppHarbor application only to find out that it does not support
I try to record video using MediaRecorder Class. However I find out that I
We are using Hibernate with Spring for our Java application. We find out that
I recently find out that wpf handles INotifyPropertyChanged in two different ways. I just
How could you find out that an Exception occurred in a Thread in a
it took me some time to find out that both Eclipse and Aptana get
I am just trying to find out that does puppet have something similar to
e.g., how can I find out that the executable has been installed in /usr/bin/python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.