Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to draw curve in java. i don't want quadratic or cubic curve. when i am drawing, it should display curve instead of line.
and i am using (x,y),(last_x,last_y),(x1,y1) coordinates.

What I have tried:

C#
if (pen_type==1){
           g2.fillOval( x, y, stroke_width, stroke_width );
       }  else if (pen_type==2) {
           g2.draw(new Line2D.Double(x, y, stroke_width, stroke_width));
       }
       else {
            //x1= ((76-4)/(6-0));
           // y= ((76-4)/(30-29));
           //y=((x*x*x)-(3*x));
           g2.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
           g2.drawLine(last_x, last_y,x,y);
            //g2.drawArc ( 0, 0, getWidth (), getHeight (), 80, -245 );
           //g2.draw(new Line2D.Double(x, y, stroke_width, stroke_width));

            //g2.drawArc(last_x, last_y, getWidth (), getHeight (), 90, 60);

           //g2.drawArc(x1, y1, last_x, last_y,5,5);

             QuadCurve2D.Double curve = new QuadCurve2D.Double(last_x, last_y,x1,y1,x,y);
             g2.draw(curve);



           //CubicCurve2D c = new CubicCurve2D .Float();
           //c.setCurve(x1, y1, last_x, last_y, x, y,x1,y1);
          // g2.draw(c);

       };
Posted
Updated 5-Nov-16 1:34am
Comments
Richard MacCutchan 5-Nov-16 6:24am    
What is the question?
Member 12821233 5-Nov-16 7:56am    
how can i draw curve in java?
draw curve instead of line..
i want to draw curve in java
Member 12821233 7-Nov-16 9:20am    
did you get any hint to draw curve in java?
Richard MacCutchan 7-Nov-16 10:20am    
Did you even bother to look at that link I gave you? There are plenty of examples all over the internet for drawing any curve, ellipse, circle etc.

1 solution

It is not clear what are you doing with your code. In any case, using drawLine you always draw a linear approximation of the curve (usually it is quite accetable). Such approximation is the more accurate the smaller are the linear segments approximating the curve (see Arc length - Wikipedia[^]).
 
Share this answer
 
Comments
Member 12821233 5-Nov-16 8:02am    
thank you for replying me.
actually i am trying to draw curve. i want to draw curve instead of line.
is there any other way to draw curve? like using dx and dy coordinate?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900