/
predicates_3.py
1111 lines (894 loc) · 35.2 KB
/
predicates_3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from compas.geometry import area_triangle
from compas.geometry import centroid_points
from compas.geometry import closest_point_on_segment
from compas.geometry import cross_vectors
from compas.geometry import distance_point_line
from compas.geometry import distance_point_plane
from compas.geometry import distance_point_point
from compas.geometry import dot_vectors
from compas.geometry import length_vector
from compas.geometry import normal_polygon
from compas.geometry import subtract_vectors
from compas.tolerance import TOL
from compas.utilities import window
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# Colinear, Coplanar
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
def is_colinear(a, b, c, tol=None):
"""Determine if three points are colinear.
Parameters
----------
a : [float, float, float] | :class:`compas.geometry.Point`
Point 1.
b : [float, float, float] | :class:`compas.geometry.Point`
Point 2.
c : [float, float, float] | :class:`compas.geometry.Point`
Point 3.
tol : float, optional
Tolerance for comparing the area of the triangle formed by the three points to zero.
Default is :attr:`TOL.absolute`.
Returns
-------
bool
True if the points are colinear.
False otherwise.
See Also
--------
is_colinear_line_line
is_coplanar
"""
return TOL.is_zero(area_triangle([a, b, c]), tol)
def is_colinear_line_line(line1, line2, tol=None):
"""Determine if two lines are colinear.
Parameters
----------
line1 : [point, point] | :class:`compas.geometry.Line`
Line 1.
line2 : [point, point] | :class:`compas.geometry.Line`
Line 2.
tol : float, optional
Tolerance for colinearity verification.
Default is :attr:`TOL.absolute`.
Returns
-------
bool
True if the lines are colinear.
False otherwise.
See Also
--------
is_colinear
is_coplanar
"""
a, b = line1
c, d = line2
return is_colinear(a, b, c, tol) and is_colinear(a, b, d, tol)
def is_coplanar(points, tol=None):
"""Determine if the points are coplanar.
Parameters
----------
points : sequence[point]
A sequence of point locations.
tol : float, optional
A tolerance for planarity validation.
Returns
-------
bool
True if the points are coplanar.
False otherwise.
See Also
--------
is_colinear
is_colinear_line_line
Notes
-----
Compute the normal vector (cross product) of the vectors formed by the first three points.
Taking the first point as base point, include one more vector at a time and check if that vector is perpendicular to the normal vector.
If all vectors are perpendicular, the points are coplanar.
"""
if len(points) < 4:
return True
temp = points[:]
while len(temp) >= 3:
a = temp.pop(0)
b = temp.pop(0)
c = temp.pop(0)
if not is_colinear(a, b, c, tol):
break
if not temp:
return True
n = cross_vectors(subtract_vectors(b, a), subtract_vectors(c, a))
return all(is_perpendicular_vector_vector(n, subtract_vectors(d, a), tol) for d in temp)
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# Parallel, Perpendicular
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
def is_parallel_vector_vector(u, v, tol=None):
"""Determine if two vectors are parallel.
Parameters
----------
u : [float, float, float] | :class:`~compas.geometry.Vector`
Vector 1.
v : [float, float, float] | :class:`~compas.geometry.Vector`
Vector 2.
tol : float, optional
Tolerance for comparing the length of the cross product of the two vectors to zero.
Default is :attr:`TOL.absolute`.
Returns
-------
bool
True if the vectors are parallel.
False otherwise.
See Also
--------
is_parallel_line_line
is_parallel_plane_plane
Notes
-----
The length of the cross product of two vectors is equal to the area of the parallelogram formed by the two vectors.
If the vectors are parallel, the area of the parallelogram is zero.
Therefore, this predicate is based on the comparison of the length of the cross product of the two vectors to zero,
and not on the comparison to zero of the actual angle between the two vectors.
"""
# Lv = length_vector(v)
# V = scale_vector(v, 1 / Lv)
# sinus = length_vector(scale_vector(subtract_vectors(scale_vector(V, dot_vectors(u, V)), u), Lv))
# # for small angles, the sinus is equal to the angle in radians
# # for larger angles, it doesn't matter :)
# return TOL.is_angle_zero(sinus, tol)
return TOL.is_zero(length_vector(cross_vectors(u, v)), tol)
def is_parallel_line_line(line1, line2, tol=None):
"""Determine if two lines are parallel.
Parameters
----------
line1 : [point, point] | :class:`compas.geometry.Line`
Line 1.
line2 : [point, point] | :class:`compas.geometry.Line`
Line 2.
tol : float, optional
Tolerance for comparing the length of the cross product of the direction vectors of the two lines to zero.
Default is :attr:`TOL.absolute`.
Returns
-------
bool
True if the lines are colinear.
False otherwise.
See Also
--------
is_parallel_vector_vector
is_parallel_plane_plane
is_perpendicular_line_line
"""
a, b = line1
c, d = line2
ab = subtract_vectors(b, a)
cd = subtract_vectors(d, c)
return is_parallel_vector_vector(ab, cd, tol)
def is_parallel_plane_plane(plane1, plane2, tol=None):
"""Determine if two planes are parallel.
Parameters
----------
plane1 : [point, vector] | :class:`compas.geometry.Plane`
Plane 1.
plane2 : [point, vector] | :class:`compas.geometry.Plane`
Plane 2.
tol : float, optional
A tolerance for verifying parallelity of the plane normals.
Returns
-------
bool
True if the planes are parallel.
False otherwise.
See Also
--------
is_parallel_vector_vector
is_parallel_line_line
is_perpendicular_plane_plane
"""
return is_parallel_vector_vector(plane1[1], plane2[1], tol)
def is_perpendicular_vector_vector(u, v, tol=None):
"""Determine if two vectors are perpendicular.
Parameters
----------
u : [float, float, float] | :class:`~compas.geometry.Vector`
Vector 1.
v : [float, float, float] | :class:`~compas.geometry.Vector`
Vector 2.
tol : float, optional
Tolerance for comparing the dot product of the two vectors to zero.
Default is :attr:`TOL.absolute`.
Returns
-------
bool
True if the vectors are perpendicular.
False otherwise.
See Also
--------
is_perpendicular_line_line
is_perpendicular_plane_plane
Notes
-----
The dot product of two vectors is equal to the product of the lengths of the two vectors and the cosine of the angle between the two vectors.
If the vectors are perpendicular, the cosine of the angle between the two vectors is zero.
Therefore, this predicate is based on the comparison of the dot product of the two vectors to zero,
and not on the comparison to zero of the actual angle between the two vectors.
"""
return TOL.is_zero(dot_vectors(u, v), tol)
def is_perpendicular_line_line(line1, line2, tol=None):
"""Determine if two lines are perpendicular.
Parameters
----------
line1 : [point, point] | :class:`~compas.geometry.Line`
Line 1.
line2 : [point, point] | :class:`~compas.geometry.Line`
Line 2.
tol : float, optional
Tolerance for verifying the perpendicularity of the direction vectors of the two lines.
Default is :attr:`TOL.absolute`.
Returns
-------
bool
True if the lines are perpendicular.
False otherwise.
See Also
--------
is_perpendicular_vector_vector
is_perpendicular_plane_plane
"""
a, b = line1
c, d = line2
ab = subtract_vectors(b, a)
cd = subtract_vectors(d, c)
return is_perpendicular_vector_vector(ab, cd, tol)
def is_perpendicular_plane_plane(plane1, plane2, tol=None):
"""Determine if two planes are perpendicular.
Parameters
----------
plane1 : [point, vector] | :class:`compas.geometry.Plane`
Plane 1.
plane2 : [point, vector] | :class:`compas.geometry.Plane`
Plane 2.
tol : float, optional
A tolerance for verifying perpendicularity of the plane normals.
Returns
-------
bool
True if the planes are perpendicular.
False otherwise.
See Also
--------
is_perpendicular_vector_vector
is_perpendicular_line_line
is_parallel_plane_plane
"""
return is_perpendicular_vector_vector(plane1[1], plane2[1], tol)
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# Convexity
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
def is_polygon_convex(polygon):
"""Determine if a polygon is convex.
Parameters
----------
polygon : sequence[point] | :class:`compas.geometry.Polygon`
A polygon.
Returns
-------
bool
True if the polygon is convex.
False otherwise.
See Also
--------
is_polyhedron_convex
Notes
-----
Use this function for *spatial* polygons.
If the polygon is in a horizontal plane, use :func:`is_polygon_convex_xy` instead.
Examples
--------
>>> polygon = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.4, 0.4, 0.0], [0.0, 1.0, 0.0]]
>>> is_polygon_convex(polygon)
False
"""
a = polygon[0]
o = polygon[1]
b = polygon[2]
oa = subtract_vectors(a, o)
ob = subtract_vectors(b, o)
n0 = cross_vectors(oa, ob)
for a, o, b in window(polygon + polygon[:2], 3):
oa = subtract_vectors(a, o)
ob = subtract_vectors(b, o)
n = cross_vectors(oa, ob)
if dot_vectors(n, n0) >= 0:
continue
else:
return False
return True
def is_polyhedron_convex(polyhedron):
"""Determine if a polyhedron is convex.
Parameters
----------
polyhedron : [sequence[point], sequence[sequence[int]]] | :class:`compas.geometry.Polyhedron`
A polyhedron defined by a sequence of points
and a sequence of faces, with each face defined as a sequence of indices into the sequence of points.
Returns
-------
bool
True if the polyhedron is convex.
False otherwise.
See Also
--------
is_polygon_convex
"""
vertices, faces = polyhedron
for face in faces:
base = vertices[face[0]]
normal = normal_polygon([vertices[index] for index in face])
direction = None
for i in range(len(vertices)):
if i not in face:
point = vertices[i]
if direction is None:
direction = dot_vectors(subtract_vectors(point, base), normal) >= 0
else:
if dot_vectors(subtract_vectors(point, base), normal) >= 0 != direction:
return False
return True
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# Containment (Plane)
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
def is_point_on_plane(point, plane, tol=None):
"""Determine if a point lies on a plane.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
A point.
plane : [point, vector] | :class:`compas.geometry.Plane`
A plane.
tol : float, optional
Tolerance for comparing the distance between the point and the plane to zero.
Default is :attr:`TOL.absolute`.
Returns
-------
bool
True if the point is in on the plane.
False otherwise.
"""
return TOL.is_zero(distance_point_plane(point, plane), tol)
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# Containment (Curves)
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
def is_point_on_line(point, line, tol=None):
"""Determine if a point lies on a line.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
A point.
line : [point, point] | :class:`compas.geometry.Line`
A line.
tol : float, optional
Tolerance for comparing the distance between the point and the line to zero.
Default is :attr:`TOL.absolute`.
Returns
-------
bool
True if the point is in on the line.
False otherwise.
"""
return TOL.is_zero(distance_point_line(point, line), tol)
def is_point_on_segment(point, segment, tol=None):
"""Determine if a point lies on a given line segment.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
A point.
segment : [point, point] | :class:`compas.geometry.Line`
A line segment.
tol : float, optional
Tolerance for comparing the distance between the point and the line segment to zero.
Default is :attr:`TOL.absolute`.
Returns
-------
bool
True if the point is on the line segment.
False otherwise.
"""
a, b = segment
d_ab = distance_point_point(a, b)
if d_ab == 0:
return False
if not is_point_on_line(point, (a, b), tol=tol):
return False
d_pa = distance_point_point(a, point)
d_pb = distance_point_point(b, point)
if TOL.is_close(d_pa + d_pb, d_ab, rtol=0, atol=tol):
return True
return False
def is_point_on_polyline(point, polyline, tol=None):
"""Determine if a point is on a polyline.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
A point.
polyline : sequence[point] | :class:`compas.geometry.Polyline`
A polyline.
tol : float, optional
Tolerance for comparing the distance between the point and the polyline to zero.
Default is :attr:`TOL.absolute`.
Returns
-------
bool
True if the point is on the polyline.
False otherwise.
"""
for i in range(len(polyline) - 1):
a = polyline[i]
b = polyline[i + 1]
c = closest_point_on_segment(point, (a, b))
if TOL.is_zero(distance_point_point(point, c), tol):
return True
return False
def is_point_on_circle(point, circle, tol=None):
"""Determine if a point lies on a circle.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
A point.
circle : [plane, float]
A circle.
tol : float, optional
A tolerance for membership verification.
Returns
-------
bool
True if the point lies on the circle.
False otherwise.
"""
plane, radius = circle
if is_point_on_plane(point, plane):
return TOL.is_zero(distance_point_point(point, plane[0]) - radius, tol)
return False
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# Containment (Surfaces)
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# Containment (Shapes)
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
def is_point_in_circle(point, circle, tol=None):
"""Determine if a point lies in a circle.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
A point.
circle : [plane, float]
A circle.
Returns
-------
bool
True if the point lies in the circle.
False otherwise.
"""
plane, radius = circle
if is_point_on_plane(point, plane, tol=tol):
return TOL.is_positive(radius - distance_point_point(point, plane[0]), tol)
return False
def is_point_in_triangle(point, triangle, tol=None):
"""Determine if a point is in the interior of a triangle.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
A point.
triangle : [point, point, point]
A triangle.
Returns
-------
bool
True if the point is in inside the triangle.
False otherwise.
See Also
--------
compas.geometry.is_point_in_triangle_xy
"""
def is_on_same_side(p1, p2, segment):
a, b = segment
v = subtract_vectors(b, a)
c1 = cross_vectors(v, subtract_vectors(p1, a))
c2 = cross_vectors(v, subtract_vectors(p2, a))
if dot_vectors(c1, c2) >= 0:
return True
return False
a, b, c = triangle
if is_point_on_plane(point, (a, normal_polygon(triangle)), tol=tol):
if is_on_same_side(point, a, (b, c)) and is_on_same_side(point, b, (a, c)) and is_on_same_side(point, c, (a, b)):
return True
return False
def is_point_in_polygon(point, polygon, tol=None):
"""Determine if a point is in the interior of a polygon.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
A point.
polygon : sequence[point] | :class:`compas.geometry.Polygon`
A polygon.
Returns
-------
bool
True if the point is in inside the polygon.
False otherwise.
"""
raise NotImplementedError
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# Containment (Solids)
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
def is_point_in_sphere(point, sphere, tol=None):
"""Determine if a point lies in a sphere.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
A point.
sphere : [point, float]
A sphere.
Returns
-------
bool
True if the point lies in the sphere.
False otherwise.
"""
center, radius = sphere
return TOL.is_positive(radius - distance_point_point(point, center), tol)
def is_point_in_aab(point, box, tol=None):
"""Determine if a point lies in an axis-aligned box.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
A point.
box : [[float, float, float], [float, float, float]] | [:class:`compas.geometry.Point`, :class:`compas.geometry.Point``]
An axis-aligned box defined by the min/max corners.
Returns
-------
bool
True if the point lies in the box.
False otherwise.
"""
a, b = box
return all(TOL.is_between(point[i], minval=a[i], maxval=b[i], atol=tol) for i in range(3))
def is_point_in_polyhedron(point, polyhedron, tol=None):
"""Determine if the point lies inside the given polyhedron.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
The test point.
polyhedron : [sequence[point], sequence[sequence[int]]] | :class:`compas.geometry.Polyhedron`.
The polyhedron defined by a sequence of points
and a sequence of faces, with each face defined as a sequence of indices into the sequence of points.
Returns
-------
bool
True, if the point lies in the polyhedron.
False, otherwise.
"""
vertices, faces = polyhedron
polygons = [[vertices[index] for index in face] for face in faces]
planes = [[centroid_points(polygon), normal_polygon(polygon)] for polygon in polygons]
return all(is_point_behind_plane(point, plane, tol=tol) for plane in planes)
def is_point_infrontof_plane(point, plane, tol=None):
"""Determine if a point lies in front of a plane.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
A point.
plane : [point, vector] | :class:`compas.geometry.Plane`
A plane.
tol : float, optional
A tolerance for membership verification.
Returns
-------
bool
True if the point is in front of the plane.
False otherwise.
"""
return TOL.is_positive(dot_vectors(subtract_vectors(point, plane[0]), plane[1]), tol)
def is_point_behind_plane(point, plane, tol=None):
"""Determine if a point lies behind a plane.
Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`
A point.
plane : [point, normal] | :class:`compas.geometry.Plane`
A plane.
tol : float, optional
A tolerance for membership verification.
Returns
-------
bool
True if the point is in front of the plane.
False otherwise.
"""
return TOL.is_negative(dot_vectors(subtract_vectors(point, plane[0]), plane[1]), tol)
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# Deprecated
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# =============================================================================
# def is_intersection_line_line(l1, l2, tol=None):
# """Verifies if two lines intersect.
# Parameters
# ----------
# l1 : [point, point] | :class:`compas.geometry.Line`
# A line.
# l2 : [point, point] | :class:`compas.geometry.Line`
# A line.
# tol : float, optional
# A tolerance for intersection verification.
# Returns
# -------
# bool
# True if the lines intersect in one point.
# False if the lines are skew, parallel or lie on top of each other.
# """
# a, b = l1
# c, d = l2
# e1 = normalize_vector(subtract_vectors(b, a))
# e2 = normalize_vector(subtract_vectors(d, c))
# # check for parallel lines
# if abs(dot_vectors(e1, e2)) > 1.0 - tol:
# return False
# # check for intersection
# if abs(dot_vectors(cross_vectors(e1, e2), subtract_vectors(c, a))) < tol:
# return True
# return False
# def is_intersection_segment_segment(s1, s2, tol=None):
# """Verifies if two segments intersect.
# Parameters
# ----------
# s1 : [point, point] | :class:`compas.geometry.Line`
# A line segment.
# s2 : [point, point] | :class:`compas.geometry.Line`
# A line segment.
# tol : float, optional
# A tolerance for intersection verification.
# Returns
# -------
# bool
# True if the segments intersect in one point.
# False if the segments are skew, parallel or lie on top of each other.
# """
# raise NotImplementedError
# def is_intersection_line_triangle(line, triangle, tol=None):
# """Verifies if a line (ray) intersects with a triangle.
# Parameters
# ----------
# line : [point, point] | :class:`compas.geometry.Line`
# A line.
# triangle : [point, point, point]
# A triangle.
# tol : float, optional
# A tolerance for intersection verification.
# Returns
# -------
# bool
# True if the line (ray) intersects with the triangle.
# False otherwise.
# Notes
# -----
# Based on the Moeller Trumbore intersection algorithm.
# The line is treated as continues, directed ray and not as line segment with a start and end point
# Examples
# --------
# >>>
# """
# a, b, c = triangle
# # direction vector and base point of line
# v1 = subtract_vectors(line[1], line[0])
# p1 = line[0]
# # Find vectors for two edges sharing triangle vertex 1
# e1 = subtract_vectors(b, a)
# e2 = subtract_vectors(c, a)
# # Begin calculating determinant - also used to calculate u parameter
# p = cross_vectors(v1, e2)
# # if determinant is near zero, ray lies in plane of triangle
# det = dot_vectors(e1, p)
# # NOT CULLING
# if det > -tol and det < tol:
# return False
# inv_det = 1.0 / det
# # calculate distance from V1 to ray origin
# t = subtract_vectors(p1, a)
# # Calculate u parameter and make_blocks bound
# u = dot_vectors(t, p) * inv_det
# # The intersection lies outside of the triangle