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           "LSR"       1=left  0=straight -1=right
24           "SLR"       0=straight 1=left  2=right
25           "SRL"       0=straight 1=right 2=left
26
27       In each case the value at sequence index i is the turn at N=i,
28
29                   i+1
30                    ^
31                    |
32                    |
33           i-1 ---> i     turn at i
34                          first turn at i = n_start + 1
35
36       For multiple "arms" the turn follows that particular arm so it's
37       i-arms, i, i+arms.  i values start "n_start()+arms_count()" so that
38       i-arms is "n_start()", the first N on the path.  A single arm path
39       beginning N=0 has its first turn at i=1.
40
41       For "Straight", "LSR", "SLR" and "SRL", straight means either straight
42       ahead or 180-degree reversal, ie. the direction N to N+1 is along the
43       same line as N-1 to N was.
44
45       "Left" means to the left side of the N-1 to N line, so not straight or
46       right.  Similarly "Right" means to the right side of the N-1 to N line,
47       so not straight or left.
48

FUNCTIONS

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

FORMULAS

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

SEE ALSO

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

HOME PAGE

135       <http://user42.tuxfamily.org/math-planepath/index.html>
136

LICENSE

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