AGX Dynamics  2.37.3.2
LineClipping.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXCOLLIDE_LINECLIPPING_H
18 #define AGXCOLLIDE_LINECLIPPING_H
19 
20 #include <agx/macros.h>
21 
23 
24 #include <agx/agxPhysics_export.h>
25 #include <agx/Interval.h>
26 
27 #ifndef _WIN32
28 #include <float.h>
29 #endif
30 
31 #include <agx/agx.h>
32 #include <agx/Vec3.h>
33 
34 namespace agxCollide
35 {
51  AGXPHYSICS_EXPORT bool clipLineToPlane(
52  agx::Real planeDistance,
53  unsigned int planeDimension,
54  int planeNormalSign,
55  const agx::Vec3& linePoint,
56  const agx::Vec3& lineDir,
57  agx::Interval& interval,
58  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
59 
60 
75  AGXPHYSICS_EXPORT bool clipLineToSlab(
76  agx::Real slabDistance,
77  unsigned int slabDimension,
78  const agx::Vec3& linePoint,
79  const agx::Vec3& lineDir,
80  agx::Interval& interval,
81  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
82 
83 
100  AGXPHYSICS_EXPORT bool clipLineToDoubleSlab(
101  agx::Real slab1Distance,
102  unsigned int slab1Dimension,
103  agx::Real slab2Distance,
104  unsigned int slab2Dimension,
105  const agx::Vec3& linePoint,
106  const agx::Vec3& lineDir,
107  agx::Interval& interval,
108  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
109 
110 
123  AGXPHYSICS_EXPORT bool clipLineToOpenBox(
124  const agx::Vec3& boxHalfExtents,
125  int openDim,
126  int openDimCutSign,
127  const agx::Vec3& linePoint,
128  const agx::Vec3& lineDir,
129  agx::Interval& interval,
130  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
131 
132 
133 
147  AGXPHYSICS_EXPORT bool clipLineToBox(
148  const agx::Vec3& boxHalfExtents,
149  const agx::Vec3& linePoint,
150  const agx::Vec3& lineDir,
151  agx::Interval& interval,
152  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
153 
154 
167  AGXPHYSICS_EXPORT bool clipLineToInfiniteCylinder(
168  agx::Real cylRadius,
169  const agx::Vec3& linePoint,
170  const agx::Vec3& lineDir,
171  agx::Interval& interval,
172  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
173 
174 
188  AGXPHYSICS_EXPORT bool clipLineToInfiniteEllipticCylinder(
189  agx::Real cylRadiusX,
190  agx::Real cylRadiusZ,
191  const agx::Vec3& linePoint,
192  const agx::Vec3& lineDir,
193  agx::Interval& interval,
194  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
195 
196 
210  AGXPHYSICS_EXPORT bool clipLineToCylinder(
211  agx::Real cylRadius,
212  agx::Real cylHeight,
213  const agx::Vec3& linePoint,
214  const agx::Vec3& lineDir,
215  agx::Interval& interval,
216  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
217 
218 
219 
220 
232  AGXPHYSICS_EXPORT bool clipLineToSphere(
233  agx::Real sphereRadius,
234  const agx::Vec3& linePoint,
235  const agx::Vec3& lineDir,
236  agx::Interval& interval,
237  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
238 
239 
253  AGXPHYSICS_EXPORT bool clipLineToCapsule(
254  agx::Real capsRadius,
255  agx::Real capsHeight,
256  const agx::Vec3& linePoint,
257  const agx::Vec3& lineDir,
258  agx::Interval& interval,
259  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
260 
261 
277  AGXPHYSICS_EXPORT bool clipRayToPlane(
278  agx::Real planeDistance,
279  unsigned int planeDimension,
280  int planeNormalSign,
281  const agx::Vec3& rayStartPoint,
282  const agx::Vec3& rayDir,
283  agx::Interval& interval,
284  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
285 
286 
301  AGXPHYSICS_EXPORT bool clipRayToSlab(
302  agx::Real slabDistance,
303  unsigned int slabDimension,
304  const agx::Vec3& rayStartPoint,
305  const agx::Vec3& rayDir,
306  agx::Interval& interval,
307  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
308 
309 
326  AGXPHYSICS_EXPORT bool clipRayToDoubleSlab(
327  agx::Real slab1Distance,
328  unsigned int slab1Dimension,
329  agx::Real slab2Distance,
330  unsigned int slab2Dimension,
331  const agx::Vec3& rayStartPoint,
332  const agx::Vec3& rayDir,
333  agx::Interval& interval,
334  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
335 
336 
349  AGXPHYSICS_EXPORT bool clipRayToOpenBox(
350  const agx::Vec3& boxHalfExtents,
351  int openDim,
352  int openDimCutSign,
353  const agx::Vec3& rayStartPoint,
354  const agx::Vec3& rayDir,
355  agx::Interval& interval,
356  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
357 
358 
359 
373  AGXPHYSICS_EXPORT bool clipRayToBox(
374  const agx::Vec3& boxHalfExtents,
375  const agx::Vec3& rayStartPoint,
376  const agx::Vec3& rayDir,
377  agx::Interval& interval,
378  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
379 
380 
381 
394  AGXPHYSICS_EXPORT bool clipRayToInfiniteCylinder(
395  agx::Real cylRadius,
396  const agx::Vec3& rayStartPoint,
397  const agx::Vec3& rayDir,
398  agx::Interval& interval,
399  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
400 
401 
402 
416  AGXPHYSICS_EXPORT bool clipRayToCylinder(
417  agx::Real cylRadius,
418  agx::Real cylHeight,
419  const agx::Vec3& rayStartPoint,
420  const agx::Vec3& rayDir,
421  agx::Interval& interval,
422  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
423 
424 
425 
437  AGXPHYSICS_EXPORT bool clipRayToSphere(
438  agx::Real sphereRadius,
439  const agx::Vec3& rayStartPoint,
440  const agx::Vec3& rayDir,
441  agx::Interval& interval,
442  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
443 
444 
445 
459  AGXPHYSICS_EXPORT bool clipRayToCapsule(
460  agx::Real capsRadius,
461  agx::Real capsHeight,
462  const agx::Vec3& rayStartPoint,
463  const agx::Vec3& rayDir,
464  agx::Interval& interval,
465  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
466 
467 
468 
484  AGXPHYSICS_EXPORT bool clipLineSegmentToPlane(
485  agx::Real planeDistance,
486  unsigned int planeDimension,
487  int planeNormalSign,
488  const agx::Vec3& lineSegmentPoint0,
489  const agx::Vec3& lineSegmentPoint1,
490  agx::Interval& interval,
491  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
492 
493 
494 
509  AGXPHYSICS_EXPORT bool clipLineSegmentToSlab(
510  agx::Real slabDistance,
511  unsigned int slabDimension,
512  const agx::Vec3& lineSegmentPoint0,
513  const agx::Vec3& lineSegmentPoint1,
514  agx::Interval& interval,
515  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
516 
517 
518 
535  AGXPHYSICS_EXPORT bool clipLineSegmentToDoubleSlab(
536  agx::Real slab1Distance,
537  unsigned int slab1Dimension,
538  agx::Real slab2Distance,
539  unsigned int slab2Dimension,
540  const agx::Vec3& lineSegmentPoint0,
541  const agx::Vec3& lineSegmentPoint1,
542  agx::Interval& interval,
543  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
544 
545 
546 
559  AGXPHYSICS_EXPORT bool clipLineSegmentToOpenBox(
560  const agx::Vec3& boxHalfExtents,
561  int openDim,
562  int openDimCutSign,
563  const agx::Vec3& lineSegmentPoint0,
564  const agx::Vec3& lineSegmentPoint1,
565  agx::Interval& interval,
566  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
567 
568 
582  AGXPHYSICS_EXPORT bool clipLineSegmentToBox(
583  const agx::Vec3& boxHalfExtents,
584  const agx::Vec3& lineSegmentPoint0,
585  const agx::Vec3& lineSegmentPoint1,
586  agx::Interval& interval,
587  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
588 
589 
590 
603  AGXPHYSICS_EXPORT bool clipLineSegmentToInfiniteCylinder(
604  agx::Real cylRadius,
605  const agx::Vec3& lineSegmentPoint0,
606  const agx::Vec3& lineSegmentPoint1,
607  agx::Interval& interval,
608  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
609 
610 
624  AGXPHYSICS_EXPORT bool clipLineSegmentToCylinder(
625  agx::Real cylRadius,
626  agx::Real cylHeight,
627  const agx::Vec3& lineSegmentPoint0,
628  const agx::Vec3& lineSegmentPoint1,
629  agx::Interval& interval,
630  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
631 
632 
633 
649  AGXPHYSICS_EXPORT bool clipLineSegmentToCone(
650  agx::Real bottomRadius,
651  agx::Real topRadius,
652  agx::Real coneHeight,
653  const agx::Vec3& lineSegmentPoint0,
654  const agx::Vec3& lineSegmentPoint1,
655  agx::Interval& interval,
656  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
657 
658 
670  AGXPHYSICS_EXPORT bool clipLineSegmentToSphere(
671  agx::Real sphereRadius,
672  const agx::Vec3& lineSegmentPoint0,
673  const agx::Vec3& lineSegmentPoint1,
674  agx::Interval& interval,
675  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
676 
677 
691  AGXPHYSICS_EXPORT bool clipLineSegmentToCapsule(
692  agx::Real capsRadius,
693  agx::Real capsHeight,
694  const agx::Vec3& lineSegmentPoint0,
695  const agx::Vec3& lineSegmentPoint1,
696  agx::Interval& interval,
697  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
698 
699 
700 
701 
702  /* Implementation */
703 
704  AGX_FORCE_INLINE bool clipLineToDoubleSlab(
705  agx::Real slab1Distance,
706  unsigned int slab1Dimension,
707  agx::Real slab2Distance,
708  unsigned int slab2Dimension,
709  const agx::Vec3& linePoint,
710  const agx::Vec3& lineDir,
711  agx::Interval& interval,
712  const agx::Real epsilon)
713  {
714  if (clipLineToSlab( slab1Distance, slab1Dimension, linePoint, lineDir, interval, epsilon )) {
715  agx::Interval tmpInt;
716  if (clipLineToSlab( slab2Distance, slab2Dimension, linePoint, lineDir, tmpInt, epsilon )) {
717  interval.intersectWith( tmpInt );
718  return interval.hasElements();
719  }
720  }
721  return false;
722  }
723 
724  AGX_FORCE_INLINE bool clipLineToOpenBox(
725  const agx::Vec3& boxHalfExtents,
726  int openDim,
727  int openDimCutSign,
728  const agx::Vec3& linePoint,
729  const agx::Vec3& lineDir,
730  agx::Interval& interval,
731  const agx::Real epsilon)
732  {
733  {
734  int dim1 = (openDim + 1) % 3;
735  if (!clipLineToSlab( boxHalfExtents[dim1], dim1, linePoint, lineDir, interval, epsilon ))
736  return false;
737  }
738  {
739  agx::Interval tmpInterval0;
740  int dim2 = (openDim + 2) % 3;
741  if (!clipLineToSlab( boxHalfExtents[dim2], dim2, linePoint, lineDir, tmpInterval0, epsilon ))
742  return false;
743  interval.intersectWith( tmpInterval0 );
744  if (interval.isEmpty())
745  return false;
746 
747  }
748  {
749  agx::Interval tmpInterval1;
750  if (!clipLineToPlane( boxHalfExtents[openDim], openDim, openDimCutSign, linePoint, lineDir, tmpInterval1, epsilon ))
751  return false;
752 
753  interval.intersectWith( tmpInterval1 );
754  return interval.hasElements();
755  }
756  }
757 
758  AGX_FORCE_INLINE bool clipLineToBox(
759  const agx::Vec3& boxHalfExtents,
760  const agx::Vec3& linePoint,
761  const agx::Vec3& lineDir,
762  agx::Interval& interval,
763  const agx::Real epsilon)
764  {
765  if (!clipLineToSlab( boxHalfExtents[0], 0, linePoint, lineDir, interval, epsilon ))
766  return false;
767  {
768  agx::Interval tmpInterval0;
769  if (!clipLineToSlab( boxHalfExtents[1], 1, linePoint, lineDir, tmpInterval0, epsilon ))
770  return false;
771  interval.intersectWith( tmpInterval0 );
772  if (interval.isEmpty())
773  return false;
774  }
775  {
776  agx::Interval tmpInterval1;
777  if (!clipLineToSlab( boxHalfExtents[2], 2, linePoint, lineDir, tmpInterval1, epsilon ))
778  return false;
779  interval.intersectWith( tmpInterval1 );
780  return interval.hasElements();
781  }
782  }
783 
784  AGX_FORCE_INLINE bool clipLineToCylinder(
785  agx::Real cylRadius,
786  agx::Real cylHeight,
787  const agx::Vec3& linePoint,
788  const agx::Vec3& lineDir,
789  agx::Interval& interval,
790  const agx::Real epsilon)
791  {
792  if (!clipLineToSlab( agx::Real( 0.5 ) * cylHeight, 1, linePoint, lineDir, interval, epsilon ))
793  return false;
794  agx::Interval tmpInterval;
795  if (!clipLineToInfiniteCylinder( cylRadius, linePoint, lineDir, tmpInterval, epsilon ))
796  return false;
797  interval.intersectWith( tmpInterval );
798  return interval.hasElements();
799  }
800 
801  AGX_FORCE_INLINE bool clipRayToPlane(
802  agx::Real planeDistance,
803  unsigned int planeDimension,
804  int planeNormalSign,
805  const agx::Vec3& rayStartPoint,
806  const agx::Vec3& rayDir,
807  agx::Interval& interval,
808  const agx::Real epsilon)
809  {
810  if (!clipLineToPlane( planeDistance, planeDimension, planeNormalSign,
811  rayStartPoint, rayDir, interval, epsilon ))
812  return false;
813  interval.intersectWithRightUnbounded( 0 );
814  return interval.hasElements();
815  }
816 
817  AGX_FORCE_INLINE bool clipRayToSlab(
818  agx::Real slabDistance,
819  unsigned int slabDimension,
820  const agx::Vec3& rayStartPoint,
821  const agx::Vec3& rayDir,
822  agx::Interval& interval,
823  const agx::Real epsilon)
824  {
825  if (clipLineToSlab( slabDistance, slabDimension, rayStartPoint, rayDir, interval, epsilon )) {
826  interval.intersectWithRightUnbounded( 0 );
827  return interval.hasElements();
828  }
829  return false;
830  }
831 
832  AGX_FORCE_INLINE bool clipRayToDoubleSlab(
833  agx::Real slab1Distance,
834  unsigned int slab1Dimension,
835  agx::Real slab2Distance,
836  unsigned int slab2Dimension,
837  const agx::Vec3& rayStartPoint,
838  const agx::Vec3& rayDir,
839  agx::Interval& interval,
840  const agx::Real epsilon)
841  {
842  if (clipRayToSlab( slab1Distance, slab1Dimension, rayStartPoint, rayDir, interval, epsilon )) {
843  agx::Interval tmpInt;
844  if (clipRayToSlab( slab2Distance, slab2Dimension, rayStartPoint, rayDir, tmpInt, epsilon )) {
845  interval.intersectWith( tmpInt );
846  return interval.hasElements();
847  }
848  }
849  return false;
850  }
851 
852 
853  AGX_FORCE_INLINE bool clipRayToOpenBox(
854  const agx::Vec3& boxHalfExtents,
855  int openDim,
856  int openDimCutSign,
857  const agx::Vec3& rayStartPoint,
858  const agx::Vec3& rayDir,
859  agx::Interval& interval,
860  const agx::Real epsilon)
861  {
862  {
863  int dim1 = (openDim + 1) % 3;
864  if (!clipRayToSlab( boxHalfExtents[dim1], dim1, rayStartPoint, rayDir, interval, epsilon ))
865  return false;
866  }
867  {
868  agx::Interval tmpInterval0;
869  int dim2 = (openDim + 2) % 3;
870  if (!clipRayToSlab( boxHalfExtents[dim2], dim2, rayStartPoint, rayDir, tmpInterval0, epsilon ))
871  return false;
872  interval.intersectWith( tmpInterval0 );
873  if (interval.isEmpty())
874  return false;
875  }
876  {
877  agx::Interval tmpInterval1;
878  if (!clipRayToPlane( boxHalfExtents[openDim], openDim, openDimCutSign, rayStartPoint, rayDir, tmpInterval1, epsilon ))
879  return false;
880 
881  interval.intersectWith( tmpInterval1 );
882  return interval.hasElements();
883  }
884  }
885 
886  AGX_FORCE_INLINE bool clipRayToBox(
887  const agx::Vec3& boxHalfExtents,
888  const agx::Vec3& rayStartPoint,
889  const agx::Vec3& rayDir,
890  agx::Interval& interval,
891  const agx::Real epsilon)
892  {
893  if (!clipRayToSlab( boxHalfExtents[0], 0, rayStartPoint, rayDir, interval, epsilon ))
894  return false;
895  {
896  agx::Interval tmpInterval0;
897  if (!clipRayToSlab( boxHalfExtents[1], 1, rayStartPoint, rayDir, tmpInterval0, epsilon ))
898  return false;
899  interval.intersectWith( tmpInterval0 );
900  if (interval.isEmpty())
901  return false;
902  }
903  {
904  agx::Interval tmpInterval1;
905  if (!clipRayToSlab( boxHalfExtents[2], 2, rayStartPoint, rayDir, tmpInterval1, epsilon ))
906  return false;
907  interval.intersectWith( tmpInterval1 );
908  return interval.hasElements();
909  }
910  }
911 
912 
913  AGX_FORCE_INLINE bool clipRayToInfiniteCylinder(
914  agx::Real cylRadius,
915  const agx::Vec3& rayStartPoint,
916  const agx::Vec3& rayDir,
917  agx::Interval& interval,
918  const agx::Real epsilon)
919  {
920  if (clipLineToInfiniteCylinder( cylRadius, rayStartPoint, rayDir, interval, epsilon )) {
921  interval.intersectWithRightUnbounded( 0 );
922  return interval.hasElements();
923  }
924  return false;
925  }
926 
927  AGX_FORCE_INLINE bool clipRayToCylinder(
928  agx::Real cylRadius,
929  agx::Real cylHeight,
930  const agx::Vec3& rayStartPoint,
931  const agx::Vec3& rayDir,
932  agx::Interval& interval,
933  const agx::Real epsilon)
934  {
935  if (!clipRayToSlab( agx::Real( 0.5 ) * cylHeight, 1, rayStartPoint, rayDir, interval, epsilon ))
936  return false;
937  agx::Interval tmpInterval;
938  if (!clipRayToInfiniteCylinder( cylRadius, rayStartPoint, rayDir, tmpInterval, epsilon ))
939  return false;
940  interval.intersectWith( tmpInterval );
941  return interval.hasElements();
942  }
943 
944  AGX_FORCE_INLINE bool clipRayToSphere(
945  agx::Real sphereRadius,
946  const agx::Vec3& rayStartPoint,
947  const agx::Vec3& rayDir,
948  agx::Interval& interval,
949  const agx::Real epsilon)
950  {
951  if (clipLineToSphere( sphereRadius, rayStartPoint, rayDir, interval, epsilon )) {
952  interval.intersectWithRightUnbounded( 0 );
953  return interval.hasElements();
954  }
955  return false;
956  }
957 
958  AGX_FORCE_INLINE bool clipRayToCapsule(
959  agx::Real capsRadius,
960  agx::Real capsHeight,
961  const agx::Vec3& rayStartPoint,
962  const agx::Vec3& rayDir,
963  agx::Interval& interval,
964  const agx::Real epsilon)
965  {
966  if (clipLineToCapsule( capsRadius, capsHeight, rayStartPoint, rayDir, interval, epsilon )) {
967  interval.intersectWithRightUnbounded( 0 );
968  return interval.hasElements();
969  }
970  return false;
971  }
972 
973  AGX_FORCE_INLINE bool clipLineSegmentToPlane(
974  agx::Real planeDistance,
975  unsigned int planeDimension,
976  int planeNormalSign,
977  const agx::Vec3& lineSegmentPoint0,
978  const agx::Vec3& lineSegmentPoint1,
979  agx::Interval& interval,
980  const agx::Real epsilon)
981  {
982  if (!clipLineToPlane( planeDistance, planeDimension, planeNormalSign,
983  lineSegmentPoint0, lineSegmentPoint1 - lineSegmentPoint0, interval, epsilon )) {
984  return false;
985  }
986  interval.intersectWith( agx::Interval( -agx::RealEpsilon, agx::Real(1)+agx::RealEpsilon ));
987  return interval.hasElements();
988  }
989 
990  AGX_FORCE_INLINE bool clipLineSegmentToSlab(
991  agx::Real slabDistance,
992  unsigned int slabDimension,
993  const agx::Vec3& lineSegmentPoint0,
994  const agx::Vec3& lineSegmentPoint1,
995  agx::Interval& interval,
996  const agx::Real epsilon)
997  {
998  if (clipLineToSlab( slabDistance, slabDimension, lineSegmentPoint0, lineSegmentPoint1 - lineSegmentPoint0, interval, epsilon )) {
999  interval.intersectWith( agx::Interval( -agx::RealEpsilon, agx::Real(1)+agx::RealEpsilon ));
1000  return interval.hasElements();
1001  }
1002  return false;
1003  }
1004 
1005  AGX_FORCE_INLINE bool clipLineSegmentToDoubleSlab(
1006  agx::Real slab1Distance,
1007  unsigned int slab1Dimension,
1008  agx::Real slab2Distance,
1009  unsigned int slab2Dimension,
1010  const agx::Vec3& lineSegmentPoint0,
1011  const agx::Vec3& lineSegmentPoint1,
1012  agx::Interval& interval,
1013  const agx::Real epsilon)
1014  {
1015  if (clipLineSegmentToSlab( slab1Distance, slab1Dimension, lineSegmentPoint0, lineSegmentPoint1, interval, epsilon )) {
1016  agx::Interval tmpInt;
1017  if (clipLineSegmentToSlab( slab2Distance, slab2Dimension, lineSegmentPoint0, lineSegmentPoint1, tmpInt, epsilon )) {
1018  interval.intersectWith( tmpInt );
1019  return interval.hasElements();
1020  }
1021  }
1022  return false;
1023  }
1024 
1025  AGX_FORCE_INLINE bool clipLineSegmentToOpenBox(
1026  const agx::Vec3& boxHalfExtents,
1027  int openDim,
1028  int openDimCutSign,
1029  const agx::Vec3& lineSegmentPoint0,
1030  const agx::Vec3& lineSegmentPoint1,
1031  agx::Interval& interval,
1032  const agx::Real epsilon)
1033  {
1034  {
1035  int dim1 = (openDim + 1) % 3;
1036  if (!clipLineSegmentToSlab( boxHalfExtents[dim1], dim1, lineSegmentPoint0, lineSegmentPoint1, interval, epsilon ))
1037  return false;
1038  }
1039  {
1040  agx::Interval tmpInterval0;
1041  int dim2 = (openDim + 2) % 3;
1042  if (!clipLineSegmentToSlab( boxHalfExtents[dim2], dim2, lineSegmentPoint0, lineSegmentPoint1, tmpInterval0, epsilon ))
1043  return false;
1044  interval.intersectWith( tmpInterval0 );
1045  if (interval.isEmpty())
1046  return false;
1047  }
1048  {
1049  agx::Interval tmpInterval1;
1050  if (!clipLineSegmentToPlane( boxHalfExtents[openDim], openDim, openDimCutSign, lineSegmentPoint0, lineSegmentPoint1, tmpInterval1, epsilon ))
1051  return false;
1052 
1053  interval.intersectWith( tmpInterval1 );
1054  return interval.hasElements();
1055  }
1056  }
1057 
1058  AGX_FORCE_INLINE bool clipLineSegmentToBox(
1059  const agx::Vec3& boxHalfExtents,
1060  const agx::Vec3& lineSegmentPoint0,
1061  const agx::Vec3& lineSegmentPoint1,
1062  agx::Interval& interval,
1063  const agx::Real epsilon)
1064  {
1065  if (!clipLineSegmentToSlab( boxHalfExtents[0], 0, lineSegmentPoint0, lineSegmentPoint1, interval, epsilon ))
1066  return false;
1067  {
1068  agx::Interval tmpInterval0;
1069  if (!clipLineSegmentToSlab( boxHalfExtents[1], 1, lineSegmentPoint0, lineSegmentPoint1, tmpInterval0, epsilon ))
1070  return false;
1071  interval.intersectWith( tmpInterval0 );
1072  if (interval.isEmpty())
1073  return false;
1074  }
1075  {
1076  agx::Interval tmpInterval1;
1077  if (!clipLineSegmentToSlab( boxHalfExtents[2], 2, lineSegmentPoint0, lineSegmentPoint1, tmpInterval1, epsilon ))
1078  return false;
1079  interval.intersectWith( tmpInterval1 );
1080  return interval.hasElements();
1081  }
1082  }
1083 
1084  AGX_FORCE_INLINE bool clipLineSegmentToInfiniteCylinder(
1085  agx::Real cylRadius,
1086  const agx::Vec3& lineSegmentPoint0,
1087  const agx::Vec3& lineSegmentPoint1,
1088  agx::Interval& interval,
1089  const agx::Real epsilon)
1090  {
1091  if (clipLineToInfiniteCylinder( cylRadius, lineSegmentPoint0, lineSegmentPoint1 - lineSegmentPoint0, interval, epsilon )) {
1092  interval.intersectWith( agx::Interval( -agx::RealEpsilon, agx::Real(1)+agx::RealEpsilon ));
1093  return interval.hasElements();
1094  }
1095  return false;
1096  }
1097 
1098  AGX_FORCE_INLINE bool clipLineSegmentToCylinder(
1099  agx::Real cylRadius,
1100  agx::Real cylHeight,
1101  const agx::Vec3& lineSegmentPoint0,
1102  const agx::Vec3& lineSegmentPoint1,
1103  agx::Interval& interval,
1104  const agx::Real epsilon)
1105  {
1106  if (!clipLineSegmentToSlab( agx::Real( 0.5 ) * cylHeight, 1, lineSegmentPoint0, lineSegmentPoint1, interval, epsilon ))
1107  return false;
1108  agx::Interval tmpInterval;
1109  if (!clipLineSegmentToInfiniteCylinder( cylRadius, lineSegmentPoint0, lineSegmentPoint1, tmpInterval, epsilon ))
1110  return false;
1111  interval.intersectWith( tmpInterval );
1112  return interval.hasElements();
1113  }
1114 
1115  AGX_FORCE_INLINE bool clipLineSegmentToSphere(
1116  agx::Real sphereRadius,
1117  const agx::Vec3& lineSegmentPoint0,
1118  const agx::Vec3& lineSegmentPoint1,
1119  agx::Interval& interval,
1120  const agx::Real epsilon)
1121  {
1122  if (clipLineToSphere( sphereRadius, lineSegmentPoint0, lineSegmentPoint1 - lineSegmentPoint0, interval, epsilon )) {
1123  interval.intersectWith( agx::Interval( -agx::RealEpsilon, agx::Real(1)+agx::RealEpsilon ));
1124  return interval.hasElements();
1125  }
1126  return false;
1127  }
1128 
1129  AGX_FORCE_INLINE bool clipLineSegmentToCapsule(
1130  agx::Real capsRadius,
1131  agx::Real capsHeight,
1132  const agx::Vec3& lineSegmentPoint0,
1133  const agx::Vec3& lineSegmentPoint1,
1134  agx::Interval& interval,
1135  const agx::Real epsilon)
1136  {
1137  if (clipLineToCapsule( capsRadius, capsHeight, lineSegmentPoint0, lineSegmentPoint1 - lineSegmentPoint0, interval, epsilon )) {
1138  interval.intersectWith( agx::Interval( -agx::RealEpsilon, agx::Real(1)+agx::RealEpsilon ));
1139  return interval.hasElements();
1140  }
1141  return false;
1142  }
1143 
1144 }
1145 
1147 #endif
AGXCORE_EXPORT const Real RealEpsilon
This namespace consists of a set of classes for handling geometric intersection tests including boole...
#define AGXPHYSICS_EXPORT
const Real AGX_EQUIVALENT_EPSILON
Definition: Math.h:57
#define AGX_FORCE_INLINE
Definition: Object.h:59
double Real
Definition: Real.h:42
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97