Be seen. Boost your question’s priority for more expert views and faster solutions

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.

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().getBound

for (int x=0; x < r1.width; x++)

{

for (int y=0; y < r1.height; y++)

{

if (ar1.intersects(r1.x+x,r1.

{

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.

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.

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 ?

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.

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() );

}

}

}

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.

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

Or was it a missunderstanding ??

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

>

>"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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

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. "