当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.append方法代码示例

本文整理汇总了Python中Matrix.Matrix.append方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.append方法的具体用法?Python Matrix.append怎么用?Python Matrix.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Matrix.Matrix的用法示例。


在下文中一共展示了Matrix.append方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Truss

# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import append [as 别名]
class Truss(object):
    def __init__(self, nodes = [], members = []):
        self.nodes = nodes
        self.members = members
    def createNode(self, position):
        self.addNode(Node(position))
    def addNode(self, node):
        if node in self.nodes:
            raise Exception("Tried to add the  " + str(node) + \
                            " to the truss \n" + str(self) + \
                            " but it was already there")
        else:
            self.nodes.append(node)
    def getNodeAt(self, position):
        tempNode = Node(position)
        for node in self.nodes:
            if tempNode == node:
                return node
        return None
    def getNodeNear(self, position, radius):
        p = Vector(position)
        nodesAndDistances = [(n.distance(p), n) for n in self.nodes]
        if len(nodesAndDistances) == 0:
            return None
        nearestNode = min(nodesAndDistances)[1]
        if nearestNode.distance(p) < radius:
            return nearestNode
        else:
            return None
    def getMemberWithNodes(self, node1, node2):
        for member in self.members:
            if sameElements([node1, node2], [member.node1, member.node2]):
                return member
        return None
    def getMembersWithNode(self, node):
        return [member for member in self.members if member.hasNode(node)]
    def getMemberNear(self, position, radius):
        p = Vector(position)
        membersAndDistances = [(m.distance(p), m) for m in self.members]
        if len(membersAndDistances) == 0:
            return None
        nearestMember = min(membersAndDistances)[1]
        if (nearestMember.distance(p) < radius):
            return nearestMember
        else:
            return None
    def deleteNode(self, node):
        for n in self.nodes:
            if node == n:
                self.nodes.remove(n)
                self.deleteMembers(n)
                return
        raise Exception("The node %s does not exist in %s" % (str(node), str(self)))
    def deleteMembers(self, node):
        toDelete = self.getMembersWithNode(node)
        for member in toDelete:
            self.deleteMember(member)
    def deleteMember(self, member):
        self.members.remove(member)
    def connectNodes(self, node1, node2):
        if (node1 == node2):
            raise Exception("The two nodes are equivalent")
        newMember = Member(node1, node2)
        if newMember not in self.members:
            if node1 in self.nodes and node2 in self.nodes:
                self.members.append(newMember)
            else:
                raise Exception("Tried to add the  " + str(newMember) + \
                                 " to the truss, but those nodes don't exist")
        else:
            raise Exception("Tried to add the  " + str(newMember) + \
                            " to the truss, but it was already there")
    def computeForces(self):
        self.getEquilibriumMatrix()
        self.solveMatrix()
        for c in range(self.matrix.width - 1):
            self.members[c].force = self.matrix[c][self.matrix.width - 1]
    def solveMatrix(self):
        if self.matrix.width > self.matrix.height + 1:
            raise Exception("The problem is under-defined")
        self.matrix.rref()
    def getEquilibriumMatrix(self):
        self.matrix = []
        for node in self.nodes:
            self.addXEquation(node)
            self.addYEquation(node)
        self.matrix = Matrix(self.matrix)
        return self.matrix

    def addXEquation(self, node):
        if not node.fixedX:
            row = []
            for member in self.members:
                if member.hasNode(node):
                    vector = member.getVector(node)
                    row.append(float(vector[0]) / vector.length)
                else:
                    row.append(0)
            row.append(-node.load[0])
            self.matrix.append(row)
#.........这里部分代码省略.........
开发者ID:alex-ozdemir,项目名称:truss-analyzer,代码行数:103,代码来源:truss.py


注:本文中的Matrix.Matrix.append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。