PLplot  5.10.0
 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
34 {
35  return ( ROUND( plsc->phyxmi + plsc->phyxlen * x ) );
36 }
37 
38 // device coords to physical coords (y)
39 
40 PLINT
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
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
58 {
59  return ( ROUND( plsc->phyymi + plsc->ypmm * y ) );
60 }
61 
62 // world coords to physical coords (x)
63 
64 PLINT
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
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
90 {
91  return (PLFLT) ( ( x - plsc->phyxmi ) / (double) plsc->phyxlen );
92 }
93 
94 // physical coords to device coords (y)
95 
96 PLFLT
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
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
114 {
115  return ( (PLFLT) ( y * plsc->ypmm / ABS( plsc->phyyma - plsc->phyymi ) ) );
116 }
117 
118 // world coords into device coords (x)
119 
120 PLFLT
122 {
123  return ( (PLFLT) ( plsc->wdxoff + plsc->wdxscl * x ) );
124 }
125 
126 // world coords into device coords (y)
127 
128 PLFLT
130 {
131  return ( (PLFLT) ( plsc->wdyoff + plsc->wdyscl * y ) );
132 }
133 
134 // subpage coords to device coords (x)
135 
136 PLFLT
138 {
139  return ( (PLFLT) ( plsc->spdxmi + ( plsc->spdxma - plsc->spdxmi ) * x ) );
140 }
141 
142 // subpage coords to device coords (y)
143 
144 PLFLT
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
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
166 {
167  return ( (PLFLT) ( y * ABS( plsc->phyyma - plsc->phyymi ) / plsc->ypmm ) );
168 }
169 
170 // world coords into millimeters (x)
171 
172 PLFLT
174 {
175  return ( (PLFLT) ( plsc->wmxoff + plsc->wmxscl * x ) );
176 }
177 
178 // world coords into millimeters (y)
179 
180 PLFLT
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
194 {
195  return ( (PLFLT) ( ( x - plsc->spdxmi ) / ( plsc->spdxma - plsc->spdxmi ) ) );
196 }
197 
198 // device coords to subpage coords (y)
199 
200 PLFLT
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
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
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
236 {
237  return ( (PLFLT) ( ( x - plsc->basecx ) * plsc->czx +
238  ( y - plsc->basecy ) * plsc->czy +
239  ( z - plsc->ranmi ) * plsc->czz ) );
240 }