Mesh Mathematical Surface

Hi friends, I’m looking to create a script from python and grasshopper but I don’t understand what the error is, I got a “Non_ACIIS” message at first, apparently I located the error but I can’t build the surface, I use rhino 6.
surface_from_math.gh (4.9 KB)

Thanks and good weekend :slight_smile:

I saw an error with getting the inputs from the GH Python component, fixing this seems to work.

import Rhino as rh
import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
import math 
import System as sys
import scriptcontext as sc
 
from random import random
from scriptcontext import escape_test

def boySurface(a, r, domainXY, resolutionXY):
    vertex = []
    for i in range(resolutionXY[0]+1):
        u = domainXY[0] + (domainXY[1]-domainXY[0])*i/resolutionXY[0]
        for j in range(resolutionXY[1]+1):
            v = domainXY[2] + (domainXY[3]-domainXY[2])*j/resolutionXY[1]
            b = 2 - r*math.sqrt(2)*math.sin(3*u)*math.sin(2*v) 
            x = a * ( math.sqrt(2) * math.cos(2*u) * math.pow(math.cos(v),2) + math.cos(u) * math.sin(2*v) ) / b
            y = a * ( math.sqrt(2) * math.sin(2*u) * math.pow(math.cos(v),2) - math.sin(u) * math.sin(2*v) ) / b
            z = a* 3 *  math.pow(math.cos(v),2) / b
            vertex.append( (x,y,z) )
    return vertex
 
def createmeshfaces(resolutionXY):
    nX = resolutionXY[0]
    nY = resolutionXY[1]
    f = []
    for i in range(nX): 
        for j in range(nY):
            baseindex = i*(nY+1)+j
            A = baseindex
            B = baseindex+1
            C = baseindex+nY+2
            D = baseindex+nY+1
            f.append( (A, B, C, D) )
    return f

def meshfunction_xy(a, r):
    domain = (-math.pi, 0, -math.pi, 0)
    resolutionXY = (30,10)
    verts = boySurface(a, r, domain, resolutionXY)
    faces = createmeshfaces(resolutionXY)
     
    return rs.AddMesh(verts, faces)

a  = meshfunction_xy(x, r)
1 Like