From b05a05a2ec315d9d8914e4023d855504a425c6db Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 17 Jun 2009 00:06:28 +0200 Subject: [PATCH] New example: Systematic testing of intersection (and approximation) algorithm(s). The idea is that approximation should generalize intersection. Hence, the example now shows that the same intersections are obtained using approximation. To also illustrate differences between the two methods to find intersections, the distance between points at optimum are computed also for the approximation solution, and these turn out to be bigger. It should be remembered that computing intersections is still more efficient than approximation (when one knows that an intersection exists). It would be possible to improve the computation of approximators so that it switches to intersection-finding once one intersection has been found, but this is not implemented at the moment. --- examples/features/intersections-other.shape | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 examples/features/intersections-other.shape diff --git a/examples/features/intersections-other.shape b/examples/features/intersections-other.shape new file mode 100644 index 00000000..88b2f01a --- /dev/null +++ b/examples/features/intersections-other.shape @@ -0,0 +1,35 @@ +pth1: @defaultunit:1%C | (0cm,0cm)>(^0°)--(^)<(1cm,1cm)>(^0°)--(^)<(2cm,~1cm)>(^0°)--(^180°)<(3cm,0cm) +line: (~1cm,1cm)--(0cm,1cm)--(1cm,~1cm) + +sl1Mark: @width:2bp & @stroking:RGB_RED | [stroke [circle 2mm]] +sl2Mark: @width:0.7bp & @stroking:RGB_BLUE | [stroke [circle 2mm]] +sla1Mark: @width:2bp & @stroking:RGB_RED | [stroke [circle 3mm]] +sla2Mark: @width:0.7bp & @stroking:RGB_BLUE | [stroke [circle 3mm]] + +fixedHead: [ShapesArrow width:3bp ...] + +helper: \ pth1 pth2 → +{ + sl: [intersection pth1 pth2] + sla: [approximator pth1 pth2] + ( newGroup + << [stroke pth1 head:fixedHead] + << @width:0.3bp | [stroke pth2 head:fixedHead] + << sl1Mark >> [shift sl.p] + << sl2Mark >> [shift sl.info.other.p] + << sla1Mark >> [shift sla.p] + << sla2Mark >> [shift sla.info.other.p] + << ( newText << ( newString << [abs sl.p - sl.info.other.p] ) ) >> [shift (0,~15mm)] + << ( newText << ( newString << [abs sla.p - sla.info.other.p] ) ) >> [shift (0,~20mm)] + ) +} + +##unit d = 5cm + +helper2: \ pth1 pth2 → ( [helper pth1 pth2] & [[shift (1d,0)] [helper pth2 pth1]] ) +helper8: \ pth1 pth2 → ( [helper2 pth1 pth2] & [[shift (0,~1d)] [helper2 pth1 [reverse pth2]]] & [[shift (0,~2d)] [helper2 [reverse pth1] pth2]] & [[shift (0,~3d)] [helper2 [reverse pth1] [reverse pth2]]] ) + +•page << [helper8 pth1 line] >> [shift (0d,0cm)] + << [helper8 [shift (5mm,0)]*[scale x:~1][]line line] >> [shift (2d,0cm)] + << [helper8 [shift (~5mm,0)]*[scale x:~1][]line line] >> [shift (4d,0cm)] + << [helper8 pth1 [shift (0.5cm,~1cm)]*[rotate 60°][]pth1] >> [shift (6d,0cm)] -- 2.11.4.GIT