How to fit a point cloud into a surface

I get a graph of points like the first one,I have the three dimensional coordinates of these points, and I can fit these points into a surface, right? I have tried to add small squares, such as the second picture, but the edges are too rough and the program runs too slowly. Is there any way to accurately fit these points into the surface? Thank you


See:

SketchUp Ruby API Release Notes:

What’s new in SketchUp 2021.1

  • Geom::PolygonMesh is now faster when looking up points in large meshes. This also improve performance when adding points to large meshes. Note that the mesh need to be created with an estimated total number of points for this performance improvement to kick in. The lookup of points for large meshes are now O(logN) instead of O(N^2).

Hello, do the coordinates of the points added to the grid have to be in a certain order? My point coordinates are sorted by row, which gives the following result. Is there any way to improve it?Thank you.

mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
mesh = Geom::PolygonMesh.new
array=[[0.0, 0.0, 0.0], [39.37007874015748, 0.0, 0.0], [78.74015748031496, 0.0, 0.0], [118.11023622047244, 0.0, 0.0], [157.48031496062993, 0.0, 0.0], [196.8503937007874, 0.0, 0.0], [236.2204724409449, 0.0, 0.0], [275.59055118110234, 0.0, 0.0], [314.96062992125985, 0.0, 0.0], [354.33070866141736, 0.0, 0.0], [0.0, 39.37007874015748, 0.0], [39.37007874015748, 39.37007874015748, 0.0], [78.74015748031496, 39.37007874015748, 0.0], [118.11023622047244, 39.37007874015748, 0.0], [157.48031496062993, 39.37007874015748, 0.0], [196.8503937007874, 39.37007874015748, 0.0], [236.2204724409449, 39.37007874015748, 0.0], [275.59055118110234, 39.37007874015748, 0.0], [314.96062992125985, 39.37007874015748, 0.0], [354.33070866141736, 39.37007874015748, 0.0], [118.11023622047244, 78.74015748031496, 0.0], [157.48031496062993, 78.74015748031496, 0.0], [196.8503937007874, 78.74015748031496, 0.0], [236.2204724409449, 78.74015748031496, 0.0], [275.59055118110234, 78.74015748031496, 0.0], [314.96062992125985, 78.74015748031496, 0.0]]
polygon_index = mesh.add_polygon(array)
Sketchup.active_model.entities.add_faces_from_mesh(mesh)

When you add a polygon to the mesh, it is usually a triangle or a quad at a time.
You can’t just dump all of the vertices into the mesh as a single polygon.

Also, as mentioned in the release notes, you tell the mesh object (in it’s constructor call) how many points will be in the mesh in order to gain the best speed.

1 Like

:thinking:Thinking aloud…

I guess you have to give the polygon points in a right order, as you see in the example of the fifth overloads here (#add_polygon-instance_method). (You get a 5 points polygon in this example.)
In my opinion, if the points are in one plane then there can be more than 4 vertices of the polygon…

The issue is: how to get the points to the rightly ordered array (Array of 3-element Arrays) to form a (convex ? ) polygon?
Unfortunately I have no experience how to solve … but there should be an algorithm to process a point cloud, preferably into triangles or quads as @DanRathbun suggested.

Perhaps https://sketchucation.com/plugin/1110-tig_points_cloud_triangulation can be usefull.

1 Like