1Math::NumSeq::PlanePathUTsuerrn(C3o)ntributed Perl DocumMeanttha:t:iNounmSeq::PlanePathTurn(3)
2
3
4

NAME

6       Math::NumSeq::PlanePathTurn -- turn sequence from PlanePath module
7

SYNOPSIS

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

DESCRIPTION

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" in the path, the turn follows that particular arm
38       so locations of N = i-arms to i to i+arms.  i values start
39       "n_start()+arms_count()" so that i-arms is "n_start()" which is the
40       first N on the path.  A single arm path beginning N=0 has its first
41       turn at i=1.
42
43       For "Straight", "LSR", "SLR", and "SRL", straight means either straight
44       ahead or 180-degree reversal, ie. the direction N to N+1 is along the
45       same line as N-1 to N was.
46
47       "Left" means to the left side of the N-1 to N line, so not straight or
48       right.  Similarly "Right" means to the right side of the N-1 to N line,
49       so not straight or left.
50

FUNCTIONS

52       See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence
53       classes.
54
55       "$seq = Math::NumSeq::PlanePathTurn->new (key=>value,...)"
56           Create and return a new sequence object.  The options are
57
58               planepath          string, name of a PlanePath module
59               planepath_object   PlanePath object
60               turn_type          string, as described above
61
62           "planepath" can be either the module part such as "SquareSpiral" or
63           a full class name "Math::PlanePath::SquareSpiral".
64
65       "$value = $seq->ith($i)"
66           Return the turn at N=$i in the PlanePath.
67
68       "$bool = $seq->pred($value)"
69           Return true if $value occurs as a turn.  Often this is merely the
70           possible turn values 1,0,-1, etc, but some spiral paths for example
71           only go left or straight in which case only 1 and 0 occur and
72           "pred()" reflects that.
73
74       "$i = $seq->i_start()"
75           Return the first index $i in the sequence.  This is the position
76           "rewind()" returns to.
77
78           This is "$path->n_start() - $path->arms_count()" from the PlanePath
79           object.
80

FORMULAS

82   Turn Left or Right
83       A turn left or right is identified by considering the dX,dY at N-1 and
84       at N.
85
86           N+1      *
87                    |
88                    |
89                    |   dx2,dy2
90                    |
91           N        *
92                   /
93                  /
94                 /  dx1,dy1
95           N-1  *
96
97       With the two vectors dx1,dy1 and dx2,dy2 at a common origin, if the
98       dx2,dy2 is "above" the dx1,dy1 line then it's a turn to the left, or
99       below is a turn to the right
100
101           dx2,dy2
102              *
103              ^   * dx1,dy1
104              |  ^
105              | /
106              |/
107              o
108
109       At dx2, the Y value of the dx1,dy1 vector is
110
111           cmpY = dx2 * dy1/dx1           if dx1 != 0
112
113           left if dy2 > cmpY
114                   dy2 > dx2 * dy1/dx1
115              so   dy2 * dx1 > dx2 * dy1
116
117       This cross-product comparison dy2*dx1 > dx2*dy1 works when dx1=0 too,
118       ie. when dx1,dy1 is vertical
119
120           left if dy2 * 0 > dx2 * dy1
121                         0 > dx2*dy1
122           good, left if dx2 and dy1 opposite signs
123
124       So
125
126           dy2*dx1 > dx2*dy1      left
127           dy2*dx1 < dx2*dy1      right
128           dy2*dx1 = dx2*dy1      straight, including 180 degree reverse
129

SEE ALSO

131       Math::NumSeq, Math::NumSeq::PlanePathCoord,
132       Math::NumSeq::PlanePathDelta, Math::NumSeq::PlanePathN
133
134       Math::NumberCruncher has a "Clockwise()" turn calculator
135

HOME PAGE

137       <http://user42.tuxfamily.org/math-planepath/index.html>
138

LICENSE

140       Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020,
141       2021 Kevin Ryde
142
143       This file is part of Math-PlanePath.
144
145       Math-PlanePath is free software; you can redistribute it and/or modify
146       it under the terms of the GNU General Public License as published by
147       the Free Software Foundation; either version 3, or (at your option) any
148       later version.
149
150       Math-PlanePath is distributed in the hope that it will be useful, but
151       WITHOUT ANY WARRANTY; without even the implied warranty of
152       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
153       General Public License for more details.
154
155       You should have received a copy of the GNU General Public License along
156       with Math-PlanePath.  If not, see <http://www.gnu.org/licenses/>.
157
158
159
160perl v5.36.0                      2022-07-22    Math::NumSeq::PlanePathTurn(3)
Impressum