PLplot: plcvt.c Source File

PLplot 5.10.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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