• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this document? Why not share!

3D Curve Project

on

  • 3,124 views

Java3D is an Application Programming Interface used for writing 3D graphics applications and applets. This paper gives a short introduction of java3D, analyses the mathematics of Hermite, Bezier, ...

Java3D is an Application Programming Interface used for writing 3D graphics applications and applets. This paper gives a short introduction of java3D, analyses the mathematics of Hermite, Bezier, FourPoints, B-Splines curve, and describes implementation of curve creation and curve
operations using Java3D API.

Statistics

Views

Total Views
3,124
Views on SlideShare
3,121
Embed Views
3

Actions

Likes
1
Downloads
41
Comments
0

1 Embed 3

http://www.graphitech.it 3

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    3D Curve Project 3D Curve Project Document Transcript

    • Computer Graphics January 12,2007 Report of 3D curve project Chunhui Chen Mat. 123721 Email: njucch@hotmail.com University of Trento, Department of Computer Science Abstract Java3D is an Application Programming Interface used for writing 3D graphics applications and applets. This paper gives a short introduction of java3D, analyses the mathematics of Hermite, Bezier, FourPoints, B-Splines curve, and describes implementation of curve creation and curve operations using Java3D API. Keywords: Java3D, curve, Hermite, Bezier, FourPoints, B-Splines 1. Java3D Introduction The Java 3D API is an interface for writing programs to display and interact with three-dimensional graphics. The API provides a collection of high-level constructs for creating and manipulating 3D geometry and structures for rendering that geometry. Java 3D provides the functions for creation of imagery, visualizations, animations, and interactive 3D graphics application programs. A Java 3D application builds and manipulates a scene graph by constructing Java 3D objects and then later modifying those objects by using their methods. A Java 3D program first constructs a scene graph, once built, hands that scene graph to Java 3D for processing. The structure of a scene graph is Directed Acyclic Graph (DAG), parent-child relationship, and tree structure with root, branch and leaf. 1
    • Computer Graphics January 12,2007 2. Curve Mathematics All curve design is concerned with the creation of smooth curves based on a small number of user-controlled parameters. It is common that the curve has two endpoints and other controls to vary the shape of the curve. Cubic polynomials are very popular in curve design. Complex curves are often created segment-by-segment, using simpler curves for each segment. Therefore, the complete curve is determined by each segment and the continuity conditions at each join point. Geometric Continuity: G0: Curves are joined G1: First derivatives are proportional at the join point. The curve tangents have the same direction, but not necessarily the same magnitude. G2: First and second derivatives are proportional at the join point. Parametric Continuity: C0: Curves are joined. C1: First derivatives are equal. C2: First and second derivatives are equal. Cn: The nth derivatives are equal. Many curve are defined on a parameter t. Instead of the function y=f(x), the curve is defined as x=f(t), y=g(t), z=s(t), tε[0,1]. One popular method is to describe the curve as a matrix equation involving a basis matrix M, a geometry vector g, and a polynomial vector p. The general form for a parametric curve can be written as: θ (t ) = p k Mg t t The blending function is represented by p k M , which give the curve its unique shape. The basis matrix M determines the coefficients of the blending function. The geometric constraints are multiplied by blending function. It is common thus to differentiate different types of curves based on geometric constraints and the basis matrix. Hermite Curves Hermite curves are a foundation of interactive curve design. Commonly hermite curves are designed by two control points and tangent segments at each control point. Tangent handles may be interactively changed to adjust the shape of the curve once control points are placed. Hermite curves are easy to implement but have a number of drawbacks. For instance, it is difficult to determine how long to make a tangent handle in order to create a desired shape. To calculate a Hermite curve, we need the following vectors: 2
    • Computer Graphics January 12,2007 P0 : The startpoint of the curve T0 : The tangent vector at the first point (how the curve leaves the start point). P1 : The endpoint of the curve T1 : The tangent vector at the endpoint. The geometric constraints can be written in the form, g = [ P0 , P1 , T0 , T1 ]t Here we consider only x-component of the Hermite curve, as y and z components are the same. x(t ) = (t 3 , t 2 , t ,1) Mg ' ' The required equations are x (0), x (1), x (0) , x (1) x(0) = [0,0,0,1]t Mg x(1) = [1,1,1,1]t Mg Since x (t ) = [3t ,2t ,1,0] Mg ' 2 t x ' (0) = [0,0,1,0]t Mg x ' (1) = [3,2,1,0]t Mg Assume g = [ x(0), x(1), x (0), x (1)] , * ' ' t ⎡0 0 0 1⎤ ⎢1 1 1 1 ⎥ g* = ⎢ ⎥ Mg * ⎢0 0 1 0 ⎥ ⎢ ⎥ ⎣3 2 1 0 ⎦ Calculate inversion of matrix, we can get M as: ⎡2 − 2 1 1⎤ ⎢− 3 3 − 2 − 1⎥ M =⎢ ⎥ ⎢0 0 1 0 ⎥ ⎢ ⎥ ⎣1 0 0 0 ⎦ This yields blending function as: b1 (t ) = 2t 3 − 3t 2 + 1 3
    • Computer Graphics January 12,2007 b2 (t ) = −2t 3 + 3t 2 b3 (t ) = t 3 − 2t 2 + t b4 (t ) = t 3 − t 2 Thus, θ (t ) = b1 (t ) P0 + b2 (t ) P1 + b3 (t )T0 + b4 (t )T1 Drawing a single segment of a Hermite curve is relatively straightforward. A more complex shape can be created with piecewise Hermite curve segments. It is necessary to decide the continuity at the join point. In fact, it is not easy to construct desired shapes for a single segment as the tangent handles have to be moved very far away from the control points to produce significant bends. It is a drawback of Hermite curves. A possible method for this drawback is to weight the blending functions for the tangent vector. Or it is possible to relax the need for tangent handles by converting a Hermite curve into a cardinal spline. Bezier Curve As discussed above, using tangent handles to adjust the shape of curve is somewhat clumsy. The difficulties increase when creating piecewise cubic Hermite curves. Compensating for these drawbacks leads into Bezier curves. Linear Bezier Linear Bezier curve is obtained by linear interpolation between two control points P0 , P1 ; θ (t ) = (1 − t ) P0 + tP1 , t ∈ [0,1] Quadratic Bezier Quadratic Bezier is obtained by deCasteljau algorithm as a linear interpolation between linear interpolation between control points P0 , P1 , P2 . (1) Consider three control points, on the line segment P0 P1 , point P1 in the ratio (1-t): t. The (1) (1) (1) point P2 on the segment P P2 is at the same ratio. Then draw a line from P 1 1 to P2 . Locate the point θ (t ) at the same ratio on that line segment. This is the point on the curve at the specified value of t, t ∈ [0,1] . As show below: 4
    • Computer Graphics January 12,2007 θ (t ) = (1 − t ) P1(1) + tP2(1) = (1 − t )[(1 − t ) P0 + tP1 ] + t[(1 − t ) P1 + tP2 ] θ (t ) = (1 − t ) 2 P0 + 2t (1 − t ) P1 + t 2 P2 With Bezier curves, tangents are implicitly specified. The geometric constraints are the individual control points. The blending functions are as below: b0 (t ) = (1 − t ) 2 b1 (t ) = 2t (1 − t ) b2 (t ) = t 2 These blending functions happen to be the second-order Bernstein polynomials. In fact, it can be extended that higher-order Bezier curves use higher-order Bernstein polynomials as their blending functions. Bernstein polynomials is defined by n! Bi ,n (t ) = t i (1 − t ) n −i (n − i )!i! Cubic Bezier Bezier curves are described as one method for implicitly specifying tangents. The tangent is simply the vector created from segments extending from the first and last points. Thus Bezier curves are supposed to be an extension of Hermite Curve, suppose the implicit tangent in a Bezier curve is related to Hermite tangent by a linear relationship. Consider cubic curve with control points P0 , P1 , P2 , P3 . Implicit Bezier tangents as below: T0 = α ( P1 − P0 ) T1 = α ( P2 − P3 ) 5
    • Computer Graphics January 12,2007 Given a value of α , the geometric constraints of the Bezier curve can be specified in a manner similar to Hermite curve. The value α is defined as 3 for cubic Bezier to maintain constant velocity as t varies from 0 to 1. Bezier constraints vector is g = [ P0 P1 P2 P3 ] t Hermite geometric constraints indicated as ⎡1 0 0 0 ⎤ ⎡ P0 ⎤ ⎢0 0 0 1 ⎥ ⎢ P ⎥ g h = [ P0 P1 T0 T1 ] = ⎢ t ⎥⎢ 1 ⎥ ⎢- 3 3 0 0 ⎥ ⎢ P2 ⎥ ⎢ ⎥⎢ ⎥ ⎣0 0 - 3 3⎦ ⎣ P3 ⎦ We have known the basis matrix M h for Hermite curves. M h gh = M b g So the basis matrix of Bezier curves ⎡- 1 3 - 3 1⎤ ⎢3 - 6 3 0⎥ Mb = ⎢ ⎥ ⎢- 3 3 0 0⎥ ⎢ ⎥ ⎣1 0 0 0⎦ The blending functions of cubic Bezier curve b1 (t ) = (1 − t ) 3 b2 (t ) = 3t (1 − t ) 2 b3 (t ) = 3t 2 (1 − t ) b4 (t ) = t 3 The blending functions are the same as third-order Bernstein polynomials. Bezier curves of degree n General expression n n! θ (t ) = ∑ Bi ,n (t ) Pi , where Bi ,n (t ) = t i (1 − t ) n −i i =0 (n − i )!i! FourPoints Curve FourPoints curve passes each control point. We define geometric constraints as: g * = [ x(0), x(1 / 3), x(2 / 3), x(1)]t 6
    • Computer Graphics January 12,2007 ⎡0 0 0 0⎤ ⎢1/27 1/9 1/3 1 ⎥ A=⎢ ⎥ ⎢8/27 4/9 2/3 1 ⎥ ⎢ ⎥ ⎣1 1 1 1⎦ Thus we can get the basis matrix of FourPoints curve M as: ⎡- 4.5 13.5 - 13.5 4.5 ⎤ ⎢9 - 22.5 18 - 4.5⎥ M = A −1 = ⎢ ⎥ ⎢- 5.5 9 - 4.5 1 ⎥ ⎢ ⎥ ⎣1 0 0 0 ⎦ B-Splines Curve Spline curves originate from flexible strips used to create smooth curves. They are formed mathematically from piecewise approximations of cubic polynomial functions with zero, first and second order continuity. The problems with a single Bezier curve range from the need of a high degree curve to accurately fit a complex shape. To overcome these problems, B-Splines curves are introduced. B-Splines are one type of spline that are perhaps the most popular in computer graphics applications. They have many advantages Changes to a control point only affects the curve in that locality. Any number of points can be added without increasing the degree of the polynomial. Closed curves can be created by making the first and last points the same. The equation for k-order B-Splines with n+1 control points Pk are defined as follows: n θ (v) = ∑ Pk N k ,t (v) v ∈ [0, n - t + 2] , k =0 where t is the degree, normally 3 or 4, as the degree increases the smoother the curve becomes. Splines of degree 3 are by far the most commonly used in practice. N (v) are called blending functions. The blending functions are defined as ⎧1 if u k ≤ v ≤ u k +1 N k ,1 (v) = ⎨ ⎩0 otherwise v − uk u −v N k ,t (v ) = N k ,t −1 (v) + k + t N k +1,t −1 (v) u k +t −1 − u k u k + t − u k +1 u k is known as break points, also called knots on the curve. A knot vector (u 0 ,u 1 ...u n +t ) must be specified. For a given v, only t basis functions are not zero, therefore B-Splines depends on t 7
    • Computer Graphics January 12,2007 nearest control points at any point v. The shapes of the blending functions are determined entirely by the relative spacing between the knots. Scaling or translating the knot vector has no effect on shapes of basis functions and B-Splines. There can be a number of possible options for the knot positions. But more commonly the following function is used. ⎧0 k<t ⎫ ⎪ ⎪ u k = ⎨k - t + 1 t ≤ k ≤ n⎬ ⎪n - t + 2 k>n ⎪ ⎩ ⎭ 3. Scene Graph Structure 8
    • Computer Graphics January 12,2007 4. Implementation Detail User Interface (package gui) Class Functionality CurveMain Main class for running application Scene Initiate control and editor components TextOutputPanel Display functionality status CurveCtrls Curve control panel Curve Editor (package editor) Class Functionality CurveEditor Curve editor panel, create java3d canvas CurveGroup Wrap curve, points, and control lines. Curve operations. DrawerBehavior Curve drawing and operations Curve Geometry (package curve) Class Functionality Curve Abstract class for curve geometry HermiteCurve Hermite curve implementation BezierCurve Bezier curve implementation FourPointCurve FourPoints curve implementation BsplineCurve B-Splines curve implementation Utility (package util) Class Functionality ControlPoint Create control point geometry ControlPointCallback Callback for changing point position CurveCallback Callback for operating curve Plane Create plane geometry for projection GeomUtil Curve geometry utility View Class Functionality Land Create land lines geometry Curve Creation Curve creation is based on the part of “Curve Mathematics” discussed above and implemented by java. You can see details of implementation in accessory java document. Curve Operation As follows describe some main curve operations: 9
    • Computer Graphics January 12,2007 Project point on plane If the application is in plane mode, create a plane with mouse clicking. While drawing curve, if the mouse picking result is instance of Plane, we can get intersection point position on plane. Cut As curve is created by indexed coordinates, we can find the nearest curve coordinates from clicking position. Hermite curve: Find two nearest curve coordinates, and make them as new curve’s startpoint and tangent of startpoint. With these two new points and the other two, we can redraw new Hermite curve. Other curves: Find the nearest curve coordinate and index. Keep the line from first coordinate to found coordinate, and delete the other. Mirror Find two nearest curve coordinates. Calculate the linear equation by these two coordinates. Then mirror all of curve coordinates with that linear equation. At last, redraw the curve. Bounding Get curve bounds and create a box branch group with the bounds. Change curve branch group to be a child of box transform group. Then the curve group is included in box branch group and can be translated with it. Copy Pick selected curve and get all the parameters of picked curve. Create a new curve with the parameters. Join Select the first curve, get the endpoint and the tangent of endpoint. Select the second curve, get the startpoint and the tangent of startpoint. Create a new Hermite curve, which the startpoint’s position and tangent equals to the endpoint’s position and tangent of the first curve, the endpoint’s position and tangent equals to the startpoint’s position and tangent of the second curve. The continuity is C1. Save Pick selected curve and get all the parameters of picked curve. Build a DOM with the parameters. At last create an XML file from DOM and save it. On the contrary, to load a saved curve, just parse all of elements in the saved XML file to get parameters of curve, then draw a curve with the parameters in the scene graph. 10
    • Computer Graphics January 12,2007 5. Conclusion In conclusion, this report gives an introduction of Java 3D, the mathematics of four different curves, and describes the scene graph structure and also implementation details of project. Through this project, we can understand the mathematics of parametric curves very well. The implementation of this 3D curve application is a good experiment for advance 3D graphical programming. A few of works can proceed based on this project in future. Finally, thanks to Professor Raffaele De Amicis and Professor Conti for their guidance and help through out the project. Appendix (Application snapshot) 11