question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shapely polygon from trimesh.path.path.Path2D

See original GitHub issue

I have sliced a 3d mesh with yz planes into several 2d sections (i.e. Path2D objects). Now, I’d like to create Shapely polygons from these 2d sections. For doing so, I need a list of points as XY coords. However, if I use Path2D.vertices, I get a weird polygon because the vertices are un-ordered. Is there any way to get an ordered list of the vertices composing a Path2D object?

Obviously I cannot use the python .sort() method.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mikedhcommented, Jan 3, 2017

Hey, so what part isn’t working? The polygon is probably displaced if you are using the to_planar method without specifying the matrix.

I updated the section example: https://github.com/mikedh/trimesh/blob/master/examples/section.ipynb check out In[12] to show how to pass the matrix. Also I added In[10] which shows a linestring-polygon intersection.

Best, Mike

0reactions
mikedhcommented, Mar 5, 2020

No worries, glad it was a version issue in this case! Though for future people looking at this I actually have another suspect that could possibly touch this too: vertex merging behavior. After a bunch of asks for “no merging by default” my compromise solution was to to consider vertex normals if populated, and only merge vertices that had the same position, vertex normal (if loaded), and UV (if loaded).

For 3D printing-ish stuff, I now load every mesh using loaded = trimesh.load(file_name, merge_norm=True, merge_tex=True). Behavior on STL files (which have no vertex normals) wouldn’t change, but OBJ could.

Read more comments on GitHub >

github_iconTop Results From Across the Web

trimesh.path — trimesh 3.17.1 documentation
A list of shapely.geometry.Polygon objects with interiors created by checking which closed polygons enclose which other polygons. Returns. full – Polygons ...
Read more >
Find Properties of Polygons from Path2D, derived from the ...
The property "polygons_closed" returns an array of shapely polygons. So to get ie. the area, use: for polygon in slice_2D.polygons_closed: ...
Read more >
Part — pyslm 0.5.0 documentation - Read the Docs
Returns the list of paths and coordinates from a cross-section (i.e.. regenerate () ... A Shapely Polygon representing the projected area of the...
Read more >
python/8446/trimesh/trimesh/path/path.py - Program Talk
path.py. A library designed to work with vector paths. ... from shapely.geometry import Polygon ... If the current Path2D consists of n 'root'...
Read more >
PySLM - lukeparry.uk
The paths are then translated into Shapely.Polygon objects. """ Extract the outline of the overhang mesh region""" poly ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found