PLplot
5.10.0
|
00001 // Coordinate transformation routines. 00002 // 00003 // Copyright (C) 2004-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 #include "plplotP.h" 00023 00024 //-------------------------------------------------------------------------- 00025 // Transformations returning physical coordinates. 00026 //-------------------------------------------------------------------------- 00027 00028 // device coords to physical coords (x) 00029 00030 PLINT 00031 plP_dcpcx( PLFLT x ) 00032 { 00033 return ( ROUND( plsc->phyxmi + plsc->phyxlen * x ) ); 00034 } 00035 00036 // device coords to physical coords (y) 00037 00038 PLINT 00039 plP_dcpcy( PLFLT y ) 00040 { 00041 return ( ROUND( plsc->phyymi + plsc->phyylen * y ) ); 00042 } 00043 00044 // millimeters from bottom left-hand corner to physical coords (x) 00045 00046 PLINT 00047 plP_mmpcx( PLFLT x ) 00048 { 00049 return ( ROUND( plsc->phyxmi + plsc->xpmm * x ) ); 00050 } 00051 00052 // millimeters from bottom left-hand corner to physical coords (y) 00053 00054 PLINT 00055 plP_mmpcy( PLFLT y ) 00056 { 00057 return ( ROUND( plsc->phyymi + plsc->ypmm * y ) ); 00058 } 00059 00060 // world coords to physical coords (x) 00061 00062 PLINT 00063 plP_wcpcx( PLFLT x ) 00064 { 00065 if ( !isfinite( x ) ) 00066 return PLINT_MIN; 00067 return ( ROUND( plsc->wpxoff + plsc->wpxscl * x ) ); 00068 } 00069 00070 // world coords to physical coords (y) 00071 00072 PLINT 00073 plP_wcpcy( PLFLT y ) 00074 { 00075 if ( !isfinite( y ) ) 00076 return PLINT_MIN; 00077 return ( ROUND( plsc->wpyoff + plsc->wpyscl * y ) ); 00078 } 00079 00080 //-------------------------------------------------------------------------- 00081 // Transformations returning device coordinates. 00082 //-------------------------------------------------------------------------- 00083 00084 // physical coords to device coords (x) 00085 00086 PLFLT 00087 plP_pcdcx( PLINT x ) 00088 { 00089 return (PLFLT) ( ( x - plsc->phyxmi ) / (double) plsc->phyxlen ); 00090 } 00091 00092 // physical coords to device coords (y) 00093 00094 PLFLT 00095 plP_pcdcy( PLINT y ) 00096 { 00097 return (PLFLT) ( ( y - plsc->phyymi ) / (double) plsc->phyylen ); 00098 } 00099 00100 // millimeters from bottom left corner to device coords (x) 00101 00102 PLFLT 00103 plP_mmdcx( PLFLT x ) 00104 { 00105 return ( (PLFLT) ( x * plsc->xpmm / ABS( plsc->phyxma - plsc->phyxmi ) ) ); 00106 } 00107 00108 // millimeters from bottom left corner to device coords (y) 00109 00110 PLFLT 00111 plP_mmdcy( PLFLT y ) 00112 { 00113 return ( (PLFLT) ( y * plsc->ypmm / ABS( plsc->phyyma - plsc->phyymi ) ) ); 00114 } 00115 00116 // world coords into device coords (x) 00117 00118 PLFLT 00119 plP_wcdcx( PLFLT x ) 00120 { 00121 return ( (PLFLT) ( plsc->wdxoff + plsc->wdxscl * x ) ); 00122 } 00123 00124 // world coords into device coords (y) 00125 00126 PLFLT 00127 plP_wcdcy( PLFLT y ) 00128 { 00129 return ( (PLFLT) ( plsc->wdyoff + plsc->wdyscl * y ) ); 00130 } 00131 00132 // subpage coords to device coords (x) 00133 00134 PLFLT 00135 plP_scdcx( PLFLT x ) 00136 { 00137 return ( (PLFLT) ( plsc->spdxmi + ( plsc->spdxma - plsc->spdxmi ) * x ) ); 00138 } 00139 00140 // subpage coords to device coords (y) 00141 00142 PLFLT 00143 plP_scdcy( PLFLT y ) 00144 { 00145 return ( (PLFLT) ( plsc->spdymi + ( plsc->spdyma - plsc->spdymi ) * y ) ); 00146 } 00147 00148 //-------------------------------------------------------------------------- 00149 // Transformations returning millimeters. 00150 //-------------------------------------------------------------------------- 00151 00152 // device coords to millimeters from bottom left-hand corner (x) 00153 00154 PLFLT 00155 plP_dcmmx( PLFLT x ) 00156 { 00157 return ( (PLFLT) ( x * ABS( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm ) ); 00158 } 00159 00160 // device coords to millimeters from bottom left-hand corner (y) 00161 00162 PLFLT 00163 plP_dcmmy( PLFLT y ) 00164 { 00165 return ( (PLFLT) ( y * ABS( plsc->phyyma - plsc->phyymi ) / plsc->ypmm ) ); 00166 } 00167 00168 // world coords into millimeters (x) 00169 00170 PLFLT 00171 plP_wcmmx( PLFLT x ) 00172 { 00173 return ( (PLFLT) ( plsc->wmxoff + plsc->wmxscl * x ) ); 00174 } 00175 00176 // world coords into millimeters (y) 00177 00178 PLFLT 00179 plP_wcmmy( PLFLT y ) 00180 { 00181 return ( (PLFLT) ( plsc->wmyoff + plsc->wmyscl * y ) ); 00182 } 00183 00184 //-------------------------------------------------------------------------- 00185 // Transformations returning subpage coordinates. 00186 //-------------------------------------------------------------------------- 00187 00188 // device coords to subpage coords (x) 00189 00190 PLFLT 00191 plP_dcscx( PLFLT x ) 00192 { 00193 return ( (PLFLT) ( ( x - plsc->spdxmi ) / ( plsc->spdxma - plsc->spdxmi ) ) ); 00194 } 00195 00196 // device coords to subpage coords (y) 00197 00198 PLFLT 00199 plP_dcscy( PLFLT y ) 00200 { 00201 return ( (PLFLT) ( ( y - plsc->spdymi ) / ( plsc->spdyma - plsc->spdymi ) ) ); 00202 } 00203 00204 //-------------------------------------------------------------------------- 00205 // 3-d plot transformations. 00206 //-------------------------------------------------------------------------- 00207 00208 // 3-d coords to 2-d projection (x) 00209 // See c_plw3d for a mathematical explanation of the transformation. 00210 00211 PLFLT 00212 plP_w3wcx( PLFLT x, PLFLT y, PLFLT PL_UNUSED( z ) ) 00213 { 00214 return ( (PLFLT) ( ( x - plsc->basecx ) * plsc->cxx + 00215 ( y - plsc->basecy ) * plsc->cxy ) ); 00216 } 00217 00218 // 3-d coords to 2-d projection (y) 00219 // See c_plw3d for a mathematical explanation of the transformation. 00220 00221 PLFLT 00222 plP_w3wcy( PLFLT x, PLFLT y, PLFLT z ) 00223 { 00224 return ( (PLFLT) ( ( x - plsc->basecx ) * plsc->cyx + 00225 ( y - plsc->basecy ) * plsc->cyy + 00226 ( z - plsc->ranmi ) * plsc->cyz ) ); 00227 } 00228 00229 // 3-d coords to 2-d projection (z), if that makes any sense... 00230 // See c_plw3d for a mathematical explanation of the transformation. 00231 00232 PLFLT 00233 plP_w3wcz( PLFLT x, PLFLT y, PLFLT z ) 00234 { 00235 return ( (PLFLT) ( ( x - plsc->basecx ) * plsc->czx + 00236 ( y - plsc->basecy ) * plsc->czy + 00237 ( z - plsc->ranmi ) * plsc->czz ) ); 00238 }