| Summary: | [G4GenericTrap] Bug in InsidePolygone method | ||
|---|---|---|---|
| Product: | Geant4 | Reporter: | Nicola Mori <mori> |
| Component: | geometry/solids | Assignee: | tatiana.nikitina |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | mori |
| Priority: | P3 | ||
| Version: | 9.6 | ||
| Hardware: | All | ||
| OS: | All | ||
| Attachments: |
Proposed patch
Fix for reported problem |
||
Dear Nicola, Thank you very much for reporting this problem. Variable 'test' is used to test, if given point p is Inside segment. But in case of two end-points of the segment with y1=0 and y2=0 it will fail. Your proposed solution is good, but it also possible to make special case for y1=y2. Fix will be tested and included in next Geant4 release. Best Regards, Tatiana. Thanks Tatiana. I didn't test the patch very thoroughly and I think it can be improved (for example, by taking into account some tolerance parameter in the geometric check). Feel free to do whatever you want with it, including throwing it away if you find a better fix. Created attachment 245 [details]
Fix for reported problem
Fix for reported problem
Dear Nicola, Thank you for the help. Fix, based on your proposal, is tested and will be included in next Geant4 release. Best Regards, Tatiana. Thank you very much Tatiana. Will the fix appear also in an eventual 9.6.p03 release or only in the Geant4 10 series? Dear Nicola, Thank you for your message, Yes, if there will be a patch, fix will be included. Best Regards, Tatiana. |
Created attachment 244 [details] Proposed patch I think I discovered a bug in the G4GenericTrap::InsidePolygon routine in Geant4 9.6.p01. In G4GenericTrap.cc at line 247, the "cross" variable is computed: in my understanding, cross is ~ 0 when the point lies on the line defined by the two extrema of the side of the polygon. At line 253 the condition cross~0 is used to check if the point lies on the segment defining a side of the polygon, but this is not correct since cross~0 also when a point lies on the segment but is not within the two extrema. As a trivial example, consider the segment defined by the two points (x1,y1)=(-1,0) and (x2,y2)=(1,0) as the side of the polygon lying on the X axis. The point (x,y)=(2,0) lies on the X axis and will give cross=0: cross = (x-x1)*(y2-y1) - (y-y1)(x2-x1) = 0 This will trigger the surface check at line 253, which will end returning kSurface at line 275. I put together an idiotic patch which seems to fix this issue, at least for my use case; I attach it to this bug report.