Mercurial > hg > orthanc-stone
annotate Resources/Computations/IntersectSegmentAndHorizontalLine.py @ 879:12b591d5d63c am-dev
some Qt integration (wip)
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Fri, 05 Jul 2019 14:52:43 +0200 |
parents | 35c2b85836ce |
children |
rev | line source |
---|---|
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 from sympy import * |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 # Intersection between the 2D line segment (prevX,prevY)-(curX,curY) and the |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 # horizontal line "y = y0" using homogeneous coordinates |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 prevX, prevY, curX, curY, y0 = symbols('prevX prevY curX curY y0') |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 p1 = Matrix([prevX, prevY, 1]) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 p2 = Matrix([curX, curY, 1]) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 l1 = p1.cross(p2) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 h1 = Matrix([0, y0, 1]) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 h2 = Matrix([1, y0, 1]) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 l2 = h1.cross(h2) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 a = l1.cross(l2) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 #pprint(cse(a/a[2], symbols = symbols('a b'))) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 pprint(a / a[2]) |