Package gaphas :: Module geometry

Module geometry

source code

Geometry functions.

Rectangle is a utility class for working with rectangles (unions and intersections)

A point is represented as a tuple (x, y).


Version: $Revision: 1794 $

Classes
  Rectangle
Python Rectangle implementation.
Functions
 
distance_point_point(point1, point2=(0.0, 0.0))
Return the distance from point point1 to point2.
source code
 
distance_point_point_fast(point1, point2)
Return the distance from point point1 to point2.
source code
 
distance_rectangle_point(rect, point)
Return the distance (fast) from a rectangle (x, y, width, height) to a point.
source code
 
point_on_rectangle(rect, point, border=False)
Return the point on which point can be projecten on the rectangle.
source code
 
distance_line_point(line_start, line_end, point)
Calculate the distance of a point from a line.
source code
 
intersect_line_line(line1_start, line1_end, line2_start, line2_end)
Find the point where the lines (segments) defined by (line1_start, line1_end) and (line2_start, line2_end) intersect.
source code
 
rectangle_contains(inner, outer)
Returns True if inner rect is contained in outer rect.
source code
 
rectangle_intersects(recta, rectb)
Return True if recta and rectb intersect.
source code
 
rectangle_clip(recta, rectb)
Return the clipped rectangle of recta and rectb.
source code
Function Details

distance_point_point_fast(point1, point2)

source code 

Return the distance from point point1 to point2. This version is faster than distance_point_point(), but less precise.

>>> distance_point_point_fast((0,0), (1,1))
2

distance_line_point(line_start, line_end, point)

source code 

Calculate the distance of a point from a line. The line is marked by begin and end point line_start and line_end.

A tuple is returned containing the distance and point on the line.

>>> distance_line_point((0., 0.), (2., 4.), point=(3., 4.))
(1.0, (2.0, 4.0))
>>> distance_line_point((0., 0.), (2., 4.), point=(-1., 0.))
(1.0, (0.0, 0.0))
>>> distance_line_point((0., 0.), (2., 4.), point=(1., 2.))
(0.0, (1.0, 2.0))
>>> d, p = distance_line_point((0., 0.), (2., 4.), point=(2., 2.))
>>> '%.3f' % d
'0.894'
>>> '(%.3f, %.3f)' % p
'(1.200, 2.400)'

intersect_line_line(line1_start, line1_end, line2_start, line2_end)

source code 

Find the point where the lines (segments) defined by (line1_start, line1_end) and (line2_start, line2_end) intersect. If no intersecion occurs, None is returned.

>>> intersect_line_line((0, 0), (10, 10), (3, 0), (8, 10))
(6.0, 6.0)
>>> intersect_line_line((0, 0), (0, 10), (3, 0), (8, 10))
>>> intersect_line_line((0, 0), (0, 10), (3, 0), (3, 10))

rectangle_clip(recta, rectb)

source code 

Return the clipped rectangle of recta and rectb. If they do not intersect, None is returned.

>>> rectangle_clip((0, 0, 20, 20), (10, 10, 20, 20))
(10, 10, 10, 10)