Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point to hull distance #59

Open
Cedvega opened this issue Aug 25, 2021 · 8 comments
Open

Point to hull distance #59

Cedvega opened this issue Aug 25, 2021 · 8 comments

Comments

@Cedvega
Copy link

Cedvega commented Aug 25, 2021

Would it be possible to add the point to hull distance ?

@davidcsterratt
Copy link
Owner

davidcsterratt commented Aug 29, 2021

On Sun, 2021-07-11 at 17:26 +0000, RENAUD Jean-Pierre (RDI Nancy) wrote:

What I want to do is to compute the distance to the hull of points that are outside the envelop. (these are map pixels for which I want to predict forest attributes, using a model that often have several independent variables (Xs)) As they are out of the calibration domain (out of the “convex hull” these are extrapolated according to the model that I’m using)

Brad Barber told me that I need to use 2 functions qh_findbestfacet and qh_distplane … but I don’t know how to use it in your geometry package.

It would be even more perfect if I could get not only the distance, but also the values of the intersecting points (on the Hull). I feel that not only the distance could be linked to the degree of bias, but also the direction of the vector.

@cbbarber 's message was:

Objet : Re: Help about finding distance of al point to the Hull

Many thanks for your clearly written question. What you are looking for should be available through the R package, but I am unfamiliar with their interface to Qhull. So you may need to reach to the R user groups.

You need two results for a given errant point --

  1. The facet that is closest to the point (in Qhull, qh_findbestfacet)
  2. The distance from the point to the facet (in Qhull, qh_distplane)

The distance is the distance from the point to the hyperplane for the closest facet. It is positive if the point is outside of the convex hull, as it should be in your case.

@davidcsterratt
Copy link
Owner

The geometry package can't do what you ask at the moment, but I am now pretty confident that I can adapt the inhulln() function to do this fairly quickly.

@cbbarber
Copy link

cbbarber commented Aug 29, 2021 via email

@davidcsterratt
Copy link
Owner

davidcsterratt commented Aug 29, 2021

Hmm... I have been using

    facet = qh_findbestfacet(qh, point, !qh_ALL, &bestdist, &isoutside);

and then taking bestdist as the distance - this seems to work in a simple example, when the perpendicular to the plane of the facet passes through the facet itself.
facet = qh_findbestfacet(qh, point, !qh_ALL, &bestdist, &isoutside);

e.g. The distance of the point (-0.5, -0.5) is found as -0.5 and (1, 1) is found as 1.412 in this simple test case:
Screenshot from 2021-08-29 19-04-56
However, the point (10, -1) is found to be 6.364 from the hull; I think is this distance from the plane of the diagonal facet. I think it should be a distance of 9 from the hull, since the closest point is (1, -1). I was trying to use qh_nearvertex() to find the closest vertex, but it reports the distance as 10, and it looks like the best vertex it finds is at (0, -1) - i.e. not one of the vertices of the hull.

@cbbarber
Copy link

cbbarber commented Aug 30, 2021 via email

@davidcsterratt
Copy link
Owner

davidcsterratt commented Sep 4, 2021

Thanks @cbbarber. qh_ALL in qh_findbestfacet seems to work and I've pushed my work so far containing this code.

However, I've run into a conceptual problem. When a point is above a facet (i.e. the perpendicular to the hyperplane of the facet passing through the point also passes through the facet, then the distance is reported correctly. But when a point is not above a facet, e.g. the point (-2, -2) in the above example, the closest point of the hull is the nearest vertex. But how do we test if a point is above a facet in order to use the distance to the nearest vertex?

@davidcsterratt
Copy link
Owner

The crucial changes are in this file: 5454978#diff-18d95f23a29dae23e9245ff171c2905184d938e4f109e63072a960f8b10801e0

@cbbarber
Copy link

cbbarber commented Sep 5, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants