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