PLplot: plcvt.c Source File

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
31 plP_dcpcx( PLFLT x )
32 {
33 return ( ROUND( plsc->phyxmi + plsc->phyxlen * x ) );
34 }
35
36 // device coords to physical coords (y)
37
38 PLINT
39 plP_dcpcy( PLFLT y )
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
47 plP_mmpcx( PLFLT x )
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
55 plP_mmpcy( PLFLT y )
56 {
57 return ( ROUND( plsc->phyymi + plsc->ypmm * y ) );
58 }
59
60 // world coords to physical coords (x)
61
62 PLINT
63 plP_wcpcx( PLFLT x )
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
73 plP_wcpcy( PLFLT y )
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
87 plP_pcdcx( PLINT x )
88 {
89 return (PLFLT) ( ( x - plsc->phyxmi ) / (double) plsc->phyxlen );
90 }
91
92 // physical coords to device coords (y)
93
94 PLFLT
95 plP_pcdcy( PLINT y )
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
103 plP_mmdcx( PLFLT x )
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
111 plP_mmdcy( PLFLT y )
112 {
113 return ( (PLFLT) ( y * plsc->ypmm / ABS( plsc->phyyma - plsc->phyymi ) ) );
114 }
115
116 // world coords into device coords (x)
117
118 PLFLT
119 plP_wcdcx( PLFLT x )
120 {
121 return ( (PLFLT) ( plsc->wdxoff + plsc->wdxscl * x ) );
122 }
123
124 // world coords into device coords (y)
125
126 PLFLT
127 plP_wcdcy( PLFLT y )
128 {
129 return ( (PLFLT) ( plsc->wdyoff + plsc->wdyscl * y ) );
130 }
131
132 // subpage coords to device coords (x)
133
134 PLFLT
135 plP_scdcx( PLFLT x )
136 {
137 return ( (PLFLT) ( plsc->spdxmi + ( plsc->spdxma - plsc->spdxmi ) * x ) );
138 }
139
140 // subpage coords to device coords (y)
141
142 PLFLT
143 plP_scdcy( PLFLT y )
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
155 plP_dcmmx( PLFLT x )
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
163 plP_dcmmy( PLFLT y )
164 {
165 return ( (PLFLT) ( y * ABS( plsc->phyyma - plsc->phyymi ) / plsc->ypmm ) );
166 }
167
168 // world coords into millimeters (x)
169
170 PLFLT
171 plP_wcmmx( PLFLT x )
172 {
173 return ( (PLFLT) ( plsc->wmxoff + plsc->wmxscl * x ) );
174 }
175
176 // world coords into millimeters (y)
177
178 PLFLT
179 plP_wcmmy( PLFLT y )
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
191 plP_dcscx( PLFLT x )
192 {
193 return ( (PLFLT) ( ( x - plsc->spdxmi ) / ( plsc->spdxma - plsc->spdxmi ) ) );
194 }
195
196 // device coords to subpage coords (y)
197
198 PLFLT
199 plP_dcscy( PLFLT y )
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
212 plP_w3wcx( PLFLT x, PLFLT y, PLFLT PL_UNUSED( z ) )
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
222 plP_w3wcy( PLFLT x, PLFLT y, PLFLT z )
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
233 plP_w3wcz( PLFLT x, PLFLT y, PLFLT z )
234 {
235 return ( (PLFLT) ( ( x - plsc->basecx ) * plsc->czx +
236 ( y - plsc->basecy ) * plsc->czy +
237 ( z - plsc->ranmi ) * plsc->czz ) );
238 }
plplotP.h
plP_w3wcz
PLFLT plP_w3wcz(PLFLT x, PLFLT y, PLFLT z)
Definition: plcvt.c:233
plP_pcdcy
PLFLT plP_pcdcy(PLINT y)
Definition: plcvt.c:95
plP_wcpcx
PLINT plP_wcpcx(PLFLT x)
Definition: plcvt.c:63
ROUND
#define ROUND(a)
Definition: plplotP.h:202
plP_dcpcx
PLINT plP_dcpcx(PLFLT x)
Definition: plcvt.c:31
PLINT_MIN
#define PLINT_MIN
Definition: plplot.h:191
plP_wcmmy
PLFLT plP_wcmmy(PLFLT y)
Definition: plcvt.c:179
plP_mmpcy
PLINT plP_mmpcy(PLFLT y)
Definition: plcvt.c:55
PLINT
int PLINT
Definition: plplot.h:181
plP_scdcy
PLFLT plP_scdcy(PLFLT y)
Definition: plcvt.c:143
plP_dcmmy
PLFLT plP_dcmmy(PLFLT y)
Definition: plcvt.c:163
plP_dcscy
PLFLT plP_dcscy(PLFLT y)
Definition: plcvt.c:199
plP_w3wcy
PLFLT plP_w3wcy(PLFLT x, PLFLT y, PLFLT z)
Definition: plcvt.c:222
plP_pcdcx
PLFLT plP_pcdcx(PLINT x)
Definition: plcvt.c:87
isfinite
#define isfinite(x)
Definition: plplotP.h:268
plP_mmdcy
PLFLT plP_mmdcy(PLFLT y)
Definition: plcvt.c:111
plP_scdcx
PLFLT plP_scdcx(PLFLT x)
Definition: plcvt.c:135
plP_mmdcx
PLFLT plP_mmdcx(PLFLT x)
Definition: plcvt.c:103
PL_UNUSED
#define PL_UNUSED(x)
Definition: plplot.h:138
PLFLT
float PLFLT
Definition: plplot.h:163
plP_w3wcx
PLFLT plP_w3wcx(PLFLT x, PLFLT y, PLFLT PL_UNUSED(z))
Definition: plcvt.c:212
plP_dcpcy
PLINT plP_dcpcy(PLFLT y)
Definition: plcvt.c:39
plP_dcscx
PLFLT plP_dcscx(PLFLT x)
Definition: plcvt.c:191
plP_mmpcx
PLINT plP_mmpcx(PLFLT x)
Definition: plcvt.c:47
plP_wcdcx
PLFLT plP_wcdcx(PLFLT x)
Definition: plcvt.c:119
plP_wcpcy
PLINT plP_wcpcy(PLFLT y)
Definition: plcvt.c:73
plP_wcmmx
PLFLT plP_wcmmx(PLFLT x)
Definition: plcvt.c:171
ABS
#define ABS(a)
Definition: plplotP.h:199
plP_wcdcy
PLFLT plP_wcdcy(PLFLT y)
Definition: plcvt.c:127
plP_dcmmx
PLFLT plP_dcmmx(PLFLT x)
Definition: plcvt.c:155