PLplot  5.15.0
plcvt.c
Go to the documentation of this file.
1 // Coordinate transformation routines.
2 //
3 // Copyright (C) 2004-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 #include "plplotP.h"
23 
24 //--------------------------------------------------------------------------
25 // Transformations returning physical coordinates.
26 //--------------------------------------------------------------------------
27 
28 // device coords to physical coords (x)
29 
30 PLINT
32 {
33  return ( ROUND( plsc->phyxmi + plsc->phyxlen * x ) );
34 }
35 
36 // device coords to physical coords (y)
37 
38 PLINT
40 {
41  return ( ROUND( plsc->phyymi + plsc->phyylen * y ) );
42 }
43 
44 // millimeters from bottom left-hand corner to physical coords (x)
45 
46 PLINT
48 {
49  return ( ROUND( plsc->phyxmi + plsc->xpmm * x ) );
50 }
51 
52 // millimeters from bottom left-hand corner to physical coords (y)
53 
54 PLINT
56 {
57  return ( ROUND( plsc->phyymi + plsc->ypmm * y ) );
58 }
59 
60 // world coords to physical coords (x)
61 
62 PLINT
64 {
65  if ( !isfinite( x ) )
66  return PLINT_MIN;
67  return ( ROUND( plsc->wpxoff + plsc->wpxscl * x ) );
68 }
69 
70 // world coords to physical coords (y)
71 
72 PLINT
74 {
75  if ( !isfinite( y ) )
76  return PLINT_MIN;
77  return ( ROUND( plsc->wpyoff + plsc->wpyscl * y ) );
78 }
79 
80 //--------------------------------------------------------------------------
81 // Transformations returning device coordinates.
82 //--------------------------------------------------------------------------
83 
84 // physical coords to device coords (x)
85 
86 PLFLT
88 {
89  return (PLFLT) ( ( x - plsc->phyxmi ) / (double) plsc->phyxlen );
90 }
91 
92 // physical coords to device coords (y)
93 
94 PLFLT
96 {
97  return (PLFLT) ( ( y - plsc->phyymi ) / (double) plsc->phyylen );
98 }
99 
100 // millimeters from bottom left corner to device coords (x)
101 
102 PLFLT
104 {
105  return ( (PLFLT) ( x * plsc->xpmm / ABS( plsc->phyxma - plsc->phyxmi ) ) );
106 }
107 
108 // millimeters from bottom left corner to device coords (y)
109 
110 PLFLT
112 {
113  return ( (PLFLT) ( y * plsc->ypmm / ABS( plsc->phyyma - plsc->phyymi ) ) );
114 }
115 
116 // world coords into device coords (x)
117 
118 PLFLT
120 {
121  return ( (PLFLT) ( plsc->wdxoff + plsc->wdxscl * x ) );
122 }
123 
124 // world coords into device coords (y)
125 
126 PLFLT
128 {
129  return ( (PLFLT) ( plsc->wdyoff + plsc->wdyscl * y ) );
130 }
131 
132 // subpage coords to device coords (x)
133 
134 PLFLT
136 {
137  return ( (PLFLT) ( plsc->spdxmi + ( plsc->spdxma - plsc->spdxmi ) * x ) );
138 }
139 
140 // subpage coords to device coords (y)
141 
142 PLFLT
144 {
145  return ( (PLFLT) ( plsc->spdymi + ( plsc->spdyma - plsc->spdymi ) * y ) );
146 }
147 
148 //--------------------------------------------------------------------------
149 // Transformations returning millimeters.
150 //--------------------------------------------------------------------------
151 
152 // device coords to millimeters from bottom left-hand corner (x)
153 
154 PLFLT
156 {
157  return ( (PLFLT) ( x * ABS( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm ) );
158 }
159 
160 // device coords to millimeters from bottom left-hand corner (y)
161 
162 PLFLT
164 {
165  return ( (PLFLT) ( y * ABS( plsc->phyyma - plsc->phyymi ) / plsc->ypmm ) );
166 }
167 
168 // world coords into millimeters (x)
169 
170 PLFLT
172 {
173  return ( (PLFLT) ( plsc->wmxoff + plsc->wmxscl * x ) );
174 }
175 
176 // world coords into millimeters (y)
177 
178 PLFLT
180 {
181  return ( (PLFLT) ( plsc->wmyoff + plsc->wmyscl * y ) );
182 }
183 
184 //--------------------------------------------------------------------------
185 // Transformations returning subpage coordinates.
186 //--------------------------------------------------------------------------
187 
188 // device coords to subpage coords (x)
189 
190 PLFLT
192 {
193  return ( (PLFLT) ( ( x - plsc->spdxmi ) / ( plsc->spdxma - plsc->spdxmi ) ) );
194 }
195 
196 // device coords to subpage coords (y)
197 
198 PLFLT
200 {
201  return ( (PLFLT) ( ( y - plsc->spdymi ) / ( plsc->spdyma - plsc->spdymi ) ) );
202 }
203 
204 //--------------------------------------------------------------------------
205 // 3-d plot transformations.
206 //--------------------------------------------------------------------------
207 
208 // 3-d coords to 2-d projection (x)
209 // See c_plw3d for a mathematical explanation of the transformation.
210 
211 PLFLT
213 {
214  return ( (PLFLT) ( ( x - plsc->basecx ) * plsc->cxx +
215  ( y - plsc->basecy ) * plsc->cxy ) );
216 }
217 
218 // 3-d coords to 2-d projection (y)
219 // See c_plw3d for a mathematical explanation of the transformation.
220 
221 PLFLT
223 {
224  return ( (PLFLT) ( ( x - plsc->basecx ) * plsc->cyx +
225  ( y - plsc->basecy ) * plsc->cyy +
226  ( z - plsc->ranmi ) * plsc->cyz ) );
227 }
228 
229 // 3-d coords to 2-d projection (z), if that makes any sense...
230 // See c_plw3d for a mathematical explanation of the transformation.
231 
232 PLFLT
234 {
235  return ( (PLFLT) ( ( x - plsc->basecx ) * plsc->czx +
236  ( y - plsc->basecy ) * plsc->czy +
237  ( z - plsc->ranmi ) * plsc->czz ) );
238 }
PLFLT plP_w3wcz(PLFLT x, PLFLT y, PLFLT z)
Definition: plcvt.c:233
PLFLT plP_pcdcy(PLINT y)
Definition: plcvt.c:95
PLINT plP_wcpcx(PLFLT x)
Definition: plcvt.c:63
#define ROUND(a)
Definition: plplotP.h:202
PLINT plP_dcpcx(PLFLT x)
Definition: plcvt.c:31
#define PLINT_MIN
Definition: plplot.h:191
PLFLT plP_wcmmy(PLFLT y)
Definition: plcvt.c:179
PLINT plP_mmpcy(PLFLT y)
Definition: plcvt.c:55
int PLINT
Definition: plplot.h:181
PLFLT plP_scdcy(PLFLT y)
Definition: plcvt.c:143
PLFLT plP_dcmmy(PLFLT y)
Definition: plcvt.c:163
PLFLT plP_dcscy(PLFLT y)
Definition: plcvt.c:199
PLFLT plP_w3wcy(PLFLT x, PLFLT y, PLFLT z)
Definition: plcvt.c:222
PLFLT plP_pcdcx(PLINT x)
Definition: plcvt.c:87
#define isfinite(x)
Definition: plplotP.h:268
PLFLT plP_mmdcy(PLFLT y)
Definition: plcvt.c:111
PLFLT plP_scdcx(PLFLT x)
Definition: plcvt.c:135
PLFLT plP_mmdcx(PLFLT x)
Definition: plcvt.c:103
#define PL_UNUSED(x)
Definition: plplot.h:138
float PLFLT
Definition: plplot.h:163
PLFLT plP_w3wcx(PLFLT x, PLFLT y, PLFLT PL_UNUSED(z))
Definition: plcvt.c:212
PLINT plP_dcpcy(PLFLT y)
Definition: plcvt.c:39
PLFLT plP_dcscx(PLFLT x)
Definition: plcvt.c:191
PLINT plP_mmpcx(PLFLT x)
Definition: plcvt.c:47
PLFLT plP_wcdcx(PLFLT x)
Definition: plcvt.c:119
PLINT plP_wcpcy(PLFLT y)
Definition: plcvt.c:73
PLFLT plP_wcmmx(PLFLT x)
Definition: plcvt.c:171
#define ABS(a)
Definition: plplotP.h:199
PLFLT plP_wcdcy(PLFLT y)
Definition: plcvt.c:127
PLFLT plP_dcmmx(PLFLT x)
Definition: plcvt.c:155