PLplot  5.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
plaffine.c
Go to the documentation of this file.
1 // $Id: plaffine.c 12024 2011-11-03 20:10:21Z hbabcock $
2 //
3 // Affine manipulation routines for PLplot.
4 //
5 // Copyright (C) 2009 Alan W. Irwin
6 //
7 // This file is part of PLplot.
8 //
9 // PLplot is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU Library General Public License as published
11 // by the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // PLplot is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU Library General Public License for more details.
18 //
19 // You should have received a copy of the GNU Library General Public License
20 // along with PLplot; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 //
24 
25 #include "plplotP.h"
26 
51 //
52 
57 void
58 plP_affine_identity( PLFLT *affine_vector )
59 {
60  affine_vector[0] = 1.;
61  affine_vector[1] = 0.;
62  affine_vector[2] = 0.;
63  affine_vector[3] = 1.;
64  affine_vector[4] = 0.;
65  affine_vector[5] = 0.;
66 }
67 
74 void
75 plP_affine_translate( PLFLT *affine_vector, PLFLT xtranslate, PLFLT ytranslate )
76 {
77  affine_vector[0] = 1.;
78  affine_vector[1] = 0.;
79  affine_vector[2] = 0.;
80  affine_vector[3] = 1.;
81  // If the new coordinate system axis is shifted by xtranslate and ytranslate
82  // relative to the old, then the actual new coordinates are shifted in
83  // the opposite direction.
84  affine_vector[4] = -xtranslate;
85  affine_vector[5] = -ytranslate;
86 }
87 
94 void
96 {
97  // If the new coordinate system axes are scaled by xscale and yscale
98  // relative to the old, then the actual new coordinates are scaled
99  // by the inverses.
100  if ( xscale == 0. )
101  {
102  plwarn( "plP_affine_scale: attempt to scale X coordinates by zero." );
103  xscale = 1.;
104  }
105  if ( yscale == 0. )
106  {
107  plwarn( "plP_affine_scale: attempt to scale Y coordinates by zero." );
108  yscale = 1.;
109  }
110  affine_vector[0] = 1. / xscale;
111  affine_vector[1] = 0.;
112  affine_vector[2] = 0.;
113  affine_vector[3] = 1. / yscale;
114  affine_vector[4] = 0.;
115  affine_vector[5] = 0.;
116 }
117 
124 void
125 plP_affine_rotate( PLFLT *affine_vector, PLFLT angle )
126 {
127  PLFLT cosangle = cos( PI * angle / 180. );
128  PLFLT sinangle = sin( PI * angle / 180. );
129  affine_vector[0] = cosangle;
130  affine_vector[1] = -sinangle;
131  affine_vector[2] = sinangle;
132  affine_vector[3] = cosangle;
133  affine_vector[4] = 0.;
134  affine_vector[5] = 0.;
135 }
136 
143 
144 void
145 plP_affine_xskew( PLFLT *affine_vector, PLFLT angle )
146 {
147  PLFLT tanangle = tan( PI * angle / 180. );
148  affine_vector[0] = 1.;
149  affine_vector[1] = 0.;
150  affine_vector[2] = -tanangle;
151  affine_vector[3] = 1.;
152  affine_vector[4] = 0.;
153  affine_vector[5] = 0.;
154 }
155 
162 
163 void
164 plP_affine_yskew( PLFLT *affine_vector, PLFLT angle )
165 {
166  PLFLT tanangle = tan( PI * angle / 180. );
167  affine_vector[0] = 1.;
168  affine_vector[1] = -tanangle;
169  affine_vector[2] = 0.;
170  affine_vector[3] = 1.;
171  affine_vector[4] = 0.;
172  affine_vector[5] = 0.;
173 }
174 
184 
185 void
187  PLFLT *affine_vectorA,
188  const PLFLT *affine_vectorB,
189  const PLFLT *affine_vectorC )
190 {
191  int i;
192  PLFLT result[NAFFINE];
193  // Multiply two affine matrices stored in affine vector form.
194  result[0] = affine_vectorB[0] * affine_vectorC[0] +
195  affine_vectorB[2] * affine_vectorC[1];
196  result[2] = affine_vectorB[0] * affine_vectorC[2] +
197  affine_vectorB[2] * affine_vectorC[3];
198  result[4] = affine_vectorB[0] * affine_vectorC[4] +
199  affine_vectorB[2] * affine_vectorC[5] +
200  affine_vectorB[4];
201 
202  result[1] = affine_vectorB[1] * affine_vectorC[0] +
203  affine_vectorB[3] * affine_vectorC[1];
204  result[3] = affine_vectorB[1] * affine_vectorC[2] +
205  affine_vectorB[3] * affine_vectorC[3];
206  result[5] = affine_vectorB[1] * affine_vectorC[4] +
207  affine_vectorB[3] * affine_vectorC[5] +
208  affine_vectorB[5];
209 
210  for ( i = 0; i < NAFFINE; i++ )
211  affine_vectorA[i] = result[i];
212 }