Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize koch Curve in ghpython

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to realize the koch curve in ghpython? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

First of all, take the basic polygon as the initial line and blow it up, because each line has to be fractal later.

After a fierce operation of ghpython, the fractal lines are grouped according to the number of recursions. Finally, the fractal lines are join, scaled and colored respectively.

# Snowflake Fractal import rhinoscriptsyntax as rsfrom Grasshopper import DataTreefrom Grasshopper.Kernel.Data import GH_Pathimport ghpythonlib.treehelpers as gt# function 1, which defines a function def fractal (line) that divides straight lines into equal parts, moves equal points and connects them into broken lines: # divides straight lines into three equal parts Get four points pts=rs.DivideCurve (line,3,False,True) # rotate the third point around the second point-60 °pt_rotate=rs.RotateObject (pts [2], pts [1],-60) # insert the rotated point into the position where the index value is 2 in the list of equivalents pts.insert (2dint) # generate a Polyline from the point Then blow up the Polyline pl=rs.AddPolyline (pts) pl_ex=rs.ExplodeCurves (pl,True) # return the exploded Polyline return pl_exnum=0 # set the initial counter lst_data= data tree [object] () # establish an empty tree data list # function 2, call function 1 to pair of straight line fractals, and add fractal data to the tree data list Note the choice of path number # so that all fractal lines of function 2 can be placed under the same path def mul_fractal (lines): # global variable, which is used to set the path number global num num+=1 lst= [] # to traverse all lines of the calling function. And append to the list for i in lines: lst.extend (fractal (I)) # put the list data into the tree data lst_data.AddRange (lst,GH_Path (num)) return lst# function 3, the main function, used to set the fractal number def main (lines,count): # if the fractal number is 0, then directly return the original line if count==0: return lines # if the fractal number is 1 As a recursive exit, return the fractal line if count==1: return mul_fractal (lines) # if the fractal number is greater than 1, then call the main function itself, minus 1 until the fractal number is 1, reach the recursive exit # and then return the recursive fractal data else: return mul_fractal (main (lines,count-1)) # call the main function to get the fractal line. Add the initial line to the first branch of the fractal tree data fractal_lines=main (lines,count) lst_data.AddRange (lines,GH_Path (0)) # traverse according to the number of branches of the tree data # move the data of each branch up for i in range (lst_data.BranchCount): rs.MoveObjects (lst_data.Branch (I), (0Power0) height)) the answer to the question about how to implement the koch curve in ghpython is shared here I hope the above content can help you to a certain extent, if you still have a lot of doubts to be solved, you can follow the industry information channel to learn more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report