AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LineClipping.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 
231  AGXPHYSICS_EXPORT bool clipLineToSphere(
232  agx::Real sphereRadius,
233  const agx::Vec3& linePoint,
234  const agx::Vec3& lineDir,
235  agx::Interval& interval,
236  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
237 
238 
252  AGXPHYSICS_EXPORT bool clipLineToCapsule(
253  agx::Real capsRadius,
254  agx::Real capsHeight,
255  const agx::Vec3& linePoint,
256  const agx::Vec3& lineDir,
257  agx::Interval& interval,
258  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
259 
260 
276  AGXPHYSICS_EXPORT bool clipRayToPlane(
277  agx::Real planeDistance,
278  unsigned int planeDimension,
279  int planeNormalSign,
280  const agx::Vec3& rayStartPoint,
281  const agx::Vec3& rayDir,
282  agx::Interval& interval,
283  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
284 
285 
300  AGXPHYSICS_EXPORT bool clipRayToSlab(
301  agx::Real slabDistance,
302  unsigned int slabDimension,
303  const agx::Vec3& rayStartPoint,
304  const agx::Vec3& rayDir,
305  agx::Interval& interval,
306  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
307 
308 
325  AGXPHYSICS_EXPORT bool clipRayToDoubleSlab(
326  agx::Real slab1Distance,
327  unsigned int slab1Dimension,
328  agx::Real slab2Distance,
329  unsigned int slab2Dimension,
330  const agx::Vec3& rayStartPoint,
331  const agx::Vec3& rayDir,
332  agx::Interval& interval,
333  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
334 
335 
348  AGXPHYSICS_EXPORT bool clipRayToOpenBox(
349  const agx::Vec3& boxHalfExtents,
350  int openDim,
351  int openDimCutSign,
352  const agx::Vec3& rayStartPoint,
353  const agx::Vec3& rayDir,
354  agx::Interval& interval,
355  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
356 
357 
358 
372  AGXPHYSICS_EXPORT bool clipRayToBox(
373  const agx::Vec3& boxHalfExtents,
374  const agx::Vec3& rayStartPoint,
375  const agx::Vec3& rayDir,
376  agx::Interval& interval,
377  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
378 
379 
380 
393  AGXPHYSICS_EXPORT bool clipRayToInfiniteCylinder(
394  agx::Real cylRadius,
395  const agx::Vec3& rayStartPoint,
396  const agx::Vec3& rayDir,
397  agx::Interval& interval,
398  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
399 
400 
401 
415  AGXPHYSICS_EXPORT bool clipRayToCylinder(
416  agx::Real cylRadius,
417  agx::Real cylHeight,
418  const agx::Vec3& rayStartPoint,
419  const agx::Vec3& rayDir,
420  agx::Interval& interval,
421  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
422 
423 
424 
436  AGXPHYSICS_EXPORT bool clipRayToSphere(
437  agx::Real sphereRadius,
438  const agx::Vec3& rayStartPoint,
439  const agx::Vec3& rayDir,
440  agx::Interval& interval,
441  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
442 
443 
444 
458  AGXPHYSICS_EXPORT bool clipRayToCapsule(
459  agx::Real capsRadius,
460  agx::Real capsHeight,
461  const agx::Vec3& rayStartPoint,
462  const agx::Vec3& rayDir,
463  agx::Interval& interval,
464  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
465 
466 
467 
483  AGXPHYSICS_EXPORT bool clipLineSegmentToPlane(
484  agx::Real planeDistance,
485  unsigned int planeDimension,
486  int planeNormalSign,
487  const agx::Vec3& lineSegmentPoint0,
488  const agx::Vec3& lineSegmentPoint1,
489  agx::Interval& interval,
490  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
491 
492 
493 
508  AGXPHYSICS_EXPORT bool clipLineSegmentToSlab(
509  agx::Real slabDistance,
510  unsigned int slabDimension,
511  const agx::Vec3& lineSegmentPoint0,
512  const agx::Vec3& lineSegmentPoint1,
513  agx::Interval& interval,
514  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
515 
516 
517 
534  AGXPHYSICS_EXPORT bool clipLineSegmentToDoubleSlab(
535  agx::Real slab1Distance,
536  unsigned int slab1Dimension,
537  agx::Real slab2Distance,
538  unsigned int slab2Dimension,
539  const agx::Vec3& lineSegmentPoint0,
540  const agx::Vec3& lineSegmentPoint1,
541  agx::Interval& interval,
542  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
543 
544 
545 
558  AGXPHYSICS_EXPORT bool clipLineSegmentToOpenBox(
559  const agx::Vec3& boxHalfExtents,
560  int openDim,
561  int openDimCutSign,
562  const agx::Vec3& lineSegmentPoint0,
563  const agx::Vec3& lineSegmentPoint1,
564  agx::Interval& interval,
565  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
566 
567 
581  AGXPHYSICS_EXPORT bool clipLineSegmentToBox(
582  const agx::Vec3& boxHalfExtents,
583  const agx::Vec3& lineSegmentPoint0,
584  const agx::Vec3& lineSegmentPoint1,
585  agx::Interval& interval,
586  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
587 
588 
589 
602  AGXPHYSICS_EXPORT bool clipLineSegmentToInfiniteCylinder(
603  agx::Real cylRadius,
604  const agx::Vec3& lineSegmentPoint0,
605  const agx::Vec3& lineSegmentPoint1,
606  agx::Interval& interval,
607  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
608 
609 
623  AGXPHYSICS_EXPORT bool clipLineSegmentToCylinder(
624  agx::Real cylRadius,
625  agx::Real cylHeight,
626  const agx::Vec3& lineSegmentPoint0,
627  const agx::Vec3& lineSegmentPoint1,
628  agx::Interval& interval,
629  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
630 
631 
643  AGXPHYSICS_EXPORT bool clipLineSegmentToSphere(
644  agx::Real sphereRadius,
645  const agx::Vec3& lineSegmentPoint0,
646  const agx::Vec3& lineSegmentPoint1,
647  agx::Interval& interval,
648  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
649 
650 
664  AGXPHYSICS_EXPORT bool clipLineSegmentToCapsule(
665  agx::Real capsRadius,
666  agx::Real capsHeight,
667  const agx::Vec3& lineSegmentPoint0,
668  const agx::Vec3& lineSegmentPoint1,
669  agx::Interval& interval,
670  const agx::Real epsilon = agx::AGX_EQUIVALENT_EPSILON );
671 
672 
673 
674 
675  /* Implementation */
676 
677  AGX_FORCE_INLINE bool clipLineToDoubleSlab(
678  agx::Real slab1Distance,
679  unsigned int slab1Dimension,
680  agx::Real slab2Distance,
681  unsigned int slab2Dimension,
682  const agx::Vec3& linePoint,
683  const agx::Vec3& lineDir,
684  agx::Interval& interval,
685  const agx::Real epsilon)
686  {
687  if (clipLineToSlab( slab1Distance, slab1Dimension, linePoint, lineDir, interval, epsilon )) {
688  agx::Interval tmpInt;
689  if (clipLineToSlab( slab2Distance, slab2Dimension, linePoint, lineDir, tmpInt, epsilon )) {
690  interval.intersectWith( tmpInt );
691  return interval.hasElements();
692  }
693  }
694  return false;
695  }
696 
697  AGX_FORCE_INLINE bool clipLineToOpenBox(
698  const agx::Vec3& boxHalfExtents,
699  int openDim,
700  int openDimCutSign,
701  const agx::Vec3& linePoint,
702  const agx::Vec3& lineDir,
703  agx::Interval& interval,
704  const agx::Real epsilon)
705  {
706  {
707  int dim1 = (openDim + 1) % 3;
708  if (!clipLineToSlab( boxHalfExtents[dim1], dim1, linePoint, lineDir, interval, epsilon ))
709  return false;
710  }
711  {
712  agx::Interval tmpInterval0;
713  int dim2 = (openDim + 2) % 3;
714  if (!clipLineToSlab( boxHalfExtents[dim2], dim2, linePoint, lineDir, tmpInterval0, epsilon ))
715  return false;
716  interval.intersectWith( tmpInterval0 );
717  if (interval.isEmpty())
718  return false;
719 
720  }
721  {
722  agx::Interval tmpInterval1;
723  if (!clipLineToPlane( boxHalfExtents[openDim], openDim, openDimCutSign, linePoint, lineDir, tmpInterval1, epsilon ))
724  return false;
725 
726  interval.intersectWith( tmpInterval1 );
727  return interval.hasElements();
728  }
729  }
730 
731  AGX_FORCE_INLINE bool clipLineToBox(
732  const agx::Vec3& boxHalfExtents,
733  const agx::Vec3& linePoint,
734  const agx::Vec3& lineDir,
735  agx::Interval& interval,
736  const agx::Real epsilon)
737  {
738  if (!clipLineToSlab( boxHalfExtents[0], 0, linePoint, lineDir, interval, epsilon ))
739  return false;
740  {
741  agx::Interval tmpInterval0;
742  if (!clipLineToSlab( boxHalfExtents[1], 1, linePoint, lineDir, tmpInterval0, epsilon ))
743  return false;
744  interval.intersectWith( tmpInterval0 );
745  if (interval.isEmpty())
746  return false;
747  }
748  {
749  agx::Interval tmpInterval1;
750  if (!clipLineToSlab( boxHalfExtents[2], 2, linePoint, lineDir, tmpInterval1, epsilon ))
751  return false;
752  interval.intersectWith( tmpInterval1 );
753  return interval.hasElements();
754  }
755  }
756 
757  AGX_FORCE_INLINE bool clipLineToCylinder(
758  agx::Real cylRadius,
759  agx::Real cylHeight,
760  const agx::Vec3& linePoint,
761  const agx::Vec3& lineDir,
762  agx::Interval& interval,
763  const agx::Real epsilon)
764  {
765  if (!clipLineToSlab( agx::Real( 0.5 ) * cylHeight, 1, linePoint, lineDir, interval, epsilon ))
766  return false;
767  agx::Interval tmpInterval;
768  if (!clipLineToInfiniteCylinder( cylRadius, linePoint, lineDir, tmpInterval, epsilon ))
769  return false;
770  interval.intersectWith( tmpInterval );
771  return interval.hasElements();
772  }
773 
774  AGX_FORCE_INLINE bool clipRayToPlane(
775  agx::Real planeDistance,
776  unsigned int planeDimension,
777  int planeNormalSign,
778  const agx::Vec3& rayStartPoint,
779  const agx::Vec3& rayDir,
780  agx::Interval& interval,
781  const agx::Real epsilon)
782  {
783  if (!clipLineToPlane( planeDistance, planeDimension, planeNormalSign,
784  rayStartPoint, rayDir, interval, epsilon ))
785  return false;
786  interval.intersectWithRightUnbounded( 0 );
787  return interval.hasElements();
788  }
789 
790  AGX_FORCE_INLINE bool clipRayToSlab(
791  agx::Real slabDistance,
792  unsigned int slabDimension,
793  const agx::Vec3& rayStartPoint,
794  const agx::Vec3& rayDir,
795  agx::Interval& interval,
796  const agx::Real epsilon)
797  {
798  if (clipLineToSlab( slabDistance, slabDimension, rayStartPoint, rayDir, interval, epsilon )) {
799  interval.intersectWithRightUnbounded( 0 );
800  return interval.hasElements();
801  }
802  return false;
803  }
804 
805  AGX_FORCE_INLINE bool clipRayToDoubleSlab(
806  agx::Real slab1Distance,
807  unsigned int slab1Dimension,
808  agx::Real slab2Distance,
809  unsigned int slab2Dimension,
810  const agx::Vec3& rayStartPoint,
811  const agx::Vec3& rayDir,
812  agx::Interval& interval,
813  const agx::Real epsilon)
814  {
815  if (clipRayToSlab( slab1Distance, slab1Dimension, rayStartPoint, rayDir, interval, epsilon )) {
816  agx::Interval tmpInt;
817  if (clipRayToSlab( slab2Distance, slab2Dimension, rayStartPoint, rayDir, tmpInt, epsilon )) {
818  interval.intersectWith( tmpInt );
819  return interval.hasElements();
820  }
821  }
822  return false;
823  }
824 
825 
826  AGX_FORCE_INLINE bool clipRayToOpenBox(
827  const agx::Vec3& boxHalfExtents,
828  int openDim,
829  int openDimCutSign,
830  const agx::Vec3& rayStartPoint,
831  const agx::Vec3& rayDir,
832  agx::Interval& interval,
833  const agx::Real epsilon)
834  {
835  {
836  int dim1 = (openDim + 1) % 3;
837  if (!clipRayToSlab( boxHalfExtents[dim1], dim1, rayStartPoint, rayDir, interval, epsilon ))
838  return false;
839  }
840  {
841  agx::Interval tmpInterval0;
842  int dim2 = (openDim + 2) % 3;
843  if (!clipRayToSlab( boxHalfExtents[dim2], dim2, rayStartPoint, rayDir, tmpInterval0, epsilon ))
844  return false;
845  interval.intersectWith( tmpInterval0 );
846  if (interval.isEmpty())
847  return false;
848  }
849  {
850  agx::Interval tmpInterval1;
851  if (!clipRayToPlane( boxHalfExtents[openDim], openDim, openDimCutSign, rayStartPoint, rayDir, tmpInterval1, epsilon ))
852  return false;
853 
854  interval.intersectWith( tmpInterval1 );
855  return interval.hasElements();
856  }
857  }
858 
859  AGX_FORCE_INLINE bool clipRayToBox(
860  const agx::Vec3& boxHalfExtents,
861  const agx::Vec3& rayStartPoint,
862  const agx::Vec3& rayDir,
863  agx::Interval& interval,
864  const agx::Real epsilon)
865  {
866  if (!clipRayToSlab( boxHalfExtents[0], 0, rayStartPoint, rayDir, interval, epsilon ))
867  return false;
868  {
869  agx::Interval tmpInterval0;
870  if (!clipRayToSlab( boxHalfExtents[1], 1, 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 (!clipRayToSlab( boxHalfExtents[2], 2, rayStartPoint, rayDir, tmpInterval1, epsilon ))
879  return false;
880  interval.intersectWith( tmpInterval1 );
881  return interval.hasElements();
882  }
883  }
884 
885 
886  AGX_FORCE_INLINE bool clipRayToInfiniteCylinder(
887  agx::Real cylRadius,
888  const agx::Vec3& rayStartPoint,
889  const agx::Vec3& rayDir,
890  agx::Interval& interval,
891  const agx::Real epsilon)
892  {
893  if (clipLineToInfiniteCylinder( cylRadius, rayStartPoint, rayDir, interval, epsilon )) {
894  interval.intersectWithRightUnbounded( 0 );
895  return interval.hasElements();
896  }
897  return false;
898  }
899 
900  AGX_FORCE_INLINE bool clipRayToCylinder(
901  agx::Real cylRadius,
902  agx::Real cylHeight,
903  const agx::Vec3& rayStartPoint,
904  const agx::Vec3& rayDir,
905  agx::Interval& interval,
906  const agx::Real epsilon)
907  {
908  if (!clipRayToSlab( agx::Real( 0.5 ) * cylHeight, 1, rayStartPoint, rayDir, interval, epsilon ))
909  return false;
910  agx::Interval tmpInterval;
911  if (!clipRayToInfiniteCylinder( cylRadius, rayStartPoint, rayDir, tmpInterval, epsilon ))
912  return false;
913  interval.intersectWith( tmpInterval );
914  return interval.hasElements();
915  }
916 
917  AGX_FORCE_INLINE bool clipRayToSphere(
918  agx::Real sphereRadius,
919  const agx::Vec3& rayStartPoint,
920  const agx::Vec3& rayDir,
921  agx::Interval& interval,
922  const agx::Real epsilon)
923  {
924  if (clipLineToSphere( sphereRadius, rayStartPoint, rayDir, interval, epsilon )) {
925  interval.intersectWithRightUnbounded( 0 );
926  return interval.hasElements();
927  }
928  return false;
929  }
930 
931  AGX_FORCE_INLINE bool clipRayToCapsule(
932  agx::Real capsRadius,
933  agx::Real capsHeight,
934  const agx::Vec3& rayStartPoint,
935  const agx::Vec3& rayDir,
936  agx::Interval& interval,
937  const agx::Real epsilon)
938  {
939  if (clipLineToCapsule( capsRadius, capsHeight, rayStartPoint, rayDir, interval, epsilon )) {
940  interval.intersectWithRightUnbounded( 0 );
941  return interval.hasElements();
942  }
943  return false;
944  }
945 
946  AGX_FORCE_INLINE bool clipLineSegmentToPlane(
947  agx::Real planeDistance,
948  unsigned int planeDimension,
949  int planeNormalSign,
950  const agx::Vec3& lineSegmentPoint0,
951  const agx::Vec3& lineSegmentPoint1,
952  agx::Interval& interval,
953  const agx::Real epsilon)
954  {
955  if (!clipLineToPlane( planeDistance, planeDimension, planeNormalSign,
956  lineSegmentPoint0, lineSegmentPoint1 - lineSegmentPoint0, interval, epsilon )) {
957  return false;
958  }
959  interval.intersectWith( agx::Interval( -agx::RealEpsilon, agx::Real(1)+agx::RealEpsilon ));
960  return interval.hasElements();
961  }
962 
963  AGX_FORCE_INLINE bool clipLineSegmentToSlab(
964  agx::Real slabDistance,
965  unsigned int slabDimension,
966  const agx::Vec3& lineSegmentPoint0,
967  const agx::Vec3& lineSegmentPoint1,
968  agx::Interval& interval,
969  const agx::Real epsilon)
970  {
971  if (clipLineToSlab( slabDistance, slabDimension, lineSegmentPoint0, lineSegmentPoint1 - lineSegmentPoint0, interval, epsilon )) {
972  interval.intersectWith( agx::Interval( -agx::RealEpsilon, agx::Real(1)+agx::RealEpsilon ));
973  return interval.hasElements();
974  }
975  return false;
976  }
977 
978  AGX_FORCE_INLINE bool clipLineSegmentToDoubleSlab(
979  agx::Real slab1Distance,
980  unsigned int slab1Dimension,
981  agx::Real slab2Distance,
982  unsigned int slab2Dimension,
983  const agx::Vec3& lineSegmentPoint0,
984  const agx::Vec3& lineSegmentPoint1,
985  agx::Interval& interval,
986  const agx::Real epsilon)
987  {
988  if (clipLineSegmentToSlab( slab1Distance, slab1Dimension, lineSegmentPoint0, lineSegmentPoint1, interval, epsilon )) {
989  agx::Interval tmpInt;
990  if (clipLineSegmentToSlab( slab2Distance, slab2Dimension, lineSegmentPoint0, lineSegmentPoint1, tmpInt, epsilon )) {
991  interval.intersectWith( tmpInt );
992  return interval.hasElements();
993  }
994  }
995  return false;
996  }
997 
998  AGX_FORCE_INLINE bool clipLineSegmentToOpenBox(
999  const agx::Vec3& boxHalfExtents,
1000  int openDim,
1001  int openDimCutSign,
1002  const agx::Vec3& lineSegmentPoint0,
1003  const agx::Vec3& lineSegmentPoint1,
1004  agx::Interval& interval,
1005  const agx::Real epsilon)
1006  {
1007  {
1008  int dim1 = (openDim + 1) % 3;
1009  if (!clipLineSegmentToSlab( boxHalfExtents[dim1], dim1, lineSegmentPoint0, lineSegmentPoint1, interval, epsilon ))
1010  return false;
1011  }
1012  {
1013  agx::Interval tmpInterval0;
1014  int dim2 = (openDim + 2) % 3;
1015  if (!clipLineSegmentToSlab( boxHalfExtents[dim2], dim2, lineSegmentPoint0, lineSegmentPoint1, tmpInterval0, epsilon ))
1016  return false;
1017  interval.intersectWith( tmpInterval0 );
1018  if (interval.isEmpty())
1019  return false;
1020  }
1021  {
1022  agx::Interval tmpInterval1;
1023  if (!clipLineSegmentToPlane( boxHalfExtents[openDim], openDim, openDimCutSign, lineSegmentPoint0, lineSegmentPoint1, tmpInterval1, epsilon ))
1024  return false;
1025 
1026  interval.intersectWith( tmpInterval1 );
1027  return interval.hasElements();
1028  }
1029  }
1030 
1031  AGX_FORCE_INLINE bool clipLineSegmentToBox(
1032  const agx::Vec3& boxHalfExtents,
1033  const agx::Vec3& lineSegmentPoint0,
1034  const agx::Vec3& lineSegmentPoint1,
1035  agx::Interval& interval,
1036  const agx::Real epsilon)
1037  {
1038  if (!clipLineSegmentToSlab( boxHalfExtents[0], 0, lineSegmentPoint0, lineSegmentPoint1, interval, epsilon ))
1039  return false;
1040  {
1041  agx::Interval tmpInterval0;
1042  if (!clipLineSegmentToSlab( boxHalfExtents[1], 1, 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 (!clipLineSegmentToSlab( boxHalfExtents[2], 2, lineSegmentPoint0, lineSegmentPoint1, tmpInterval1, epsilon ))
1051  return false;
1052  interval.intersectWith( tmpInterval1 );
1053  return interval.hasElements();
1054  }
1055  }
1056 
1057  AGX_FORCE_INLINE bool clipLineSegmentToInfiniteCylinder(
1058  agx::Real cylRadius,
1059  const agx::Vec3& lineSegmentPoint0,
1060  const agx::Vec3& lineSegmentPoint1,
1061  agx::Interval& interval,
1062  const agx::Real epsilon)
1063  {
1064  if (clipLineToInfiniteCylinder( cylRadius, lineSegmentPoint0, lineSegmentPoint1 - lineSegmentPoint0, interval, epsilon )) {
1065  interval.intersectWith( agx::Interval( -agx::RealEpsilon, agx::Real(1)+agx::RealEpsilon ));
1066  return interval.hasElements();
1067  }
1068  return false;
1069  }
1070 
1071  AGX_FORCE_INLINE bool clipLineSegmentToCylinder(
1072  agx::Real cylRadius,
1073  agx::Real cylHeight,
1074  const agx::Vec3& lineSegmentPoint0,
1075  const agx::Vec3& lineSegmentPoint1,
1076  agx::Interval& interval,
1077  const agx::Real epsilon)
1078  {
1079  if (!clipLineSegmentToSlab( agx::Real( 0.5 ) * cylHeight, 1, lineSegmentPoint0, lineSegmentPoint1, interval, epsilon ))
1080  return false;
1081  agx::Interval tmpInterval;
1082  if (!clipLineSegmentToInfiniteCylinder( cylRadius, lineSegmentPoint0, lineSegmentPoint1, tmpInterval, epsilon ))
1083  return false;
1084  interval.intersectWith( tmpInterval );
1085  return interval.hasElements();
1086  }
1087 
1088  AGX_FORCE_INLINE bool clipLineSegmentToSphere(
1089  agx::Real sphereRadius,
1090  const agx::Vec3& lineSegmentPoint0,
1091  const agx::Vec3& lineSegmentPoint1,
1092  agx::Interval& interval,
1093  const agx::Real epsilon)
1094  {
1095  if (clipLineToSphere( sphereRadius, lineSegmentPoint0, lineSegmentPoint1 - lineSegmentPoint0, interval, epsilon )) {
1096  interval.intersectWith( agx::Interval( -agx::RealEpsilon, agx::Real(1)+agx::RealEpsilon ));
1097  return interval.hasElements();
1098  }
1099  return false;
1100  }
1101 
1102  AGX_FORCE_INLINE bool clipLineSegmentToCapsule(
1103  agx::Real capsRadius,
1104  agx::Real capsHeight,
1105  const agx::Vec3& lineSegmentPoint0,
1106  const agx::Vec3& lineSegmentPoint1,
1107  agx::Interval& interval,
1108  const agx::Real epsilon)
1109  {
1110  if (clipLineToCapsule( capsRadius, capsHeight, lineSegmentPoint0, lineSegmentPoint1 - lineSegmentPoint0, interval, epsilon )) {
1111  interval.intersectWith( agx::Interval( -agx::RealEpsilon, agx::Real(1)+agx::RealEpsilon ));
1112  return interval.hasElements();
1113  }
1114  return false;
1115  }
1116 
1117 }
1118 
1120 #endif
AGXCORE_EXPORT const Real RealEpsilon
#define AGXPHYSICS_EXPORT
const Real AGX_EQUIVALENT_EPSILON
Definition: Math.h:55
#define AGX_FORCE_INLINE
Definition: Object.h:62
double Real
Definition: Real.h:42
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:101
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:100