Solved

Curves and x, y points

Posted on 2002-06-24
13
311 Views
Last Modified: 2007-12-19
Hello everybody,

What I want is straightforward.
I need all the X, Y pairs of points of a quadratic curve.

For example I know the x1, y1 & x2, y2 and finally ctrX1 & ctrY1 points
to make the quadratic curve.

But I need to know the x,y points that this line is made of so I wil be able to
make an animation of an image up to this path. I itend not to draw the actual
line.

I found the PathIterator in the API but this does not really solve my problem.
From my understanding it reconstructs a complex shape with the aid of simpler ones.

It doesn't give any clues about the x,y points.
If I am wrong please tell me.

I found also a piece of code that I change it a bit to fit my needs. This will be
the worst solution though.
I cannot believe that for that simple problem I need to do the following. There must
be a simpler way.

What I found is to:
1. Make the curve
2. Take the Rectangle for that Shape with getBounds()
3. Make a smaller curve line
4. Take the rectangle for this as well
5. Subtract the areas (Not know how to do this)
6. Find the x, y points for the final area

Actually what I have just said is not the worst solution.
I thought somwthing even worst than this. :)
Anyway

I am not sure if this is possible.
What I have on hands is that foloowing code.

QuadCurve2D.Double q2d2 = new QuadCurve2D.Double( 10, 200, 95, 50, 200, 200);
r1   = q2d.getBounds2D().getBounds();

for (int x=0; x < r1.width; x++)
{
     for (int y=0; y < r1.height; y++)    
     {          
          if (ar1.intersects(r1.x+x,r1.y+y,1,1))   // this point is on the arc          
          {
               g2d.fillRect(r1.x + x, r1.y + y, 1, 1);
          }
     }
}

I do not know how to take the Area though form the previous shape.
Anybody can help me with some sample solution ???
Any comments ??
Other simpler ways ?
Do you thing I am in the right trck ?
Thank you in advance.
0
Comment
Question by:pouli
  • 7
  • 3
  • 3
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
What you need to do is to derive the quadratic function from x1,y1,x2,y2 then you can derive all y points you need in the intervals. If you have a problem with this, give us the values of the above points.
0
 

Author Comment

by:pouli
Comment Utility
I think there should be another way to get around without maths.

My maths are not good. But could you give me the equation, if you know it ?

I could see the source code for the Quadratic class but I think it will be easier if you know it to tell it to me :)


>If you have a problem with this, give us the values of >the above points

I have some values in the code. If this is what you mean.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
What exactly is it you want to paint?
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
OK, I need you to give me two valid pairs of values.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Come to think of it, I think I'll need 3 pairs of points. Where are these points coming from anyway? How do you know it's a quadratic finction?
0
 

Author Comment

by:pouli
Comment Utility
> What exactly is it you want to paint?
It is JLabel's images.

> OK, I need you to give me two valid pairs of values.
> Come to think of it, I think I'll need 3 pairs of  
> points. Where are these points coming from anyway? How  >do you know it's a quadratic finction?

QuadCurve2D.Double q2d2 = new QuadCurve2D.Double( 10, 200, 95, 50, 200, 200);

The result of what I want to do is the result of the previous line of code.

The x1, y1 & x2, y2 & ctrX1 & ctrX2 points will be changing according to my needss. They will simply be points on the screen. You could assume that is going to be anywhere on screen.

I do not know the quadratic function with 1 contol point. Do you ?

Anybody can think of any way find these points ?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:pouli
Comment Utility
Hello, again

I think that I must give the points to myself :-)
I found the answer. Unfortunately to a web site that is probably supported by M$ :-(

Anyway the writer is open minded.

The URL is :

http://www.maxcode.com/nuke/article.php?sid=232

It is for a Bezier line with 2 control points but if we give the same values to the 2 control points then we have the Bezier line with 1 control point :-)

And that's all.

Thank you all for your interest.

0
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
Comment Utility
Still confused about what you were trying to do.

My understanding was the QuadCurve already used Bezier's to determine it's path via the PathIterator class.

From PathIterator javadoc:

"This interface allows these objects to retrieve the path of their boundary a segment at a time by using 1st through 3rd order Bézier curves, which are lines and quadratic or cubic Bézier splines. "

0
 

Author Comment

by:pouli
Comment Utility
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class BezierLine extends JFrame
{

     Graphics2D g2d;
     
     
     double x1 = 100;
     double y1 = 100;
         
     double x2 = 300;
     double y2 = 300;
     
     double xa = 300;
     double ya = 50;
     
     double xb = 300;
     double yb = 50;
     
     public BezierLine()
     {
          setSize( 500, 500 );
          addMouseListener( new mouseListener() );
          show();
     }
     
     
     public void update( Graphics g )
     {
          paint( g );
     }
     
     public void paint( Graphics g )
     {
          g2d = (Graphics2D) g;
          double v2, v1;
          double x, y;
         
          int temp = 0;
          for( v1 = 0; v1 < 1; v1 = v1 + 0.01 )
          {
               v2 = 1.0 - v1;
               x = ( x1 * Math.pow(v2, 3.0) + (3.0 * xa * v1 * v2 * v2) + (3.0 * xb * v1 * v1 * v2) + (x2 * Math.pow(v1, 3.0)));
               y = ( y1 * Math.pow(v2, 3.0) + (3.0 * ya * v1 * v2 * v2) + (3.0 * yb * v1 * v1 * v2) + (y2 * Math.pow(v1, 3.0)));
               g2d.fillRect((int)x, (int)y, 1, 1);
               temp++;
          }          
          System.out.println(temp);
         
          g2d.fillRect( (int)xa, (int)ya, 3, 3 );
          g2d.fillRect( (int)xb, (int)yb, 3, 3 );
     }
     
     public static void main( String args[] )
     {
          new BezierLine();
     }
     
     private class mouseListener extends MouseAdapter
     {
          public void mouseClicked(MouseEvent e)
          {
               System.out.println("X is " + e.getX() + ", Y is " + e.getY() );
          }
     }
     
     
}
0
 

Author Comment

by:pouli
Comment Utility
This is a sample program that I made in order to check how it works.

My itention is not to draw the lines but accumulate the 100 points into an array and then pass them to a Thread that will animate the image along that path
:-)

I always support though the people who support me.
0
 

Author Comment

by:pouli
Comment Utility
Objects You told me once that the paint method is for the old version of Java, and I should not use it now.

COuld you give me the better version (1.4) from the previous program.

Or was it a missunderstanding ??
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
From reading the Javadoc the Quad2DCurve.getPathIterator appears to return the points you are after. I'd try it.

Regards using paint, it is still used for heavyweight components. It's just lightweights that you should use paintComponent for.

thanks for the points :)

http://www.objects.com.au/staff/mick
Brainbench MVP for Java 1
http://www.brainbench.com
0
 

Author Comment

by:pouli
Comment Utility
>From PathIterator javadoc:
>
>"This interface allows these objects to retrieve the path >of their boundary a segment at a time by using 1st >through 3rd order Bézier curves, which are lines and >quadratic or cubic Bézier splines. "

Objects I tried the PathIteratorand what I understood was that it breaks a complex shape into other smaller components using 1st & 3rd order Bezier curves. It gives the initial and final points but not the intermediate.

If I am wrong please tell me I would like to know how this can be done with Java api's.


0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now