Hi,
suppose I have two points in 3D space:
A = ROOT.TGLVertex3(1, 1, -20)
B = ROOT.TGLVertex3(1, 1, +20)
and I construct a line from these:
myLine = ROOT.TGLLine3(A, B)
Now I define three other points and construct a plane of these three:
C = ROOT.TGLVertex3(1, 3, 0)
D = ROOT.TGLVertex3(2, 0, 0)
E = ROOT.TGLVertex3(5, 4, 0)
myPlane = ROOT.TGLPlane(C, D, E)
And I want to know whether myLine
intersects myPlane
and, if so, where exactly:
intersectionOfMyLineAndMyPlane = ROOT.std.pair(bool, ROOT.TGLVertex3)(ROOT.Intersection(myPlane, myLine, False))
if intersectionOfMyLineAndMyPlane.first:
print(f"myLine intersects myPlane at x={intersectionOfMyLineAndMyPlane.second.X()}, y={intersectionOfMyLineAndMyPlane.second.Y()}, z={intersectionOfMyLineAndMyPlane.second.Z()}")
else:
print("No intersection!")
That all works very well. But further down the road, I would like to limit the infinite myPlane
by a simple 2D shape like e.g. a square, and to check if myLine
intersects this square part of myPlane
. Any idea how I could go about this? Maybe with some different ROOT classes?
Full code:
import ROOT
A = ROOT.TGLVertex3(1, 1, -20)
B = ROOT.TGLVertex3(1, 1, +20)
myLine = ROOT.TGLLine3(A, B)
C = ROOT.TGLVertex3(1, 3, 0)
D = ROOT.TGLVertex3(2, 0, 0)
E = ROOT.TGLVertex3(5, 4, 0)
myPlane = ROOT.TGLPlane(C, D, E)
intersectionOfMyLineAndMyPlane = ROOT.std.pair(bool, ROOT.TGLVertex3)(ROOT.Intersection(myPlane, myLine, False))
if intersectionOfMyLineAndMyPlane.first:
print(f"myLine intersects myPlane at x={intersectionOfMyLineAndMyPlane.second.X()}, y={intersectionOfMyLineAndMyPlane.second.Y()}, z={intersectionOfMyLineAndMyPlane.second.Z()}")
else:
print("No intersection!")
# is there any way to limit the infinite myPlane to e.g. a simple square (given by e.g. 4 points on this plane: J, K, L, M) and to check if myLine intersects myPlane inside this square?
ROOT Version: 6.22/06
Platform: CentOS 7