# Laplacian kind of deformation in Rhino with SpaceMorph

Hi all,
I am looking for a way to implement a laplacian deformation for meshes like the cgal-library offers it.
Unless I don’t want to do too much math by myself I hope there is a way this can be done Rhino.
What I want to do:

1. Select all vertices which should be part of the deformation (region of interest)
2. Inside the region of interest select fixed vertices for which you already know the final position
3. provide the final position for the fixed vertices (for instance as a collection of Point3d)
4. deform the region of interest by moving the fixed vertices to the final position and let the others follow as smooth as possible
For self-explaining pictures see the link I provided.

One idea is to use the SpaceMorhp for that. I allready read this blogpost, but can not figure out where the points in SpaceMorph.MorphPoint(point) are coming from.
They seem to be connected to the mesh-vertices, but I dont know how. In the following code example every vertex in the mesh seems to be called twice.
I also don’t know what to do with a point for which I dont know the final position.

``````
import Rhino

class TestMorph(Rhino.Geometry.SpaceMorph):

def __init__(self):
self.num_pt_call = 0

def MorphPoint(self, point):
self.num_pt_call += 1
print "MorpPoint called with: %s" % point
return point

def create_mesh():
mesh = Rhino.Geometry.Mesh()

mesh.Normals.ComputeNormals()
mesh.Compact()

return mesh

mesh = create_mesh()
tm = TestMorph()
tm.Morph(mesh)

print "called MorphPoint %s times" % tm.num_pt_call

# should print:
# MorpPoint called with: 0,0,0.0009765625
# MorpPoint called with: 1,0,0.0009765625
# MorpPoint called with: 1,1,0.0009765625
# MorpPoint called with: 0,1,0.0009765625
# MorpPoint called with: 0,0,0
# MorpPoint called with: 1,0,0
# MorpPoint called with: 1,1,0
# MorpPoint called with: 0,1,0
# called MorphPoint 8 times

``````

Has anyone an idea for the Laplacian deformation?
Or can someone explain which points are given to the SpaceMorph.MorphPoint(…) method?
What to do with points for which I want Rhino to calculated the most “smooth” position?

Best

Raik

Hi Raik,

This really depends on the kind of geometry being morphed.

`SpaceMorph.MorphPoint` morph Euclidean points.

I should add that just because RhinoCommon has a space morph class doesn’t mean you have to use it. If you have an algorithm that work on meshes then you can certainly just code up your own function.

– Dale