에서 임의의 요소를 선택 별도의 가지에있는 다른 임의의 지점으로 "지점". 한 라인이 만들어지면 두 지점의 위치 지점은 향후 라인 생성에 사용할 수 없게됩니다.반복 :</p> <pre><code>tree = [[[x,y],[x,y],[x,y]], [[x,y],[x,y],[x,y]], [[x,y],[x,y],[x,y]]] </code></pre> <p>내 목표는 각 임의 점에서 더욱 라인을 연결하는 것입니다 ("매트릭스"또는) 라인 위치 점의 무리를 포함 나는 나무가 무작위 목록
random.shuffle()을 사용하여 점 반복을 임의화할 수 있었지만 현재 한 번에 하나의 분기 만 가져 와서 한 번에 하나의 인접 분기 만 가진 점을 비교하고 있습니다. 이것은 하나의 브랜치에서 첫 번째 브랜치로 연결되는 많은 라인을 제공하지만, 나는 많은 브랜치에 연결하여 모든 곳에서 원한다.
여기까지 제가 지금까지 가지고 있습니다. 이 기능은 Cinema 4D의 기본 기능입니다. 검색 가능한 API는 다음에서 찾을 수 있습니다. https://developers.maxon.net/docs/Cinema4DPythonSDK/html/index.html 함수 GetSplinePoint()는 단순히 스플라인 (3D 선) 객체의 위치를 반환합니다.
rand_pts = [_ for _ in xrange(spline_resolution)]
for p_spline in xrange(len(splines)):
random.shuffle(rand_pts)
for p in rand_pts:
if p == 0 or p == spline_resolution-1 or occupied[p_spline][p] == True: continue
mindist = 99999
new_connection = False
p_amt = c4d.utils.RangeMap(p, 0, spline_resolution-1, 0, 1, False)
p_pt = spline_objs[p_spline].GetSplinePoint(p_amt)
for n_spline in xrange(len(splines)):
if n_spline != p_spline:
random.shuffle(rand_pts)
for n in rand_pts:
if n == 0 or n == spline_resolution-1 or occupied[n_spline][n] == True: continue
n_amt = c4d.utils.RangeMap(n, 0, spline_resolution-1, 0, 1, False)
n_pt = spline_objs[n_spline].GetSplinePoint(n_amt)
dist = (p_pt - n_pt).GetLength()
if dist < op[c4d.ID_USERDATA,5] and dist < mindist:
mindist = dist
new_connection = True
break
첫 번째 줄에는 쉼표가 없습니다. – Wolf
그렇게 생각하지 마십시오. – tanzola
좋아요, 실제로 첫 줄에 * * 고정되어 있지 않았습니다. – Wolf