def getAxis2AxisRotation(a0, a1): """Given 2 vectors return the rotation that is needed to transfer 1 into the other. """ # TODO: how to know which angle is taken (if you switch the axes, will you # still have to correct angle and axis?) vec3Type = type(GeomTypes.Vec3([0, 0, 0])) assert (type(a0) == vec3Type) and (type(a1) == vec3Type) if a0 == a1: # if both axis are in fact the same no roation is needed axis = GeomTypes.uz angle = 0 if a0 == -a1: # if one axis should be rotated in its opposite axis, handle # separately, since the cross product will not work. # rotate pi around any vector that makes a straight angle with a0 a2 = GeomTypes.Vec3([i + 0.5 for i in a1]) angle = math.pi axis = a2.cross(a0) else: a_0 = a0.normalize() a_1 = a1.normalize() n = a_0 * a_1 # because of floats there might be some rounding problems: n = min(n, 1.0) n = max(n, -1.0) angle = math.acos(n) axis = a_0.cross(a_1) return axis, angle
def xy2SphereV(x, y, w, h, R2): x, y = x - width / 2, height / 2 - y l2 = x * x + y * y if l2 < R2: spherePos = GeomTypes.Vec3([x, y, math.sqrt(R2 - l2)]) elif l2 > R2: scale = math.sqrt(R2 / l2) spherePos = GeomTypes.Vec3([scale * x, scale * y, 0]) else: # probably never happens (floats) spherePos = GeomTypes.Vec3([x, y, 0]) return spherePos
def updateOrientation(this): v = this.showGui[this.__AxisGuiIndex].GetVertex() if v == GeomTypes.Vec3([0, 0, 0]): rot = GeomTypes.E this.statusText( 'Rotation axis is the null-vector: applying identity', LOG_INFO) else: rot = GeomTypes.Rot3(axis=v, angle=Geom3D.Deg2Rad * this.currentAngle) try: this.shape.setBaseOrientation(rot) except AttributeError: this.statusText( 'Apply symmetry first, before pulling the slide-bar', LOG_WARN)
def GetSelected(this): """returns a symmetry instance""" sym = this.getSymmetryClass(applyOrder=False) setup = {} for i, gui in zip(range(len(this.oriGuis)), this.oriGuis): inputType = sym.initPars[i]['type'] if inputType == 'vec3': v = gui.GetVertex() if v != GeomTypes.Vec3([0, 0, 0]): setup[sym.initPars[i]['par']] = v elif inputType == 'int': v = gui.GetValue() setup[sym.initPars[i]['par']] = v #print 'GetSelected; setup:', setup #print 'class:', sym sym = sym(setup=setup) return sym
import Geom3D import GeomTypes import math Vs = [ GeomTypes.Vec3([ 1, 1, 1]), GeomTypes.Vec3([-1, 1, 1]), GeomTypes.Vec3([-1, -1, 1]), GeomTypes.Vec3([ 1, -1, 1]), GeomTypes.Vec3([ 1, 1, -1]), GeomTypes.Vec3([-1, 1, -1]), GeomTypes.Vec3([-1, -1, -1]), GeomTypes.Vec3([ 1, -1, -1]), GeomTypes.Vec3([ 1, 1, -2]), GeomTypes.Vec3([.5, 1, 1]), ] Fs = [ [0, 1, 2, 3], [0, 3, 7, 4], [1, 0, 4, 5], [2, 1, 5, 6], [3, 2, 6, 7], [7, 6, 5, 4] ] shape0 = Geom3D.SimpleShape(Vs = Vs, Fs = Fs) Vs = [ GeomTypes.Vec3([ 0, 0, 2]), GeomTypes.Vec3([ 2, 0, 0]),
T64: '64 Triangles', } def Vlen(v0, v1): x = v1[0] - v0[0] y = v1[1] - v0[1] z = v1[2] - v0[2] return (math.sqrt(x * x + y * y + z * z)) # get the col faces array by using a similar shape here, so it is calculated # only once useIsom = isometry.A4() egShape = Geom3D.IsometricShape(Vs=[ GeomTypes.Vec3([0, 0, 1]), GeomTypes.Vec3([0, 1, 1]), GeomTypes.Vec3([1, 1, 1]) ], Fs=[[0, 1, 2]], directIsometries=useIsom, unfoldOrbit=True) #colStabiliser = isometry.C2(setup = {'axis': [0.0, 1.0, 0.0]}) #colStabiliser = isometry.C2(setup = {'axis': [0.0, 0.0, 1.0]}) useSimpleColours = False colStabiliser = isometry.C2(setup={'axis': [1.0, 0.0, 0.0]}) colQuotientSet = useIsom / colStabiliser if useSimpleColours: useRgbCols = [ rgb.gray95, rgb.gray80,
import Geom3D import GeomTypes import math Vs = [ GeomTypes.Vec3([ 1, 1, 1]), GeomTypes.Vec3([-1, 1, 1]), GeomTypes.Vec3([-1, -1, 1]), GeomTypes.Vec3([ 1, -1, 1]), GeomTypes.Vec3([ 1, 1, -1]), GeomTypes.Vec3([-1, 1, -1]), GeomTypes.Vec3([-1, -1, -1]), GeomTypes.Vec3([ 1, -1, -1]), GeomTypes.Vec3([ 1, 1, -2]), GeomTypes.Vec3([.5, 1, 1]), ] Fs = [ [0, 4, 8], # just a line [0, 9, 1, 2, 3],# first part on line, cannot be used to calc face normal [0, 3, 7, 4], [1, 0, 4, 5], [2, 1, 5, 6], [3, 2, 6, 7], [7, 6, 5, 4] ] shape = Geom3D.SimpleShape(Vs = Vs, Fs = Fs)
# along with this program; if not, # check at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # or write to the Free Software Foundation, #-------------------------------------------------------------------- import wx import math import rgb import Heptagons import GeomTypes import Geom3D import Scenes3D Title = 'Equilateral Heptagons Tetrahedron' vec = lambda x, y, z: GeomTypes.Vec3([x, y, z]) V2 = math.sqrt(2) hV2 = 1.0/V2 tV3 = 1.0/math.sqrt(3) class Shape(Heptagons.EqlHeptagonShape): def __init__(this): Heptagons.EqlHeptagonShape.__init__(this, directIsometries = [ GeomTypes.E, GeomTypes.Hx, GeomTypes.Hy, GeomTypes.Hz ], name = 'EglHeptS4A4'
import GeomTypes import Geom3D import isometry shape = Geom3D.IsometricShape( Vs = [ GeomTypes.Vec3([1.0, 1.0, 1.0]), GeomTypes.Vec3([-1.0, 1.0, 1.0]), GeomTypes.Vec3([-1.0, -1.0, 1.0]), GeomTypes.Vec3([1.0, -1.0, 1.0]), GeomTypes.Vec3([1.0, 1.0, -1.0]), GeomTypes.Vec3([-1.0, 1.0, -1.0]), GeomTypes.Vec3([-1.0, -1.0, -1.0]), GeomTypes.Vec3([1.0, -1.0, -1.0]) ], Fs = [ [0, 1, 2, 3], [0, 3, 7, 4], [1, 0, 4, 5], [2, 1, 5, 6], [3, 2, 6, 7], [7, 6, 5, 4] ], Es = [0, 1, 1, 2, 2, 3, 0, 3, 3, 7, 4, 7, 0, 4, 4, 5, 1, 5, 5, 6, 2, 6, 6, 7], colors = [ ([[0.99609400000000003, 0.83984400000000003, 0.0]], []), ([[0.13281200000000001, 0.54296900000000003, 0.13281200000000001]], []), ([[0.54296900000000003, 0.0, 0.0]], []), ([[0.0, 0.74609400000000003, 0.99609400000000003]], []), ([[0.54296900000000003, 0.0, 0.0]], []), ([[0.13281200000000001, 0.54296900000000003, 0.13281200000000001]], []), ([[0.0, 0.74609400000000003, 0.99609400000000003]], []),
import GeomTypes import Geom3D import isometry shape = Geom3D.CompoundShape(simpleShapes=[ Geom3D.SimpleShape(Vs=[ GeomTypes.Vec3([1.0, 1.0, 1.0]), GeomTypes.Vec3([-1.0, 1.0, 1.0]), GeomTypes.Vec3([-1.0, -1.0, 1.0]), GeomTypes.Vec3([1.0, -1.0, 1.0]), GeomTypes.Vec3([1.0, 1.0, -1.0]), GeomTypes.Vec3([-1.0, 1.0, -1.0]), GeomTypes.Vec3([-1.0, -1.0, -1.0]), GeomTypes.Vec3([1.0, -1.0, -1.0]), GeomTypes.Vec3([1.0, 1.0, -2.0]), GeomTypes.Vec3([0.5, 1.0, 1.0]) ], Fs=[[0, 1, 2, 3], [0, 3, 7, 4], [1, 0, 4, 5], [2, 1, 5, 6], [3, 2, 6, 7], [7, 6, 5, 4]], Es=[], colors=([[0.99609400000000003, 0.0, 0.0]], [0, 0, 0, 0, 0, 0]), name="SimpleShape"), Geom3D.SimpleShape(Vs=[ GeomTypes.Vec3([0.0, 0.0, 2.0]), GeomTypes.Vec3([2.0, 0.0, 0.0]), GeomTypes.Vec3([0.0, 2.0, 0.0]), GeomTypes.Vec3([-2.0, 0.0, 0.0]), GeomTypes.Vec3([0.0, -2.0, 0.0]), GeomTypes.Vec3([0.0, 0.0, 2.0]) ], Fs=[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1],
def glDrawSingleRemoveUnscaledEdges(this): isScaledDown = not Geom3D.eq(this.c.scale, 1.0, margin=0.001) if not this.projectedTo3D: # print 'reprojecting...' try: del this.cell except AttributeError: pass Ns3D = [] if this.rot4 != None: Vs4D = [this.rot4 * v for v in this.Vs] # TODO fix Ns.. if needed.. # if this.Ns != []:cleanUp # Ns4D = [this.rot4*n for n in this.Ns] else: Vs4D = [v for v in this.Vs] Vs3D = this.projectVsTo3D(Vs4D) #for i in range(0, len(this.Es), 2): # v0 = Vs4D[this.Es[i]] # v1 = Vs4D[this.Es[i+1]] # print 'delta v:', v0 - v1 # print 'Edge [%d, %d]; len:' % (this.Es[i], this.Es[i+1]), (v1-v0).length() #if this.Ns != []: # Ns3D = this.projectVsTo3D(Ns4D) # Now project all to one 3D shape. 1 3D shape is chosen, instean of # projecting each cell to one shape because of different reasons: # - when drawing transparent faces all the opaqe fae should be # drawn first. # - if drawing the cells per shape, the glVertexPointer should be # called for each cell. (Currently SimpleShape will not call this # function unless the vertices have been changed... shapeVs = [] shapeEs = [] shapeFs = [] shapeColIndices = [] if this.c.draw: shapeCols = this.c.col[0] else: shapeCols = this.f.col[0] if this.removeTransparency: shapeCols = [c[0:3] for c in shapeCols] if this.e.draw and (not isScaledDown or this.e.showUnscaled): shapeVs = Vs3D shapeEs = this.Es # Add a shape with faces for each cell for i in xrange(len(this.Cs)): # use a copy, since we will filter (v indices will change): cellFs = [f[:] for f in this.Cs[i]] if this.c.draw: shapeColIndices.extend([this.c.col[1][i] for f in cellFs]) else: shapeColIndices.extend(this.f.col[1][i]) # Now cleanup Vs3D # TODO # if this.e.draw and (not isScaledDown or this.e.showUnscaled): # Then shapeVs = Vs3D already, and the code below is all # unecessary. cellVs = Vs3D[:] nrUsed = glue.cleanUpVsFs(cellVs, cellFs) # Now attaching to current Vs, will change index: offset = len(shapeVs) cellFs = [[vIndex + offset for vIndex in f] for f in cellFs] # Now scale from gravitation centre: if isScaledDown: g = GeomTypes.Vec3([0, 0, 0]) sum = 0 for vIndex in range(len(cellVs)): g = g + nrUsed[vIndex] * GeomTypes.Vec3(cellVs[vIndex]) sum = sum + nrUsed[vIndex] if sum != 0: g = g / sum #print this.name, 'g:', g cellVs = [ this.c.scale * (GeomTypes.Vec3(v) - g) + g for v in cellVs ] shapeVs.extend(cellVs) shapeFs.extend(cellFs) # for shapeColIndices.extend() see above this.cell = Geom3D.SimpleShape( shapeVs, shapeFs, shapeEs, [], # Vs , Fs, Es, Ns (shapeCols, shapeColIndices), name='%s_projection' % (this.name)) this.cell.setVertexProperties(radius=this.v.radius, color=this.v.col) this.cell.setEdgeProperties(radius=this.e.radius, color=this.e.col, drawEdges=this.e.draw) this.cell.setFaceProperties(drawFaces=this.f.draw) this.cell.glInitialised = True # done as first step in this func this.projectedTo3D = True this.updateTransparency = False if this.e.draw and isScaledDown: this.cell.recreateEdges() # Don't use, out of performance issues: # cellEs = this.cell.getEdgeProperties()['Es'] # -------------------------- # Bad performance during scaling: # cellEs = this.cell.getEdgeProperties()['Es'] # this.cell.recreateEdges() # cellEs.extend(this.cell.getEdgeProperties()['Es']) # -------end bad perf--------- cellEs = this.cell.Es if this.e.showUnscaled: cellEs.extend(this.Es) this.cell.setEdgeProperties(Es=cellEs) if this.updateTransparency: cellCols = this.cell.getFaceProperties()['colors'] if this.removeTransparency: shapeCols = [c[0:3] for c in cellCols[0]] else: if this.c.draw: shapeCols = this.c.col[0] else: shapeCols = this.f.col[0] cellCols = (shapeCols, cellCols[1]) this.cell.setFaceProperties(colors=cellCols) this.updateTransparency = False
def __init__(this, v0, v1, v2): this.v = [GeomTypes.Vec3(v0), GeomTypes.Vec3(v1), GeomTypes.Vec3(v2)] this.N = None
def GetVertex(this): return GeomTypes.Vec3([ this.__v[0].GetValue(), this.__v[1].GetValue(), this.__v[2].GetValue(), ])
only_hepts: 'Just Heptagons', } pos_angle_refl_2 = math.pi/2 def Vlen(v0, v1): x = v1[0] - v0[0] y = v1[1] - v0[1] z = v1[2] - v0[2] return (math.sqrt(x*x + y*y + z*z)) V2 = math.sqrt(2) V3 = math.sqrt(3) hV2 = V2/2 o4_fld_0 = GeomTypes.Vec3([1, 0, 0]) o4_fld_1 = GeomTypes.Vec3([0, 1, 1]) isomS4 = isometry.S4(setup = {'o4axis0': o4_fld_0, 'o4axis1': o4_fld_1}) o4fld = Rot(axis = o4_fld_1, angle = GeomTypes.qTurn) isomO4 = isometry.C4(setup = {'axis': o4_fld_1}) o3axis = GeomTypes.Vec3([1/V3, 0, V2/V3]) o3fld = Rot(axis = o3axis, angle = GeomTypes.tTurn) isomO3 = isometry.C3(setup = {'axis': o3axis}) # get the col faces array by using a similar shape here, so it is calculated # only once colStabilisers = [ isometry.D2(setup = { 'axis_n': [0.0, 0.0, 1.0], 'axis_2': [1.0, 0.0, 0.0],
def setV(this): Vt = [0, this.top, 0] Vb = [0, -this.tail, 0] Vl = [-this.side, 0, 0] Vr = [this.side, 0, 0] tuple = Heptagons.Kite2Hept(Vl, Vt, Vr, Vb) if tuple == None: return h0, h1, h2, h3, h4, h5, h6 = tuple[0] # # 3 0' # # # 6' 1' # # # 2 + 0 # # 5' 2' # # # # 4' 3' # # # 1 # this.kiteVs = [ GeomTypes.Vec3([Vr[0], Vr[1], Vr[2]]), GeomTypes.Vec3([Vb[0], Vb[1], Vb[2]]), GeomTypes.Vec3([Vl[0], Vl[1], Vl[2]]), GeomTypes.Vec3([Vt[0], Vt[1], Vt[2]]) ] d = 1e-4 this.heptaVs = [ GeomTypes.Vec3([Vt[0], Vt[1], Vt[2] + d]), GeomTypes.Vec3([h1[0], h1[1], h1[2] + d]), GeomTypes.Vec3([h2[0], h2[1], h2[2] + d]), GeomTypes.Vec3([h3[0], h3[1], h3[2] + d]), GeomTypes.Vec3([h4[0], h4[1], h4[2] + d]), GeomTypes.Vec3([h5[0], h5[1], h5[2] + d]), GeomTypes.Vec3([h6[0], h6[1], h6[2] + d]) ] # try to set the vertices array. # the failure occurs at init since showKite and showHepta don't exist try: Vs = [] print 'this.showKite', this.showKite, 'this.showHepta', this.showHepta if this.showKite: Vs.extend(this.kiteVs) if this.showHepta: Vs.extend(this.heptaVs) for v in Vs: print v print '===============' this.setVertexProperties(Vs=Vs) except AttributeError: pass
import GeomTypes import Geom3D import isometry shape = Geom3D.SimpleShape(Vs=[ GeomTypes.Vec3([1.0, 1.0, 1.0]), GeomTypes.Vec3([-1.0, 1.0, 1.0]), GeomTypes.Vec3([-1.0, -1.0, 1.0]), GeomTypes.Vec3([1.0, -1.0, 1.0]), GeomTypes.Vec3([1.0, 1.0, -1.0]), GeomTypes.Vec3([-1.0, 1.0, -1.0]), GeomTypes.Vec3([-1.0, -1.0, -1.0]), GeomTypes.Vec3([1.0, -1.0, -1.0]), GeomTypes.Vec3([1.0, 1.0, -2.0]), GeomTypes.Vec3([0.5, 1.0, 1.0]) ], Fs=[[0, 4, 8], [0, 9, 1, 2, 3], [0, 3, 7, 4], [1, 0, 4, 5], [2, 1, 5, 6], [3, 2, 6, 7], [7, 6, 5, 4]], Es=[], colors=([[0.99609400000000003, 0.0, 0.0]], [0, 0, 0, 0, 0, 0, 0]), name="SimpleShape")
def setV(this): # input this.h St = this.h / (Dtau2 * V3 * this.h - 3) #print 's', St # # 0 # __..--'-_ # 3 -'' . _"- 1 # \ _-' # \ _-' # \-' # 2 # # z y # ^ 7\ # |/ # ---> x # # # The kite above is a 5th of the top face of dodecahedron # standing on 1 face, 2 is a vertex, 1 and 3, centres of two edges # and 0 a face centre. # Vs = [ vec(0.0, 0.0, this.h), # 0 Rl, vec(0.0, -Dtau2 * St, St), vec(-Rl[0], Rl[1], Rl[2]) # 3 ] # add heptagons H = HalfTurn(Vs[3]) this.errorStr = '' if not this.heptPosAlt: Ns = Vs heptN = Heptagons.Kite2Hept(Vs[3], Vs[0], Vs[1], Vs[2]) if heptN == None: this.errorStr = 'No valid equilateral heptagon for this position' return Mr = Rot(axis=GeomTypes.Vec3(Vs[2]), angle=GeomTypes.turn(0.2)) # p is a corner of the pentagon inside the pentagram # p is rotated 1/5th turn to form a triangle # together with 2 corners of the pentagram: # 5 of these triangles will cover the pentagram. # this is easier than finding the centre of the pentagram. v3 = heptN[0][3] v4 = heptN[0][4] p = v3 + (v4 - v3) / tau v = Mr * p if this.triangleAlt: vt = heptN[0][6] xtraEdgeIndex = 15 else: vt = heptN[0][5] xtraEdgeIndex = 14 # A part that will form the regular pentagrams (with overlaps). RegularTrianglePartV = [ heptN[0][3], heptN[0][4], vec(v[0], v[1], v[2]), ] RegularTrianglePartN = Vs[2] # vt is the vertex that will be projected by a half turn on the # third vertex of the isosceles triangle. IsoscelesTriangleV = [heptN[0][5], heptN[0][6], vt] else: heptN = Heptagons.Kite2Hept(Vs[1], Vs[2], Vs[3], Vs[0]) if heptN == None: this.errorStr = 'No valid equilateral heptagon for this position' return if this.triangleAlt: vt = heptN[0][1] xtraEdgeIndex = 14 else: vt = heptN[0][2] xtraEdgeIndex = 15 # One third of regular triangle. RegularTrianglePartV = [ heptN[0][3], heptN[0][4], vec(0, 0, heptN[0][3][2]), ] RegularTrianglePartN = RegularTrianglePartV[2] # vt is the vertex that will be projected by a half turn on the # third vertex of the isosceles triangle. IsoscelesTriangleV = [heptN[0][1], heptN[0][2], vt] if heptN == None: this.errorStr = 'No valid equilateral heptagon for this position' return else: this.errorStr = '' vt = H * vt # rotate vt by a half turn, IsoscelesTriangleV NOT auto updated. IsoscelesTriangleV[2] = vt Vs.extend(heptN[0]) # V4 - V10, the heptagon Vs.extend(RegularTrianglePartV) # V11 - V13 Vs.extend(IsoscelesTriangleV) # V14 - V16 #for V in Vs: print V #h = heptN[1] #Ns = [[-h[0], -h[1], -h[2]] for i in range(11)] Ns = [heptN[1] for i in range(11)] Ns.extend([RegularTrianglePartN for i in range(3)]) IsoscelesTriangleN = Geom3D.Triangle(IsoscelesTriangleV[0], IsoscelesTriangleV[1], IsoscelesTriangleV[2]).normal() Ns.extend([IsoscelesTriangleN for i in range(3)]) this.xtraEs = [] if this.addXtraEdge: this.xtraEs = [xtraEdgeIndex, 16] #this.showBaseOnly = True this.setBaseVertexProperties(Vs=Vs, Ns=Ns) Fs = [] Es = [] colIds = [] if this.showKite: Fs.extend(this.kiteFs) Es.extend(this.kiteEs) colIds.extend(this.kiteColIds) if this.showHepta: Fs.extend(this.heptFs) Es.extend(this.heptEs) colIds.extend(this.heptColIds) if this.showXtra: Fs.extend(this.xtraFs) Es.extend(this.xtraEs) colIds.extend(this.xtraColIds) this.setBaseEdgeProperties(Es=Es) this.setBaseFaceProperties(Fs=Fs, colors=(this.theColors, colIds)) this.Vs = Vs
def getVector(this, i): return GeomTypes.Vec3([ this.__v[i][0].GetValue(), this.__v[i][1].GetValue(), this.__v[i][2].GetValue(), ])