geometry.Rectangle()

class feign.geometry.Rectangle(p1, p2, p3, p4)

A class used to represent a Rectangle.

Rectangles are actually general convex quadritlaterals. To create a Rectangle, one should give the four corners in a clockwise or counter-clockwise order

Parameters
  • p1 (Point()) – first corner

  • p2 (Point()) – second corner

  • p3 (Point()) – third corner

  • p4 (Point()) – fourth corner

p1

first corner

Type

Point()

p2

second corner

Type

Point()

p3

third corner

Type

Point()

p4

fourth corner

Type

Point()

p1p2

first side

Type

Segment()

p2p3

second side

Type

Segment()

p3p4

third side

Type

Segment()

p4p1

fourth side

Type

Segment()

corners

list of the corner points

Type

list of Point()

sides

list of the sides

Type

list of Segment()

Raises

ValueError – if Corners are not defined in clockwise or counter-clockwise order.

encloses_point(P)

The function to assess whether a point is enclosed by a Rectangle().

Parameters

P (Point()) – point to decide whether is enclosed by Rectangle

Returns

True if the point is enclosed by the Rectangle, False otherwise.

Return type

bool

Examples

>>> rect=Rectangle(Point(3,7),Point(5,3),Point(13,5),Point(12,6))
>>> P=Point(6,5)
>>> rect.encloses_point(P)
True
>>> Q=Point(4,3)
>>> rect.encloses_point(Q)
False
intersection(seg)

The function to find the intersection of a Rectangle with a Segment.

Parameters

seg (Segment()) – The Segment for which the intersection is calculated

Returns

list of the intersections

Return type

list of Point()

Notes

The list has one element if one of the endpoints of the Segment is enclosed by the rectangle.

The list has two elements if both endpoints of the Segment lies outside the Rectangle, and the Segment passes through the Rectangle.

An empty list is returned if the Segment does not pass through the Rectangle, or in case the Segment passes through only one of the corners.

Examples

>>> rect=Rectangle(Point(-10,10),Point(10,10),Point(10,-10),Point(-10,-10))
>>> s=Segment(Point(-30,-30),Point(30,30))
>>> rect.intersection(s)
[Point(10.000, 10.000), Point(-10.000, -10.000)]
rotate(alpha)

The function to rotate a Rectangle around the origin with alpha (deg)

Parameters

alpha (float) – Rotation angle (in degrees)

Returns

Rectangle with rotated end points

Return type

Rectangle()