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

GetParameterAt reports -1 for some locations. #946

Open
ikeough opened this issue Feb 21, 2023 · 1 comment
Open

GetParameterAt reports -1 for some locations. #946

ikeough opened this issue Feb 21, 2023 · 1 comment
Labels
Bug Something isn't working
Milestone

Comments

@ikeough
Copy link
Contributor

ikeough commented Feb 21, 2023

See https://github.com/tkahng/ElementsCurve.

@tkahng
Copy link

tkahng commented Feb 25, 2023

so i did some more digging and got it to work by using a custom extension method for Polygon.GetParameterAt.
theres a few things ive noticed, but not sure if they are the culprit causing this behavior.

first the geometry in the rhino file is definitely not the best to test this on, since its a nurbs polycurve etc.

seems like there might be related to #945 , the closestPoint from DistanceTo does not seem to be always actually on the polygon. hence when using GetParameterAt using that point, it fails to find the segment the point lies on, returning -1.

GetParameterAt is not overriden on Polygon, so calls invoke the Polyline.Segments() instead of Polygon.Segments(), . maybe one less line in the return could be problematic.

heres a dirty workaround i used it make it work:

        public static double PolygonGetParameterAt(this Polygon polygon, Vector3 point)
        {
            var segments = polygon.Segments();
            var segment = segments.Select(s => new { line = s, dist = point.DistanceTo(point.ClosestPointOn(s)) }).OrderBy(p => p.dist).First().line;
            var segmentIndex = segments.ToList().IndexOf(segment);
            var segmentsLength = segments.Where((x, i) => i < segmentIndex).Sum(x => x.Length());
            var pointLength = segmentsLength + point.ClosestPointOn(segment).DistanceTo(segment.Start);
            return pointLength / polygon.Length();
        }

ill try to save the geometry as json so we can test without the rhino3dm dependency.

@ikeough ikeough added this to the 2.0 milestone Apr 14, 2023
@ikeough ikeough added the Bug Something isn't working label Apr 17, 2023
@ikeough ikeough modified the milestones: 2.0, 0.2.1, 2.1 Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants