feign.geometry tutorial¶
The API of feign requires the definition of several geometric objects, thus the user needs some familiarity of the classes of the feign.geometry modul. The classes have several methods which are not needed to be used by the user, only used by the module feign.blocks. In the following it is highlighted whether a method is needed to be used by the user.
feign.geometry has an API similar to sympy, nevertheless, feign.geometry is not a symbolic module.
Every coordinate is meant in cm units.
The objects which might be used by the user are the following:
Point
Segment
Circle
Rectangle
Let’s import first the module.
[1]:
from feign.geometry import *
Point()¶
A 2D Point is defined through its x,y coordinates. Its attributes are also x and y.
When writing an input one needs to use points in order to define:
Detector points (mandatory)
Absorbers (giving the corners of Rectangles, see later) (optional)
Pool (giving the corners of Rectangle, see later) (optional)
[2]:
p=Point(3,4)
q=Point(x=3.4,y=32)
[3]:
print(p)
print(p.x,p.y)
print(q)
print(q.x,q.y)
Point(3.000, 4.000)
3 4
Point(3.400, 32.000)
3.4 32
Methods may be used¶
While writing the input, two methods may come handy:
rotate: for rotating the point around (0,0) with alpha angle (in deg)
translate: translating the point with (xt,yt) vector.
Both methods will create a new object.
[4]:
p.rotate(45)
[4]:
Point(-0.707, 4.950)
[5]:
p.translate(2,1)
[5]:
Point(5.000, 5.000)
Other methods¶
There are some other methods which are used in feign.blocks.
distance: distance between two points
inBetween: two decide whether a point lies on the same line as two other points, and whether it is between the two points
isEqual: to decide whether two points are the same.
[6]:
p.distance(q)
[6]:
28.00285699709942
[7]:
p.isEqual(q)
[7]:
False
[8]:
Point(1,2).inBetween(p,q)
[8]:
False
Segment()¶
A 2D Segment is defined through its end points p and q. Its attributes are p, q, points (list of [p,q]), slope, intercept. If the segment is vertically aligned, the slope is np.Inf, and the intercept becomes the intersection with the x axis.
When writing an input one needs to use segments in order to define:
The front and back opening of collimators (optional)
[9]:
s=Segment(p,q)
print(s)
print(s.points)
print(s.p.x,s.p.y)
print(s.slope)
print(s.intercept)
print(Segment(Point(3,4),Point(3,6)).slope)
Segment(Point(3.000, 4.000),Point(3.400, 32.000))
[Point(3.000, 4.000), Point(3.400, 32.000)]
3 4
70.00000000000001
-206.00000000000006
inf
Methods may be used¶
While writing the input, one method may come handy:
rotate: for rotating the segment around (0,0) with alpha angle (in deg)
The method will create a new object.
[10]:
s.rotate(45)
[10]:
Segment(Point(-0.707, 4.950),Point(-20.223, 25.032))
Other methods¶
The segment class has one more method available:
intersection: intersection of two segments
[11]:
Segment(p,q).intersection(Segment(Point(-4.5,4.5),Point(5.5,4.5)))
[11]:
[Point(3.007, 4.500)]
Circle()¶
A 2D Circle is defined through its center c and radius r. Its attributes are also c, r.
When writing an input one may need to use circles in order to define:
Absorber elements (optional)
[12]:
c=Circle(Point(4.5,4.5),5)
print(c)
print(c.c)
print(c.r)
Circle(C=(4.500, 4.500),R=5.000)
Point(4.500, 4.500)
5
Other methods¶
While writing the input, usually Circle methods are not needed. Nevertheless, there are two available methods:
intersection: intersection with a segment
encloses_point: to decide whether a point is within the circle
[13]:
c.intersection(s)
[13]:
[Point(3.076, 9.293)]
[14]:
c.encloses_point(Point(5,5))
[14]:
True
Rectangle()¶
A 2D Rectangle is defined through its corner points p1, p2, p3, p4. Its attributes are the corner points p1, p2, p3, p4, corners a list of these poins, the side segments p1p2, p2p3, p3p4, p4p1, and sides a list of the side segments.
The corners have to be defined in a clockwise or counter-clockwise order.
In fact, a Rectangle() object can be a general convex quadritlateral, the choice of naming is only to avoid typos.
When writing an input one needs to use rectangles in order to define:
The pool (optional)
Absorbers elements (optional)
[15]:
r=Rectangle(Point(-3,-3),Point(-3,3),Point(3,3),Point(3,-3))
print(r)
print(r.p1,r.p2,r.p3,r.p4)
print(r.corners)
print(r.p1p2,r.p2p3,r.p3p4,r.p4p1)
print(r.sides)
Rectangle(Point(-3.000, -3.000),Point(-3.000, 3.000),Point(3.000, 3.000),Point(3.000, -3.000))
Point(-3.000, -3.000) Point(-3.000, 3.000) Point(3.000, 3.000) Point(3.000, -3.000)
[Point(-3.000, -3.000), Point(-3.000, 3.000), Point(3.000, 3.000), Point(3.000, -3.000)]
Segment(Point(-3.000, -3.000),Point(-3.000, 3.000)) Segment(Point(-3.000, 3.000),Point(3.000, 3.000)) Segment(Point(3.000, 3.000),Point(3.000, -3.000)) Segment(Point(3.000, -3.000),Point(-3.000, -3.000))
[Segment(Point(-3.000, -3.000),Point(-3.000, 3.000)), Segment(Point(-3.000, 3.000),Point(3.000, 3.000)), Segment(Point(3.000, 3.000),Point(3.000, -3.000)), Segment(Point(3.000, -3.000),Point(-3.000, -3.000))]
Methods may be used¶
While writing the input, one method may come handy:
rotate: for rotating the rectangle around (0,0) with alpha angle (in deg)
The method will create a new object.
[16]:
r.rotate(45)
[16]:
Rectangle(Point(-0.000, -4.243),Point(-4.243, 0.000),Point(0.000, 4.243),Point(4.243, -0.000))
Other methods¶
Similarly to Circle, Rectangles also have two more available methods:
intersection: intersection with a segment
encloses_point: to decide whether a point is within the rectangle
[17]:
r.intersection(Segment(Point(-3,-4),Point(3,4)))
[17]:
[Point(2.250, 3.000), Point(-2.250, -3.000)]
[18]:
r.encloses_point(Point(1,2))
[18]:
True