1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
/* $Id: plcvt.c,v 1.3 2007/05/08 09:09:37 rice Exp $
Coordinate transformation routines.
Copyright (C) 2004 Alan W. Irwin
This file is part of PLplot.
PLplot is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
PLplot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with PLplot; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "plplotP.h"
/*--------------------------------------------------------------------------*\
* Transformations returning physical coordinates.
\*--------------------------------------------------------------------------*/
/* device coords to physical coords (x) */
PLINT
plP_dcpcx(PLFLT x)
{
return (ROUND(plsc->phyxmi + plsc->phyxlen * x));
}
/* device coords to physical coords (y) */
PLINT
plP_dcpcy(PLFLT y)
{
return (ROUND(plsc->phyymi + plsc->phyylen * y));
}
/* millimeters from bottom left-hand corner to physical coords (x) */
PLINT
plP_mmpcx(PLFLT x)
{
return (ROUND(plsc->phyxmi + plsc->xpmm * x));
}
/* millimeters from bottom left-hand corner to physical coords (y) */
PLINT
plP_mmpcy(PLFLT y)
{
return (ROUND(plsc->phyymi + plsc->ypmm * y));
}
/* world coords to physical coords (x) */
PLINT
plP_wcpcx(PLFLT x)
{
return (ROUND(plsc->wpxoff + plsc->wpxscl * x));
}
/* world coords to physical coords (y) */
PLINT
plP_wcpcy(PLFLT y)
{
return (ROUND(plsc->wpyoff + plsc->wpyscl * y));
}
/*--------------------------------------------------------------------------*\
* Transformations returning device coordinates.
\*--------------------------------------------------------------------------*/
/* physical coords to device coords (x) */
PLFLT
plP_pcdcx(PLINT x)
{
return (PLFLT) ((x - plsc->phyxmi) / (double) plsc->phyxlen);
}
/* physical coords to device coords (y) */
PLFLT
plP_pcdcy(PLINT y)
{
return (PLFLT) ((y - plsc->phyymi) / (double) plsc->phyylen);
}
/* millimeters from bottom left corner to device coords (x) */
PLFLT
plP_mmdcx(PLFLT x)
{
return ((PLFLT) (x * plsc->xpmm / ABS(plsc->phyxma - plsc->phyxmi)));
}
/* millimeters from bottom left corner to device coords (y) */
PLFLT
plP_mmdcy(PLFLT y)
{
return ((PLFLT) (y * plsc->ypmm / ABS(plsc->phyyma - plsc->phyymi)));
}
/* world coords into device coords (x) */
PLFLT
plP_wcdcx(PLFLT x)
{
return ((PLFLT) (plsc->wdxoff + plsc->wdxscl * x));
}
/* world coords into device coords (y) */
PLFLT
plP_wcdcy(PLFLT y)
{
return ((PLFLT) (plsc->wdyoff + plsc->wdyscl * y));
}
/* subpage coords to device coords (x) */
PLFLT
plP_scdcx(PLFLT x)
{
return ((PLFLT) (plsc->spdxmi + (plsc->spdxma - plsc->spdxmi) * x));
}
/* subpage coords to device coords (y) */
PLFLT
plP_scdcy(PLFLT y)
{
return ((PLFLT) (plsc->spdymi + (plsc->spdyma - plsc->spdymi) * y));
}
/*--------------------------------------------------------------------------*\
* Transformations returning millimeters.
\*--------------------------------------------------------------------------*/
/* device coords to millimeters from bottom left-hand corner (x) */
PLFLT
plP_dcmmx(PLFLT x)
{
return ((PLFLT) (x * ABS(plsc->phyxma - plsc->phyxmi) / plsc->xpmm));
}
/* device coords to millimeters from bottom left-hand corner (y) */
PLFLT
plP_dcmmy(PLFLT y)
{
return ((PLFLT) (y * ABS(plsc->phyyma - plsc->phyymi) / plsc->ypmm));
}
/* world coords into millimeters (x) */
PLFLT
plP_wcmmx(PLFLT x)
{
return ((PLFLT) (plsc->wmxoff + plsc->wmxscl * x));
}
/* world coords into millimeters (y) */
PLFLT
plP_wcmmy(PLFLT y)
{
return ((PLFLT) (plsc->wmyoff + plsc->wmyscl * y));
}
/*--------------------------------------------------------------------------*\
* Transformations returning subpage coordinates.
\*--------------------------------------------------------------------------*/
/* device coords to subpage coords (x) */
PLFLT
plP_dcscx(PLFLT x)
{
return ((PLFLT) ((x - plsc->spdxmi) / (plsc->spdxma - plsc->spdxmi)));
}
/* device coords to subpage coords (y) */
PLFLT
plP_dcscy(PLFLT y)
{
return ((PLFLT) ((y - plsc->spdymi) / (plsc->spdyma - plsc->spdymi)));
}
/*--------------------------------------------------------------------------*\
* 3-d plot transformations.
\*--------------------------------------------------------------------------*/
/* 3-d coords to 2-d projection (x) */
/* See c_plw3d for a mathematical explanation of the transformation. */
PLFLT
plP_w3wcx(PLFLT x, PLFLT y, PLFLT z)
{
(void) z; /* pmr: make it used */
return ((PLFLT) ((x - plsc->basecx) * plsc->cxx +
(y - plsc->basecy) * plsc->cxy));
}
/* 3-d coords to 2-d projection (y) */
/* See c_plw3d for a mathematical explanation of the transformation. */
PLFLT
plP_w3wcy(PLFLT x, PLFLT y, PLFLT z)
{
return ((PLFLT) ((x - plsc->basecx) * plsc->cyx +
(y - plsc->basecy) * plsc->cyy +
(z - plsc->ranmi) * plsc->cyz));
}
|