PLplot 5.9.6
|
00001 /* $Id$ 00002 * 00003 * Coordinate transformation routines. 00004 * 00005 * Copyright (C) 2004 Alan W. Irwin 00006 * 00007 * This file is part of PLplot. 00008 * 00009 * PLplot is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Library Public License as published 00011 * by the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * PLplot is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU Library General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Library General Public License 00020 * along with PLplot; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 */ 00023 00024 #include "plplotP.h" 00025 00026 /*--------------------------------------------------------------------------*\ 00027 * Transformations returning physical coordinates. 00028 \*--------------------------------------------------------------------------*/ 00029 00030 /* device coords to physical coords (x) */ 00031 00032 PLINT 00033 plP_dcpcx( PLFLT x ) 00034 { 00035 return ( ROUND( plsc->phyxmi + plsc->phyxlen * x ) ); 00036 } 00037 00038 /* device coords to physical coords (y) */ 00039 00040 PLINT 00041 plP_dcpcy( PLFLT y ) 00042 { 00043 return ( ROUND( plsc->phyymi + plsc->phyylen * y ) ); 00044 } 00045 00046 /* millimeters from bottom left-hand corner to physical coords (x) */ 00047 00048 PLINT 00049 plP_mmpcx( PLFLT x ) 00050 { 00051 return ( ROUND( plsc->phyxmi + plsc->xpmm * x ) ); 00052 } 00053 00054 /* millimeters from bottom left-hand corner to physical coords (y) */ 00055 00056 PLINT 00057 plP_mmpcy( PLFLT y ) 00058 { 00059 return ( ROUND( plsc->phyymi + plsc->ypmm * y ) ); 00060 } 00061 00062 /* world coords to physical coords (x) */ 00063 00064 PLINT 00065 plP_wcpcx( PLFLT x ) 00066 { 00067 if ( !finite( x ) ) 00068 return PLINT_MIN; 00069 return ( ROUND( plsc->wpxoff + plsc->wpxscl * x ) ); 00070 } 00071 00072 /* world coords to physical coords (y) */ 00073 00074 PLINT 00075 plP_wcpcy( PLFLT y ) 00076 { 00077 if ( !finite( y ) ) 00078 return PLINT_MIN; 00079 return ( ROUND( plsc->wpyoff + plsc->wpyscl * y ) ); 00080 } 00081 00082 /*--------------------------------------------------------------------------*\ 00083 * Transformations returning device coordinates. 00084 \*--------------------------------------------------------------------------*/ 00085 00086 /* physical coords to device coords (x) */ 00087 00088 PLFLT 00089 plP_pcdcx( PLINT x ) 00090 { 00091 return (PLFLT) ( ( x - plsc->phyxmi ) / (double) plsc->phyxlen ); 00092 } 00093 00094 /* physical coords to device coords (y) */ 00095 00096 PLFLT 00097 plP_pcdcy( PLINT y ) 00098 { 00099 return (PLFLT) ( ( y - plsc->phyymi ) / (double) plsc->phyylen ); 00100 } 00101 00102 /* millimeters from bottom left corner to device coords (x) */ 00103 00104 PLFLT 00105 plP_mmdcx( PLFLT x ) 00106 { 00107 return ( (PLFLT) ( x * plsc->xpmm / ABS( plsc->phyxma - plsc->phyxmi ) ) ); 00108 } 00109 00110 /* millimeters from bottom left corner to device coords (y) */ 00111 00112 PLFLT 00113 plP_mmdcy( PLFLT y ) 00114 { 00115 return ( (PLFLT) ( y * plsc->ypmm / ABS( plsc->phyyma - plsc->phyymi ) ) ); 00116 } 00117 00118 /* world coords into device coords (x) */ 00119 00120 PLFLT 00121 plP_wcdcx( PLFLT x ) 00122 { 00123 return ( (PLFLT) ( plsc->wdxoff + plsc->wdxscl * x ) ); 00124 } 00125 00126 /* world coords into device coords (y) */ 00127 00128 PLFLT 00129 plP_wcdcy( PLFLT y ) 00130 { 00131 return ( (PLFLT) ( plsc->wdyoff + plsc->wdyscl * y ) ); 00132 } 00133 00134 /* subpage coords to device coords (x) */ 00135 00136 PLFLT 00137 plP_scdcx( PLFLT x ) 00138 { 00139 return ( (PLFLT) ( plsc->spdxmi + ( plsc->spdxma - plsc->spdxmi ) * x ) ); 00140 } 00141 00142 /* subpage coords to device coords (y) */ 00143 00144 PLFLT 00145 plP_scdcy( PLFLT y ) 00146 { 00147 return ( (PLFLT) ( plsc->spdymi + ( plsc->spdyma - plsc->spdymi ) * y ) ); 00148 } 00149 00150 /*--------------------------------------------------------------------------*\ 00151 * Transformations returning millimeters. 00152 \*--------------------------------------------------------------------------*/ 00153 00154 /* device coords to millimeters from bottom left-hand corner (x) */ 00155 00156 PLFLT 00157 plP_dcmmx( PLFLT x ) 00158 { 00159 return ( (PLFLT) ( x * ABS( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm ) ); 00160 } 00161 00162 /* device coords to millimeters from bottom left-hand corner (y) */ 00163 00164 PLFLT 00165 plP_dcmmy( PLFLT y ) 00166 { 00167 return ( (PLFLT) ( y * ABS( plsc->phyyma - plsc->phyymi ) / plsc->ypmm ) ); 00168 } 00169 00170 /* world coords into millimeters (x) */ 00171 00172 PLFLT 00173 plP_wcmmx( PLFLT x ) 00174 { 00175 return ( (PLFLT) ( plsc->wmxoff + plsc->wmxscl * x ) ); 00176 } 00177 00178 /* world coords into millimeters (y) */ 00179 00180 PLFLT 00181 plP_wcmmy( PLFLT y ) 00182 { 00183 return ( (PLFLT) ( plsc->wmyoff + plsc->wmyscl * y ) ); 00184 } 00185 00186 /*--------------------------------------------------------------------------*\ 00187 * Transformations returning subpage coordinates. 00188 \*--------------------------------------------------------------------------*/ 00189 00190 /* device coords to subpage coords (x) */ 00191 00192 PLFLT 00193 plP_dcscx( PLFLT x ) 00194 { 00195 return ( (PLFLT) ( ( x - plsc->spdxmi ) / ( plsc->spdxma - plsc->spdxmi ) ) ); 00196 } 00197 00198 /* device coords to subpage coords (y) */ 00199 00200 PLFLT 00201 plP_dcscy( PLFLT y ) 00202 { 00203 return ( (PLFLT) ( ( y - plsc->spdymi ) / ( plsc->spdyma - plsc->spdymi ) ) ); 00204 } 00205 00206 /*--------------------------------------------------------------------------*\ 00207 * 3-d plot transformations. 00208 \*--------------------------------------------------------------------------*/ 00209 00210 /* 3-d coords to 2-d projection (x) */ 00211 /* See c_plw3d for a mathematical explanation of the transformation. */ 00212 00213 PLFLT 00214 plP_w3wcx( PLFLT x, PLFLT y, PLFLT z ) 00215 { 00216 return ( (PLFLT) ( ( x - plsc->basecx ) * plsc->cxx + 00217 ( y - plsc->basecy ) * plsc->cxy ) ); 00218 } 00219 00220 /* 3-d coords to 2-d projection (y) */ 00221 /* See c_plw3d for a mathematical explanation of the transformation. */ 00222 00223 PLFLT 00224 plP_w3wcy( PLFLT x, PLFLT y, PLFLT z ) 00225 { 00226 return ( (PLFLT) ( ( x - plsc->basecx ) * plsc->cyx + 00227 ( y - plsc->basecy ) * plsc->cyy + 00228 ( z - plsc->ranmi ) * plsc->cyz ) ); 00229 } 00230 00231 /* 3-d coords to 2-d projection (z), if that makes any sense... */ 00232 /* See c_plw3d for a mathematical explanation of the transformation. */ 00233 00234 PLFLT 00235 plP_w3wcz( PLFLT x, PLFLT y, PLFLT z ) 00236 { 00237 return ( (PLFLT) ( ( x - plsc->basecx ) * plsc->czx + 00238 ( y - plsc->basecy ) * plsc->czy + 00239 ( z - plsc->ranmi ) * plsc->czz ) ); 00240 }