Source Code Cross Referenced for Spline2D.java in  » Graphic-Library » jgraph » org » jgraph » util » 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 » Graphic Library » jgraph » org.jgraph.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)Spline2D.java
003:         * 
004:         * Copyright (c) 2003 Martin Krueger
005:         * Copyright (c) 2005 David Benson
006:         *  
007:         */
008:        package org.jgraph.util;
009:
010:        import java.awt.geom.Point2D;
011:
012:        /**
013:         * Interpolates points given in the 2D plane. The resulting spline
014:         * is a function s: R -> R^2 with parameter t in [0,1].
015:         * 
016:         * @author krueger
017:         */
018:        public class Spline2D {
019:
020:            /** 
021:             *	Array representing the relative proportion of the total distance
022:             *	of each point in the line ( i.e. first point is 0.0, end point is
023:             *	1.0, a point halfway on line is 0.5 ).
024:             */
025:            private double[] t;
026:            private Spline splineX;
027:            private Spline splineY;
028:            /**
029:             * Total length tracing the points on the spline
030:             */
031:            private double length;
032:
033:            /**
034:             * Creates a new Spline2D.
035:             * @param points
036:             */
037:            public Spline2D(Point2D[] points) {
038:                double[] x = new double[points.length];
039:                double[] y = new double[points.length];
040:
041:                for (int i = 0; i < points.length; i++) {
042:                    x[i] = points[i].getX();
043:                    y[i] = points[i].getY();
044:                }
045:
046:                init(x, y);
047:            }
048:
049:            /**
050:             * Creates a new Spline2D.
051:             * @param x
052:             * @param y
053:             */
054:            public Spline2D(double[] x, double[] y) {
055:                init(x, y);
056:            }
057:
058:            private void init(double[] x, double[] y) {
059:                if (x.length != y.length) {
060:                    throw new IllegalArgumentException(
061:                            "Arrays must have the same length.");
062:                }
063:
064:                if (x.length < 2) {
065:                    throw new IllegalArgumentException(
066:                            "Spline edges must have at least two points.");
067:                }
068:
069:                t = new double[x.length];
070:                t[0] = 0.0; // start point is always 0.0
071:
072:                // Calculate the partial proportions of each section between each set
073:                // of points and the total length of sum of all sections
074:                for (int i = 1; i < t.length; i++) {
075:                    double lx = x[i] - x[i - 1];
076:                    double ly = y[i] - y[i - 1];
077:                    // If either diff is zero there is no point performing the square root
078:                    if (0.0 == lx) {
079:                        t[i] = Math.abs(ly);
080:                    } else if (0.0 == ly) {
081:                        t[i] = Math.abs(lx);
082:                    } else {
083:                        t[i] = Math.sqrt(lx * lx + ly * ly);
084:                    }
085:
086:                    length += t[i];
087:                    t[i] += t[i - 1];
088:                }
089:
090:                for (int i = 1; i < (t.length) - 1; i++) {
091:                    t[i] = t[i] / length;
092:                }
093:
094:                t[(t.length) - 1] = 1.0; // end point is always 1.0
095:
096:                splineX = new Spline(t, x);
097:                splineY = new Spline(t, y);
098:            }
099:
100:            /**
101:             * @param t 0 <= t <= 1
102:             */
103:            public double[] getPoint(double t) {
104:                double[] result = new double[2];
105:                result[0] = splineX.getValue(t);
106:                result[1] = splineY.getValue(t);
107:
108:                return result;
109:            }
110:
111:            public double getDx(double t) {
112:                return splineX.getDx(t);
113:            }
114:
115:            public double getDy(double t) {
116:                return splineY.getDx(t);
117:            }
118:
119:            public double getLength() {
120:                return length;
121:            }
122:
123:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.