Mercurial > hg > orthanc-stone
annotate Resources/Computations/IntersectSegmentAndVerticalLine.py @ 525:2549363fadc3 am-touch-events
Close branch am-touch-events.
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 12 Mar 2019 17:29:12 +0000 |
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 # vertical line "x = x0" 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, x0 = symbols('prevX prevY curX curY x0') |
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([x0, 0, 1]) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 h2 = Matrix([x0, 1, 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(a / a[2]) |