Make a beizer curve intersect true the mouse courser(calculate of control points)
in
Programming Questions
•
2 years ago
Ok let me try to ex plane my problem I want to draw a ball with a horizontal line on it. And when I with the mouse courser move over the ball I want to turn the ball and then bend the horizontal line to give the impression of the ball turning.
In the end it should be both a horizontal and a vertical line but the problem is the same for both off them.
My idea is to use a ellipse to draw the ball and use a bezier for the horizontal line but I cant figure out how to calculate the control points to get the impression I want.
The real problem is how to calculate the controller points so I get a nice curve that intersects the mouse pointer when it's inside the ellipse.
See the images below where as I have programmed It now the curve will not intersect the mouse cursor. The mouse cursor is showed as a small ellipse with a point in.
I will use it on my android phone to control a robot and the "ball" I'm trying to draw is one of the controls to behave as an analog stick.
- void setup(){
- size(640, 480);
- smooth();
- }
- void draw()
- {
- background(200);
- fill(180);
- ellipse(width/2, height/2, 200, 200);
- stroke(0);
- noFill();
- bezier(width/2-100, height/2, width/2-100, mouseY, width/2+100, mouseY, width/2+100, height/2);
- bezier(width/2, height/2-100, mouseX, height/2-100, mouseX, height/2+100, width/2, height/2+100);
- fill(150);
- ellipse(mouseX, mouseY, 5, 5);
- point(mouseX, mouseY);
- }
1