Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help in adding a control point for Bezier curve  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

Sorry if this question/similar question is answered before but I here is the code which creates the bezier curve with total 4 control points

Blue color is the starting and end control point.
Cyan color is the second and third control point.

I want to add a control point to the existing curve so that now I have 3 cyan coloured control points so that I can resize the curve from any of these 3 control points instead of the 2 control points. Can anyone please help in this as to what needs to be done for this?

I have attached the output of the below code as an attachment. Kindly help anyone.

Bezier-Curve-Output.png
[Thumbnail for Bezier-Curve-Output.png]
 
Saloon Keeper
Posts: 4336
108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the code do now, and where exactly are you stuck making the required changes?
 
Piyush Guptaa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code creates a bezier curve which can be resized by holding any blue or cyan circle and moving here and there. I have also attached a screenshot.

My question is I want to add another control point to this curve so that instead of 4, now I get 5 control points.

This is the code which actually creates the curve



However in this code, I can only pass 6 parameters to the function curveTo which are x and y coordinates or 2nd, 3rd nd 4th control points. How can I add another control point?
 
Tim Moores
Saloon Keeper
Posts: 4336
108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is not supported by the java.awt.geom.Path2D class and its descendants - they can handle only cubic Bezier curves. You'd need to implement this without using those classes - I'm sure there are libraries out there that do that.

On an unrelated note, if you're just starting out with graphics programming, use Swing (or the newer JavaFX) for GUI code, not the age-old AWT. Here, that means using JFrame instead of Frame, and implementing paintComponent instead of paint.
 
Piyush Guptaa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim for the reply. It really helped me. If there is any library which you would like to point me to will be great..
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!