Skip to content

Instantly share code, notes, and snippets.

@yasushisakai
Last active December 23, 2015 09:59
Show Gist options
  • Save yasushisakai/6618355 to your computer and use it in GitHub Desktop.
Save yasushisakai/6618355 to your computer and use it in GitHub Desktop.
polar diagram WORK IN PROGRESS
import rhinoscriptsyntax as rs
import math
#再利用出来るように
#なるだけ関数として書くこと!!だらだら書かない!
#plots a point in the Polar Diagram
def plotToPolarGraph(_eye,_target,_graphRadius=1000.0):
angles=rs.Angle(_eye,_target)
orientation = angles[0]
elevationAngle = angles[1]
direction=[math.cos(math.radians(orientation)),
math.sin(math.radians(orientation)),
0.0]
direction=[xyz*((1.0-(elevationAngle/90))*_graphRadius) for xyz in direction]
eye=rs.PointCoordinates(_eye)
return rs.AddPoint(direction[0]+eye.X,direction[1]+eye.Y,direction[2]+eye.Z)
#plots a line in the Polar Diagram
def drawPolarGraph(_eye,_target,_graphRadius=1000.0):
angles=rs.Angle(_eye,_target)
orientation = angles[0]
elevation = [angles[1]/90.0]*3
_eye=rs.PointCoordinates(_eye)
line = rs.AddLine(_eye,[_eye.X+_graphRadius,_eye.Y,_eye.Z])
rs.RotateObject(line,_eye,orientation)
rs.ScaleObject(line,rs.CurveEndPoint(line),elevation)
return line
#project a line to a PolarDiagram
#the result will be a polyline(the _lineDivision will configure the smoothness)
def drawPolarGraphCurve(_eye,_curve,_graphRadius=1000.0,_lineDivision=30):
#divide the Curve into fragments, then create a polyline(from lineDivision)
points=[ plotToPolarGraph(_eye,p,_graphRadius) for p in rs.DivideCurve(_curve,_lineDivision)]
#return the given Polyline (sort it)
return rs.AddPolyline(rs.SortPointList(points))
#draw a Polar Diagram for one surface
#this will return a polyline
def drawPolarGraphSurface(_eye,_surface,_graphRadius=1000.0,_lineDivision=30):
#get the poins of the Surface
surfaceEdges=rs.DuplicateEdgeCurves(_surface)
polarDEdges=[ drawPolarGraphCurve(_eye,sf,_graphRadius,_lineDivision) for sf in surfaceEdges]
#join it
return rs.JoinCurves(polarDEdges)
#draw a PolarDiagm for one polySurface
#the last variable shows wheather to 'region union' the result
def drawPolarGraphPolySurface(_eye,_polysurface,_graphRadius=1000.0,_lineDivision=30,_unionFlag=True):
surfaces=rs.ExplodePolysurfaces(_polysurface)
psEdges=[]
for ps in surfaces:
psEdges.append(drawPolarGraphSurface(_eye,ps,_graphRadius,_lineDivision=30))
if not _unionFlag:
return psEdges
else:
print psEdges
return rs.CurveBooleanUnion(psEdges)[0]
#draw a PolarDiagram for multi-Breps
#the last variable shows wheater to 'region union ' the result
def drawPolarGraphMultipleBrep(_eye,_brep,_graphRadius=1000.0,_lineDivision=30,_unionFlag=True):
brepEdges=[]
for b in _brep:
brepEdges.append(drawPolarGraphPolySurface(_eye,b,_graphRadius,_lineDivision,True))
if not _unionFlag:
return brepEdges
else:
return rs.CurveBooleanUnion(brepEdges)[0]
diagrams=[]
circles=[]
for p in points:
circles.append(rs.AddCircle(p,radius))
for bE in drawPolarGraphMultipleBrep(p,breps,radius,30,False):
diagrams.append(bE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment