Drawing geometries with salome

From Elmer Wiki
Jump to: navigation, search

Helix

This is an example how to draw a helix pipe.

Salome python script:

import geompy
import salome
import math

gg = salome.ImportComponentGUI("GEOM")

points = 50
radius = .016
pipeRadius = 0.00035
turnLength = 0.0032
numberOfturns = 3

def Helix(a, t):
	return [a*math.cos(t), a*math.sin(t), turnLength*t/(2*math.pi)]

def dHelix(a, t):
	return [a*math.sin(t), a*math.cos(t), turnLength/(2*math.pi)]

# create vertices
pointList=[]
for i in range(numberOfturns*points+1):
	Helixx = Helix(radius, 2*math.pi/points * i)
	pointList.append(geompy.MakeVertex(Helixx.pop(0), Helixx.pop(0), Helixx.pop(0)))

HelixCurve = geompy.MakeInterpol(pointList)

Helixx = tuple(Helix(radius, 0))
dHelixx = dHelix(radius, 0)

P1forVector = geompy.MakeVertex(Helixx[0], Helixx[1], Helixx[2])
P2forVector = geompy.MakeVertex(Helixx[0]+dHelixx.pop(0), Helixx[1]+dHelixx.pop(0), Helixx[2]+dHelixx.pop(0))

VectorForBaseCircle = geompy.MakeVector(P1forVector, P2forVector)

BaseCircle = geompy.MakeCircle(P1forVector, VectorForBaseCircle, pipeRadius)

CircleFace = geompy.MakeFace(BaseCircle, 1)

HelixPipe = geompy.MakePipe(CircleFace, HelixCurve)

# add objects in the study
#id_HelixCurve = geompy.addToStudy(HelixCurve, "Helix Curve")
#id_VectorForBase = geompy.addToStudy(VectorForBaseCircle, "Vector For Base Circle")
#id_BaseCircle = geompy.addToStudy(BaseCircle, "Base Circle")
#id_CircleFace = geompy.addToStudy(CircleFace, "Base Circle Face")
id_HelixPipe = geompy.addToStudy(HelixPipe, "Helix Pipe")

gg.createAndDisplayGO(id_HelixPipe)