-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
82 lines (51 loc) · 1.48 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import rhinoscriptsyntax as rs
import Rhino.Geometry.Interval as Interval
import Rhino.Geometry.Intersect.Intersection as Intersection
def MovePt2PtBasedOnSrf(fromPt, toPt, toSrf):
u,v = rs.SurfaceClosestPoint(toSrf, toPt)
vt = rs.VectorCreate(toPt, fromPt)
vt = rs.VectorUnitize(vt)
c = rs.SurfaceCurvature(toSrf, (u, v))
c = c[7]
vt = rs.VectorScale(vt, 10*c)
return rs.PointAdd(toPt, vt)
#eof
def projectPtOnSrf(attractorPt, targetSrf, pt):
r = rs.AddLine(attractorPt, pt)
r = rs.ScaleObject(r, attractorPt, (10, 10,10))
dom = rs.CurveDomain(r)
crv = rs.coercecurve(r)
srf = rs.coercesurface(targetSrf).ToNurbsSurface()
inv = Interval(dom[0], dom[1])
rs.DeleteObject(r)
xobj = Intersection.CurveSurface(crv, inv, srf, 0.1, 1)
return xobj[0].PointB
#eof
def averagePt(ptList):
x = 0
y = 0
z = 0
for pt in ptList:
x+= pt.X
y+= pt.Y
z+= pt.Z
x /= len(ptList)
y /= len(ptList)
z /= len(ptList)
return (x,y,z)
#eof
def makeEngravingFont(txt):
return rs.ExplodeText(txt, True)
#eof
def getCurvatureOfClosestPoint(pt, srf, scale=None):
if scale is None:
global curvatureScale
scale = curvatureScale
u,v = rs.SurfaceClosestPoint(srf, pt)
c = rs.SurfaceCurvature(srf, (u, v))
if c is None:
return 0
else:
return c[7]*scale
#eof
curvatureScale = 15