Week 2: Transformation and Nesting Objects With Rhino
by mengjiazhu in Workshop > 3D Printing
929 Views, 0 Favorites, 0 Comments
Week 2: Transformation and Nesting Objects With Rhino
Assignment: Create a set of small stacking or nesting objects functional or otherwise (cups, baskets, coasters, measuring spoons, Matryoshka dolls etc.)
Findings:
I made a shelled heart shape using a set of grasshopper operations. I think due to the asymmetry of the shape, the scale and nesting is not perfect. Some places is closer to each other, like the corners, while other places are far away. So I use the closest places as referencing points for vector adjustment. After baking all generated objects, I use manual moving and snapping to nest and stack the objects.
For object transformation, I altered the code with a scale offset to control the scale.
Problem:
One problem I have is on the surface morph. In the example Jennifer gave, the 'surf' input of surfmorph is connected to a geometry component. But I got error like: data conversion failed from brep to surface. I also tried extracting the surface, it works when the surface is not 'closed'. Wondering how should I change my code to the closed surface.
Here is the complete python code:
"""Provides a scripting component.<br> Inputs: x: The x script variable y: The y script variable Output: a: The a output variable"""
__author__ = "mengjia"
import rhinoscriptsyntax as rs import Rhino.Geometry as geom
'''function to create an affine transformation given two points and a scale value''' def TransformFrom2Points(p0,p1,s): v1 = p1-p0 v3 = rs.CreateVector(0,0,1) v2 = geom.Vector3d.CrossProduct(v3,v1) v3 = geom.Vector3d.CrossProduct(v1,v2)
v1.Unitize() v2.Unitize() v3.Unitize() t = geom.Transform.Identity t.M00 = v1.X*s t.M10 = v1.Y*s t.M20 = v1.Z*s
t.M01 = v2.X*s t.M11 = v2.Y*s t.M21 = v2.Z*s
t.M02 = v3.X*s t.M12 = v3.Y*s t.M22 = v3.Z*s
t.M03 = p0.X t.M13 = p0.Y t.M23 = p0.Z
return t '''get points from first and last point of first curve in input list''' p0 = c[0].PointAtStart p1 = c[0].PointAtEnd
'''list for storing transformed geometry''' geomOutput = []
'''calculating inital scaling value based on distance between first and last point''' s = (p1-p0).Length/100
'''loop through count set by input slider''' for i in range(0,count): '''create a duplicate of input geomety, calculate the transformation and apply to the duplicate''' gC = g.Duplicate(); t = TransformFrom2Points(p0,p1,s) gC.Transform(t) geomOutput.append(gC)
'''calculate the placement based on the bounding box of the input geometry''' bbox = geomOutput[i].GetBoundingBox(geom.Plane.WorldXY) center = bbox.Center center.Z = center.Z-stackingOffset '''set points for next transformation relative to the bounding box of the previously transformed geometry''' diff = center-p0 p0 = center p1 = p1+diff s = s + soffset
a = geomOutput
Printing:
I printed the smallest and the second smallest object for demonstration. The bed leveling test took sometime and resulting printing is good after some adjustment.