1Math::NumSeq::PlanePathUTsuerrn(C3o)ntributed Perl DocumMeanttha:t:iNounmSeq::PlanePathTurn(3)
2
3
4
6 Math::NumSeq::PlanePathTurn -- turn sequence from PlanePath module
7
9 use Math::NumSeq::PlanePathTurn;
10 my $seq = Math::NumSeq::PlanePathTurn->new (planepath => 'DragonCurve',
11 turn_type => 'Left');
12 my ($i, $value) = $seq->next;
13
15 This is a tie-in to present turns from a "Math::PlanePath" module in
16 the form of a NumSeq sequence.
17
18 The "turn_type" choices are
19
20 "Left" 1=left, 0=right or straight
21 "Right" 1=right, 0=left or straight
22 "Straight" 1=straight, 0=left or right
23 "NotStraight" 0=straight, 1=left or right
24 "LSR" 1=left, 0=straight, -1=right
25 "SLR" 0=straight, 1=left, 2=right
26 "SRL" 0=straight, 1=right, 2=left
27
28 In each case the value at sequence index i is the turn at N=i,
29
30 i+1
31 ^
32 |
33 |
34 i-1 ---> i turn at i
35 first turn at i = n_start + 1
36
37 For multiple "arms", the turn follows that particular arm so it's
38 i-arms, i, i+arms. i values start "n_start()+arms_count()" so that
39 i-arms is "n_start()", the first N on the path. A single arm path
40 beginning N=0 has its first turn at i=1.
41
42 For "Straight", "LSR", "SLR", and "SRL", straight means either straight
43 ahead or 180-degree reversal, ie. the direction N to N+1 is along the
44 same line as N-1 to N was.
45
46 "Left" means to the left side of the N-1 to N line, so not straight or
47 right. Similarly "Right" means to the right side of the N-1 to N line,
48 so not straight or left.
49
51 See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence
52 classes.
53
54 "$seq = Math::NumSeq::PlanePathTurn->new (key=>value,...)"
55 Create and return a new sequence object. The options are
56
57 planepath string, name of a PlanePath module
58 planepath_object PlanePath object
59 turn_type string, as described above
60
61 "planepath" can be either the module part such as "SquareSpiral" or
62 a full class name "Math::PlanePath::SquareSpiral".
63
64 "$value = $seq->ith($i)"
65 Return the turn at N=$i in the PlanePath.
66
67 "$bool = $seq->pred($value)"
68 Return true if $value occurs as a turn. Often this is merely the
69 possible turn values 1,0,-1, etc, but some spiral paths for example
70 only go left or straight in which case only 1 and 0 occur and
71 "pred()" reflects that.
72
73 "$i = $seq->i_start()"
74 Return the first index $i in the sequence. This is the position
75 "rewind()" returns to.
76
77 This is "$path->n_start() - $path->arms_count()" from the PlanePath
78 object.
79
81 Turn Left or Right
82 A turn left or right is identified by considering the dX,dY at N-1 and
83 at N.
84
85 N+1 *
86 |
87 |
88 | dx2,dy2
89 |
90 N *
91 /
92 /
93 / dx1,dy1
94 N-1 *
95
96 With the two vectors dx1,dy1 and dx2,dy2 at a common origin, if the
97 dx2,dy2 is "above" the dx1,dy1 line then it's a turn to the left, or
98 below is a turn to the right
99
100 dx2,dy2
101 *
102 ^ * dx1,dy1
103 | ^
104 | /
105 |/
106 o
107
108 At dx2, the Y value of the dx1,dy1 vector is
109
110 cmpY = dx2 * dy1/dx1 if dx1 != 0
111
112 left if dy2 > cmpY
113 dy2 > dx2 * dy1/dx1
114 so dy2 * dx1 > dx2 * dy1
115
116 This cross-product comparison dy2*dx1 > dx2*dy1 works when dx1=0 too,
117 ie. when dx1,dy1 is vertical
118
119 left if dy2 * 0 > dx2 * dy1
120 0 > dx2*dy1
121 good, left if dx2 and dy1 opposite signs
122
123 So
124
125 dy2*dx1 > dx2*dy1 left
126 dy2*dx1 < dx2*dy1 right
127 dy2*dx1 = dx2*dy1 straight, including 180 degree reverse
128
130 Math::NumSeq, Math::NumSeq::PlanePathCoord,
131 Math::NumSeq::PlanePathDelta, Math::NumSeq::PlanePathN
132
133 Math::NumberCruncher has a "Clockwise()" turn calculator
134
136 <http://user42.tuxfamily.org/math-planepath/index.html>
137
139 Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Kevin
140 Ryde
141
142 This file is part of Math-PlanePath.
143
144 Math-PlanePath is free software; you can redistribute it and/or modify
145 it under the terms of the GNU General Public License as published by
146 the Free Software Foundation; either version 3, or (at your option) any
147 later version.
148
149 Math-PlanePath is distributed in the hope that it will be useful, but
150 WITHOUT ANY WARRANTY; without even the implied warranty of
151 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
152 General Public License for more details.
153
154 You should have received a copy of the GNU General Public License along
155 with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
156
157
158
159perl v5.30.1 2020-01-30 Math::NumSeq::PlanePathTurn(3)