generated from ansys/template
    
        
        - 
                Notifications
    
You must be signed in to change notification settings  - Fork 3
 
Open
Labels
enhancementNew features or code improvementsNew features or code improvements
Description
📝 Description of the feature
Create a function that can return a region based on an original region that is smaller (or larger) than the original.
💡 Steps for implementing the feature
- Create a method for returning perpendicular lines for an entity of given length:
 
def get_perpendicular_line(entity, length):
    line = Line(entity.start, entity.end)
    line.rotate(entity.midpoint, 90)
    line.start = line.midpoint
    new_end = line.get_coordinate_from_distance(line.start, distance=length)
    line.end = new_end
    return line
- Use the perpendicular lines to get the vector to shift original lines by:
 
shifted_entities = []
perpendicular_lines = []
for entity in square_1.entities:
    perpendicular_line = get_perpendicular_line(entity, margin)
    perpendicular_lines.append(perpendicular_line)
    vector_to_shift = perpendicular_line.end - perpendicular_line.start
    shifted_entity = Line(entity.start, entity.end)
    shifted_entity.translate(vector_to_shift.x, vector_to_shift.y)
    shifted_entities.append(shifted_entity)
- Find the intersection points of these shifted lines:
 
intersection_points = []
entity = shifted_entities[-1]
for i in range(len(shifted_entities)):
    next_entity = shifted_entities[i]
    intersection_points.append(entity.get_intersection(next_entity)[0])
    entity = next_entity
intersection_points.append(intersection_points[0])
- Draw new lines between the intersection points to form the new 'margin region':
 
point_1 = intersection_points[0]
margin_region = Region()
for i in range(len(intersection_points)-1):
    point_2 = intersection_points[i+1]
    margin_region.add_entity(Line(point_1, point_2))
    point_1 = point_2
🔗 Useful links and references
Metadata
Metadata
Assignees
Labels
enhancementNew features or code improvementsNew features or code improvements