Skip to content

Function for drawing a margin around a region #599

@JackB-Ansys

Description

@JackB-Ansys

📝 Description of the feature

Image

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
Image
  • 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)
Image
  • 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
Image

🔗 Useful links and references

square_margin.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew features or code improvements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions