PLplot  5.10.0
plaffine.c
Go to the documentation of this file.
00001 // Affine manipulation routines for PLplot.
00002 //
00003 // Copyright (C) 2009-2014 Alan W. Irwin
00004 //
00005 // This file is part of PLplot.
00006 //
00007 // PLplot is free software; you can redistribute it and/or modify
00008 // it under the terms of the GNU Library General Public License as published
00009 // by the Free Software Foundation; either version 2 of the License, or
00010 // (at your option) any later version.
00011 //
00012 // PLplot is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU Library General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU Library General Public License
00018 // along with PLplot; if not, write to the Free Software
00019 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020 //
00021 //
00022 
00023 #include "plplotP.h"
00024 
00049 //
00050 
00055 void
00056 plP_affine_identity( PLFLT *affine_vector )
00057 {
00058     affine_vector[0] = 1.;
00059     affine_vector[1] = 0.;
00060     affine_vector[2] = 0.;
00061     affine_vector[3] = 1.;
00062     affine_vector[4] = 0.;
00063     affine_vector[5] = 0.;
00064 }
00065 
00072 void
00073 plP_affine_translate( PLFLT *affine_vector, PLFLT xtranslate, PLFLT ytranslate )
00074 {
00075     affine_vector[0] = 1.;
00076     affine_vector[1] = 0.;
00077     affine_vector[2] = 0.;
00078     affine_vector[3] = 1.;
00079     // If the new coordinate system axis is shifted by xtranslate and ytranslate
00080     // relative to the old, then the actual new coordinates are shifted in
00081     // the opposite direction.
00082     affine_vector[4] = -xtranslate;
00083     affine_vector[5] = -ytranslate;
00084 }
00085 
00092 void
00093 plP_affine_scale( PLFLT *affine_vector, PLFLT xscale, PLFLT yscale )
00094 {
00095     // If the new coordinate system axes are scaled by xscale and yscale
00096     // relative to the old, then the actual new coordinates are scaled
00097     // by the inverses.
00098     if ( xscale == 0. )
00099     {
00100         plwarn( "plP_affine_scale: attempt to scale X coordinates by zero." );
00101         xscale = 1.;
00102     }
00103     if ( yscale == 0. )
00104     {
00105         plwarn( "plP_affine_scale: attempt to scale Y coordinates by zero." );
00106         yscale = 1.;
00107     }
00108     affine_vector[0] = 1. / xscale;
00109     affine_vector[1] = 0.;
00110     affine_vector[2] = 0.;
00111     affine_vector[3] = 1. / yscale;
00112     affine_vector[4] = 0.;
00113     affine_vector[5] = 0.;
00114 }
00115 
00122 void
00123 plP_affine_rotate( PLFLT *affine_vector, PLFLT angle )
00124 {
00125     PLFLT cosangle = cos( PI * angle / 180. );
00126     PLFLT sinangle = sin( PI * angle / 180. );
00127     affine_vector[0] = cosangle;
00128     affine_vector[1] = -sinangle;
00129     affine_vector[2] = sinangle;
00130     affine_vector[3] = cosangle;
00131     affine_vector[4] = 0.;
00132     affine_vector[5] = 0.;
00133 }
00134 
00141 
00142 void
00143 plP_affine_xskew( PLFLT *affine_vector, PLFLT angle )
00144 {
00145     PLFLT tanangle = tan( PI * angle / 180. );
00146     affine_vector[0] = 1.;
00147     affine_vector[1] = 0.;
00148     affine_vector[2] = -tanangle;
00149     affine_vector[3] = 1.;
00150     affine_vector[4] = 0.;
00151     affine_vector[5] = 0.;
00152 }
00153 
00160 
00161 void
00162 plP_affine_yskew( PLFLT *affine_vector, PLFLT angle )
00163 {
00164     PLFLT tanangle = tan( PI * angle / 180. );
00165     affine_vector[0] = 1.;
00166     affine_vector[1] = -tanangle;
00167     affine_vector[2] = 0.;
00168     affine_vector[3] = 1.;
00169     affine_vector[4] = 0.;
00170     affine_vector[5] = 0.;
00171 }
00172 
00182 
00183 void
00184 plP_affine_multiply(
00185     PLFLT *affine_vectorA,
00186     const PLFLT *affine_vectorB,
00187     const PLFLT *affine_vectorC )
00188 {
00189     int   i;
00190     PLFLT result[NAFFINE];
00191     // Multiply two affine matrices stored in affine vector form.
00192     result[0] = affine_vectorB[0] * affine_vectorC[0] +
00193                 affine_vectorB[2] * affine_vectorC[1];
00194     result[2] = affine_vectorB[0] * affine_vectorC[2] +
00195                 affine_vectorB[2] * affine_vectorC[3];
00196     result[4] = affine_vectorB[0] * affine_vectorC[4] +
00197                 affine_vectorB[2] * affine_vectorC[5] +
00198                 affine_vectorB[4];
00199 
00200     result[1] = affine_vectorB[1] * affine_vectorC[0] +
00201                 affine_vectorB[3] * affine_vectorC[1];
00202     result[3] = affine_vectorB[1] * affine_vectorC[2] +
00203                 affine_vectorB[3] * affine_vectorC[3];
00204     result[5] = affine_vectorB[1] * affine_vectorC[4] +
00205                 affine_vectorB[3] * affine_vectorC[5] +
00206                 affine_vectorB[5];
00207 
00208     for ( i = 0; i < NAFFINE; i++ )
00209         affine_vectorA[i] = result[i];
00210 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines