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(1,0,0)
    v2 = geom.Vector3d.CrossProduct(v1,v3)
    v3 = geom.Vector3d.CrossProduct(v2,v1)

    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.PointAtStart
p1 = c.PointAtEnd

'''list for storing transformed geometry'''
geomOutput = []

'''calculating inital scaling value based on distance between first and last point'''
maxScaleW = abs((p1-p0).Length/10)

maxScaleWRange = maxScaleW-0.6;
scaleIncW = abs((maxScaleWRange/count));
sW = maxScaleW

stackOffset = 10
'''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();
    sW-= scaleIncW

    t = TransformFrom2Points(p0,p1,sW)
    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
  
    '''create a new point offset from the center of the previous geometry'''
    centerOffset = rs.CreatePoint(center.X,center.Y,(stackOffset+1)*(i+1))
    diff = centerOffset-p0
    
    '''set points for next transformation relative to the bounding box of the previously transformed geometry'''
    diff = centerOffset-p0
    p0 = centerOffset
    p1 = p1+diff

    
a = geomOutput