← Back to team overview

yade-users team mailing list archive

Re: [Question #691976]: gtsPFacet

 

Question #691976 on Yade changed:
https://answers.launchpad.net/yade/+question/691976

    Status: Open => Answered

Jan Stránský proposed the following answer:
###
import gts
center = (0,0,0)
radius = 1
height = 2

# triangles as yade facets, can be anything else, e.g. custom class
facets = geom.facetCylinder(center,radius,height)

# yade facet to gts.Face
def f2f(f): 
    p = f.state.pos
    o = f.state.ori
    vs = [p+o*v for v in f.shape.vertices] # vertices in global coordinates
    vs = [gts.Vertex(v[0],v[1],v[2]) for v in vs] # Vector3 -> gts.Vertex
    es = [gts.Edge(v,vs[(i+1)%3]) for i,v in enumerate(vs)] # gts edges
    f = gts.Face(*es) # gts Face
    return f
faces = [f2f(f) for f in facets]

# gts Surface
surf = gts.Surface()
for f in faces: # filled with faces
    surf.add(f)
print(surf.is_ok(),surf.is_closed(),surf.is_orientable())
surf.cleanup(1e-6) # needs cleanup to merge "almost same vertices"
print(surf.is_ok(),surf.is_closed(),surf.is_orientable())

# save
with open("cyl.gts","w") as f:
    surf.write(f)
###

cheers
Jan

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.