Hello everyone! I am trying to write a script for finding the closest point of a curve. I try to generate a point that has random coordinates on rhino canvas and then test if it is inside a given area.If it is outside of the given area I want it to be projected on the closest point of the area borders,and then have a random walk towards the center of the area (this part of the code is not solved yet).I have a problem though in converting the GUID to Point coordinates. I know its an easy task but I seem to have stuck. I attach the code(the area is given and the curve is the border of the area)
Thanking everyone in advance
The script is the following
import rhinoscriptsyntax as rs
import random as r
from Rhino import Geometry
class Walker:
def __init__(self):
self.x=r.randint(-20,20)
self.y=r.randint(-20,20)
self.z=0
def point(self):
shape=rs.AddPoint(self.x,self.y,self.z)
return shape
def update(self):
choice=r.randint(0,3)
if (choice==0):
self.x+=1
elif(choice==1):
self.x-=1
elif(choice==2) :
self.y+=1
else:
self.y-=1
def project(self,area,curve):
point=(self.x,self.y,self.z)
check=rs.IsPointInSurface(area,point)
if check:
self.x=self.x
self.y=self.y
else:
closest=rs.CurveClosestPoint(curve,point)
cp=rs.AddPoint(closest)
point=point+cd
def test(self):
print self.x,self.y
w=Walker()
for t in range(time):
w.test()
w.project(area,curve)
a=w.point()
w.update()