def getEdgesAngle(edge1, edge2): """getEdgesAngle(edge1, edge2): returns a angle between two edges.""" vec1 = vec(edge1) vec2 = vec(edge2) angle = vec1.getAngle(vec2) angle = math.degrees(angle) return angle
def getParametersOfFace(structure, facename, sketch=True): """getParametersOfFace(structure, facename, sketch = True): This function will return length, width and points of center of mass of a given face w.r.t sketch value. For eg.: Case 1: When sketch is True: We use True when we want to create rebars from sketch (planar rebars) and the sketch is strictly based on 2D, so we neglected the normal axis of the face. Output: [(FaceLength, FaceWidth), (CenterOfMassX, CenterOfMassY)] Case 2: When sketch is False: When we want to create non-planar rebars (like stirrup) or rebar from a wire. Also for creating rebar from wire we will require three coordinates (x, y, z). Output: [(FaceLength, FaceWidth), (CenterOfMassX, CenterOfMassY, CenterOfMassZ)] """ face = structure.Shape.Faces[getFaceNumber(facename) - 1] center_of_mass = face.CenterOfMass # center_of_mass = center_of_mass.sub( # getBaseStructuralObject(structure).Placement.Base # ) center_of_mass = center_of_mass.sub(structure.Placement.Base) Edges = [] facePRM = [] # When structure is cubic. It support all structure is derived from # any other object (like a sketch, wire etc). if isCubic(structure.Shape): for edge in face.Edges: if not Edges: Edges.append(edge) else: # Checks whether similar edges is already present in Edges list # or not. if round((vec(edge)).Length) not in [ round((vec(x)).Length) for x in Edges ]: Edges.append(edge) if len(Edges) == 1: Edges.append(edge) # facePRM holds length of a edges. facePRM = [(vec(edge)).Length for edge in Edges] face_normal = face.normalAt(0, 0) if round(face_normal[0]) in (-1, 1): x = center_of_mass[1] y = center_of_mass[2] elif round(face_normal[1]) in (-1, 1): x = center_of_mass[0] y = center_of_mass[2] elif round(face_normal[2]) in (-1, 1): x = center_of_mass[0] y = center_of_mass[1] # When edge is parallel to y-axis if round(Edges[0].tangentAt(0)[1]) in {1, -1}: if round(Edges[1].tangentAt(0)[0]) in {1, -1}: # Change order when edge along x-axis is at second place. facePRM.reverse() elif round(Edges[0].tangentAt(0)[2]) in {1, -1}: facePRM.reverse() facelength = facePRM[0] facewidth = facePRM[1] # When structure is not cubic. For founding parameters of given face # I have used bounding box. else: boundbox = face.BoundBox # Check that one length of bounding box is zero. Here bounding box # looks like a plane. if 0 in { round(boundbox.XLength), round(boundbox.YLength), round(boundbox.ZLength), }: normal = face.normalAt(0, 0) normal = face.Placement.Rotation.inverted().multVec(normal) # print "x: ", boundbox.XLength # print "y: ", boundbox.YLength # print "z: ", boundbox.ZLength # Set length and width of user selected face of structural element flag = True # FIXME: Improve below logic. for i in range(len(normal)): if round(normal[i]) == 0: if flag and i == 0: x = center_of_mass[i] facelength = boundbox.XLength flag = False elif flag and i == 1: x = center_of_mass[i] facelength = boundbox.YLength flag = False if i == 1: y = center_of_mass[i] facewidth = boundbox.YLength elif i == 2: y = center_of_mass[i] facewidth = boundbox.ZLength # print [(facelength, facewidth), (x, y)] # Return parameter of the face when rebar is not created from the sketch. # For eg. non-planar rebars like stirrup etc. if not sketch: center_of_mass = face.CenterOfMass return [(facelength, facewidth), center_of_mass] # TODO: Add support when bounding box have depth. Here bounding box looks # like cuboid. If we given curved face. return [(facelength, facewidth), (x, y)]