Source Code Cross Referenced for CartesianTransformation.java in  » Chart » jcckit » jcckit » transformation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Chart » jcckit » jcckit.transformation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /*
02:         * Copyright 2003-2004, Franz-Josef Elmer, All rights reserved
03:         *
04:         * This library is free software; you can redistribute it and/or modify
05:         * it under the terms of the GNU Lesser General Public License as published by
06:         * the Free Software Foundation; either version 2.1 of the License, or
07:         * (at your option) any later version.
08:         *
09:         * This program is distributed in the hope that it will be useful,
10:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
11:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12:         * GNU Lesser General Public License for more details
13:         * (http://www.gnu.org/copyleft/lesser.html).
14:         *
15:         * You should have received a copy of the GNU Lesser General Public License
16:         * along with this library; if not, write to the Free Software
17:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18:         */
19:        package jcckit.transformation;
20:
21:        import jcckit.data.DataPoint;
22:        import jcckit.graphic.GraphPoint;
23:        import jcckit.util.Util;
24:
25:        /**
26:         *  Two-dimensional Cartesian transformation. The two independent
27:         *  transformations for the x-axis and the y-axis can be logarithmic
28:         *  from data coordinates to device-independent coordinates in order to
29:         *  realize diagrams with logarithmic scales.
30:         *
31:         *  @author Franz-Josef Elmer
32:         */
33:        public class CartesianTransformation implements  Transformation {
34:            private final boolean _xLogScale;
35:            private final double _xOffset;
36:            private final double _xScale;
37:            private final boolean _yLogScale;
38:            private final double _yOffset;
39:            private final double _yScale;
40:
41:            /**
42:             *  Creates an instance from the specified reference points.
43:             *  Note, that the reference points must differ in x and y coordinates
44:             *  otherwise a transformation would not be possible.
45:             *  @param xLogScale <tt>true</tt> if logarithmic x axis.
46:             *  @param yLogScale <tt>true</tt> if logarithmic y axis.
47:             *  @param dataPoint1 First reference point in data coordinates.
48:             *  @param graphPoint1 First reference point in device-independent 
49:             *         coordinates.
50:             *  @param dataPoint2 Second reference point in data coordinates.
51:             *  @param graphPoint2 Second reference point in device-independent
52:             *         coordinates.
53:             *  @throws IllegalArgumentException if transformation in at least
54:             *          one of both directions is not possible.
55:             */
56:            public CartesianTransformation(boolean xLogScale,
57:                    boolean yLogScale, DataPoint dataPoint1,
58:                    GraphPoint graphPoint1, DataPoint dataPoint2,
59:                    GraphPoint graphPoint2) {
60:                _xLogScale = xLogScale;
61:                double d1 = Util.log(dataPoint1.getX(), xLogScale);
62:                double dd = Util.log(dataPoint2.getX(), xLogScale) - d1;
63:                check(dd, "data", "x", d1);
64:                _xScale = (graphPoint2.getX() - graphPoint1.getX()) / dd;
65:                check(_xScale, "graphical", "x", graphPoint1.getX());
66:                _xOffset = graphPoint1.getX() - d1 * _xScale;
67:
68:                _yLogScale = yLogScale;
69:                d1 = Util.log(dataPoint1.getY(), yLogScale);
70:                dd = Util.log(dataPoint2.getY(), yLogScale) - d1;
71:                check(dd, "data", "y", d1);
72:                _yScale = (graphPoint2.getY() - graphPoint1.getY()) / dd;
73:                check(_yScale, "graphical", "y", graphPoint1.getY());
74:                _yOffset = graphPoint1.getY() - d1 * _yScale;
75:            }
76:
77:            private void check(double valueToCheck, String type, String axis,
78:                    double value) {
79:                if (valueToCheck == 0) {
80:                    throw new IllegalArgumentException("The " + type
81:                            + " reference points in " + axis
82:                            + " must be different; both are " + value);
83:                }
84:            }
85:
86:            public GraphPoint transformToGraph(DataPoint point) {
87:                return new GraphPoint(_xOffset
88:                        + Util.log(point.getX(), _xLogScale) * _xScale,
89:                        _yOffset + Util.log(point.getY(), _yLogScale) * _yScale);
90:            }
91:
92:            public DataPoint transformToData(GraphPoint point) {
93:                return new DataPoint(Util.exp((point.getX() - _xOffset)
94:                        / _xScale, _xLogScale), Util.exp(
95:                        (point.getY() - _yOffset) / _yScale, _yLogScale));
96:            }
97:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.