Exemple #1
0
def MultiplyTest():
    c = basetypes.TCoord(0, 1, 2)
    c = geomutils.Multiply(c, 2)
    print(str(c[0]) + ' ' + str(c[1]) + ' ' + str(c[2]))

    print('')
    fa = [3.0, 6.0, 4.0]
    fa = geomutils.Multiply(fa, 2)
    for f in range(len(fa)):
        print(str(fa[f]))

    print('')
    ca = []
    c = basetypes.TCoord(3, 8, 1)
    ca.append(c)
    c = basetypes.TCoord(6, 4, 6)
    ca.append(c)
    c = basetypes.TCoord(0, 2, 5)
    ca.append(c)
    ca = geomutils.Multiply(ca, 2)
    for f in range(len(ca)):
        print(str(ca[f][0]) + ' ' + str(ca[f][1]) + ' ' + str(ca[f][2]))

    print('')
    q1 = geomutils.TQuaternion(2, 4, 3, 5)
    q2 = geomutils.TQuaternion(1, 3, 5, 2)
    q1 = geomutils.Multiply(q1, q2)
    print(str(q1[0]) + ' ' + str(q1[1]) + ' ' + str(q1[2]) + ' ' + str(q1[3]))

    print('')
    r1 = geomutils.TRotMatrix(2, 4, 5, 3, 1, 1, 3, 2, 2)
    r2 = geomutils.TRotMatrix(3, 1, 1, 2, 5, 5, 4, 2, 3)
    r1 = geomutils.Multiply(r1, r2)
    print(str(r1[0, 0]) + ' ' + str(r1[0, 1]) + ' ' + str(r1[0, 2]) + '\n' + str(r1[1, 0]) + ' ' + str(r1[1, 1]) + ' '
          + str(r1[1, 2]) + '\n' + str(r1[2, 0]) + ' ' + str(r1[2, 1]) + ' ' + str(r1[2, 2]))
    def EuclideanDistanceConstraint(self, ATargetPoints, AProbePoints, Dist):
        tres = 1 / self.FTargetResolution
        pres = 1 / self.FProbeResolution
        targetpoints = geomutils.Multiply(
            geomutils.Add(self.FTargetTransVec, ATargetPoints), tres)
        probepoints = geomutils.Add(
            basetypes.TCoord(self.FDomainBlock.XOffset,
                             self.FDomainBlock.YOffset,
                             self.FDomainBlock.ZOffset),
            geomutils.Multiply(
                geomutils.Add(self.FProbeTransVec, AProbePoints), pres))
        mit = basetypes.Min(targetpoints)
        mat = basetypes.Max(targetpoints)
        mip = basetypes.Min(probepoints)
        map = basetypes.Max(probepoints)
        griddist = Dist / self.FTargetResolution
        distsquare = griddist**2

        lx1 = round(mit[0] - map[0] - 0.5 - griddist)
        lx2 = round(mat[0] - mip[0] + 0.5 + griddist)
        linegrids.Intersect(self.FXDomain, lx1, lx2)
        # Clear FYDomainAtX outside FXDomain
        oldix = 0
        for x in range(len(self.FXDomain)):
            for xx in range(oldix, self.FXDomain[x][0]):
                self.FYDomainAtX[xx] = []
            oldix = self.FXDomain[x][1] + 1
        for xx in range(oldix, len(self.FYDomainAtX)):
            self.FYDomainAtX[xx] = []

        # Set FYDomainAtX
        for x in range(len(self.FXDomain)):
            for xx in range(self.FXDomain[x][0], self.FXDomain[x][1] + 1):
                ly1, ly2 = self.SetYLimits(xx, targetpoints, probepoints,
                                           griddist, distsquare)
                linegrids.Intersect(self.FYDomainAtX[xx], ly1, ly2)

                # Clear FZDomainAtXY outside FYDomainAtX
                oldix = 0
                for y in range(len(self.FYDomainAtX[xx])):
                    for yy in range(oldix, self.FYDomainAtX[xx][y][0]):
                        self.FZDomainAtXY[xx][yy] = []
                    oldix = self.FYDomainAtX[xx][y][1] + 1
                for yy in range(oldix, len(self.FZDomainAtXY[xx])):
                    self.FZDomainAtXY[xx][yy] = []

                # Set FZDomainAtXY
                for y in range(len(self.FYDomainAtX[xx])):
                    for yy in range(self.FYDomainAtX[xx][y][0],
                                    self.FYDomainAtX[xx][y][1]):
                        lz1, lz2 = self.SetZLimits(xx, yy, targetpoints,
                                                   probepoints, griddist,
                                                   distsquare)
                        linegrids.Intersect(self.FZDomainAtXY[xx][yy], lz1,
                                            lz2)
    def LinearDistanceConstraint(self, ATargetPoints, AProbePoints, Dist):
        targetpoints = geomutils.Add(self.FTargetTransVec, ATargetPoints)
        probepoints = geomutils.Add(self.FProbeTransVec, AProbePoints)
        tres = 1 / self.FTargetResolution
        pres = 1 / self.FProbeResolution

        mit = geomutils.Multiply(basetypes.Min(targetpoints), tres)
        mat = geomutils.Multiply(basetypes.Max(targetpoints), tres)
        mip = geomutils.Multiply(basetypes.Min(probepoints), tres)
        map = geomutils.Multiply(basetypes.Max(probepoints), tres)
        d = Dist / self.FTargetResolution

        lx1 = round(mit[0] - map[0] - self.FDomainBlock.XOffset - 0.5 - d)
        lx2 = round(mat[0] - mip[0] - self.FDomainBlock.XOffset + 0.5 + d)
        ly1 = round(mit[1] - map[1] - self.FDomainBlock.YOffset - 0.5 - d)
        ly2 = round(mat[1] - mip[1] - self.FDomainBlock.YOffset + 0.5 + d)
        lz1 = round(mit[2] - map[2] - self.FDomainBlock.ZOffset - 0.5 - d)
        lz2 = round(mat[2] - mip[2] - self.FDomainBlock.ZOffset + 0.5 + d)
        linegrids.Intersect(self.FXDomain, lx1, lx2)

        # Clear FYDomainAtX outside FXDomain
        oldix = 0
        for x in range(len(self.FXDomain)):
            for xx in range(oldix, self.FXDomain[x][0]):
                self.FYDomainAtX[xx] = []
            oldix = self.FXDomain[x][1] + 1
        for xx in range(oldix, len(self.FYDomainAtX)):
            self.FYDomainAtX[xx] = []

        # Set FYDomainAtX
        for x in range(len(self.FXDomain)):
            for xx in range(self.FXDomain[x][0], self.FXDomain[x][1] + 1):
                linegrids.Intersect(self.FYDomainAtX[xx], ly1, ly2)
                # Clear FZDomainAtXY outside FYDomainAtX
                oldix = 0
                for y in range(len(self.FYDomainAtX[xx])):
                    for yy in range(oldix, self.FYDomainAtX[xx][y][0]):
                        self.FZDomainAtXY[xx][yy] = []
                    oldix = self.FYDomainAtX[xx][y][1] + 1
                for yy in range(oldix, len(self.FYDomainAtX[xx])):
                    self.FZDomainAtXY[xx][yy] = []

                # Set FZDomainAtXY
                for y in range(len(self.FYDomainAtX[xx])):
                    for yy in range(self.FYDomainAtX[xx][y][0],
                                    self.FYDomainAtX[xx][y][1] + 1):
                        linegrids.Intersect(self.FZDomainAtXY[xx][yy], lz1,
                                            lz2)
Exemple #4
0
def EulerSampleZYX(ZSteps):
    # Get ZSteps^2 points uniformly distributed around a sphere
    Result = []
    for z in range(ZSteps):
        qz = geomutils.RotationQuaternion(basetypes.TCoord(0, 0, 1),
                                          2 * geomutils.PI / ZSteps * z)
        for y in range(ZSteps):
            qy = geomutils.RotationQuaternion(basetypes.TCoord(0, 1, 0),
                                              2 * geomutils.PI / ZSteps * y)
            for x in range(int(ZSteps / 2) - 1):
                qx = geomutils.RotationQuaternion(
                    basetypes.TCoord(1, 0, 0), 2 * geomutils.PI / ZSteps * x)
                Result.append(
                    geomutils.Multiply(geomutils.Multiply(qz, qy), qx))
    # Return TQuaternions
    return Result
Exemple #5
0
 def FirstTranslation(self, InitialPoint):
     FF = basetypes.TCoord()
     for f in range(len(self.FFixed)):
         FF = geomutils.Add(FF, self.FFixed[f])
     if len(self.FFixed) > 0:
         FF = geomutils.Multiply(FF, 1 / len(self.FFixed))
         for f in range(3):
             InitialPoint[f + 3] = FF[f]
Exemple #6
0
 def Center(self):
     self.FCenterVec = basetypes.TCoord()
     for f in range(len(self.FMobile)):
         self.FCenterVec = geomutils.Add(self.FCenterVec, self.FMobile[f])
     if len(self.FMobile) > 0:
         self.FCenterVec = geomutils.Multiply(self.FCenterVec,
                                              1 / len(self.FMobile))
     for f in range(len(self.FMobile)):
         self.FMobile[f] = geomutils.Subtract(self.FMobile[f],
                                              self.FCenterVec)
Exemple #7
0
 def ListNeighbours(self, C):
     C = geomutils.Multiply(geomutils.Add(C, self.FShiftToGrid),
                            self.FInvGridStep)
     Result = []
     x1, x2 = self.GridBounds(C[0], self.FHighX)
     y1, y2 = self.GridBounds(C[1], self.FHighY)
     z1, z2 = self.GridBounds(C[2], self.FHighZ)
     for x in range(x1, x2 + 1):
         for y in range(y1, y2 + 1):
             for z in range(z1, z2 + 1):
                 for f in range(len(self.FHashGrid[x][y][z])):
                     Result.append(self.FHashGrid[x][y][z][f])
     # Return TIntegers
     return Result
 def PlaneConstraint(self, Point, Normal, Margin):
     # Scaling factors for the shapes
     tres = 1 / self.FTargetResolution
     pres = 1 / self.FProbeResolution
     # Plane and line variables
     planepoint = geomutils.Subtract(
         geomutils.Add(Point, geomutils.Multiply(self.FTargetTransVec,
                                                 tres)),
         geomutils.Multiply(self.FProbeTransVec, pres))
     planepoint = geomutils.Subtract(
         planepoint,
         basetypes.TCoord(self.FDomainBlock.XOffset,
                          self.FDomainBlock.YOffset,
                          self.FDomainBlock.ZOffset))
     xflags = basetypes.FilledInts(self.FDomainBlock.DomainEndX + 1, -1)
     yflags = basetypes.FilledInts(self.FDomainBlock.DomainEndY + 1, -1)
     zflags = basetypes.FilledInts(self.FDomainBlock.DomainEndZ + 1, -1)
     for x in range(len(self.FXDomain)):
         for xx in range(self.FXDomain[x][0], self.FXDomain[x][1] + 1):
             self.SetYDomain(xx, yflags, zflags, planepoint, Normal, Margin)
             if self.FYDomainAtX[xx] is not None and (len(
                     self.FYDomainAtX[xx]) != 0):
                 xflags[xx] = 1
     self.FXDomain = linegrids.IntegersToLine(xflags)
Exemple #9
0
 def IsInnerPoint(self, C):
     tmpc = geomutils.Multiply(geomutils.Add(C, self.FShiftToGrid),
                               self.FInvGridStep)
     Result = False
     x1, x2 = self.GridBounds(tmpc[0], self.FHighX)
     y1, y2 = self.GridBounds(tmpc[1], self.FHighY)
     z1, z2 = self.GridBounds(tmpc[2], self.FHighZ)
     for x in range(x1, x2 + 1):
         for y in range(y1, y2 + 1):
             for z in range(z1, z2 + 1):
                 for f in range(len(self.FHashGrid[x][y][z])):
                     ix = self.FHashGrid[x][y][z][f]
                     if geomutils.Distance(
                             C, self.FPoints[ix]) < self.FRads[ix]:
                         Result = True
                         break
                 if Result:
                     break
             if Result:
                 break
         if Result:
             break
     # Return Boolean
     return Result
Exemple #10
0
 def CurrentRotation(self):
     # Return TRotMatrix
     return geomutils.Multiply(
         geomutils.BuildRotation(self.FRotation, geomutils.MCXYZRotation),
         self.FBaseRotation)