im trying to draw a curved line using mouse. there are three points on a straight line. a starting point, an ending point and a point in between. i want to draw a curved line by dragging the middle point in any direction. the other two points remain constant.

You're talking about a spline!
Will there only ever be three points or merely looking at the current three points in an array of points.
Do you want the curve to pass through the points or use them as a guide for placing a smooth curve!

If you're on the curve then that means that they all have the same radius from the center of a circle right? Draw 3 points on a piece of paper. Take a compass draw some intersecting curves. Do you see your answer?

Now think ellipse.

Circumference of a circle is 2 PI r = PI (r + r)
Or think of r as x, so PI (x + x ) since x = y on a graph.
Circumference of an elipse is PI (x + y)

im trying to draw a curved line using mouse. there are three points on a straight line. a starting point, an ending point and a point in between. i want to draw a curved line by dragging the middle point in any direction. the other two points remain constant.

Three points can produce all sorts of different curves, not just one. What kind of curve are you talking about? A Bezier curve?

could you please elaborate. or give an example. i want the curve to pass through the three points. the three points may not be place equidistant from the center. two could be right next to each other

i want any kind of curve which will contain the three points

What kind of curve! As Vernon Dozier indicates.

For example, if the moving point is between the two center points on a curve. Put it between them. Now move tangent to the line between the two end points. It's a circle, but if you get further the 1/2 the distance between the two points your circle flips. Instead of being between the two points on the acute angle formed by those two points and the circle midpoint of the circle. You are now on the obtuse side of the angle.

This is only one type of curve. There are others!

Since you want any curve. Try working with what I just posted. Forget curve for now, think on full circule. change to an arc later once it works.

The one thing in common with what I posted is there is one center point, and all three points have the same radius from that point!


i have attached a picture of how the curve should look like. the three points are shown

i want any kind of curve which will contain the three points

[ATTACH]10803[/ATTACH]

i have attached a picture of how the curve should look like. the three points are shown

It may be a Bezier, I'm not sure. Being as this is the Java forum, Java has a tailor-made Bezier-Curve option, so go with what's already there. Here's an applet I made.

http://www.derekscswebsite.com/MathStuff/BezierCurve/index.html

You're looking at using a GeneralPath, using curveTo, I would imagine. Three points will make your curve, so curveTo expects six doubles/floats (two doubles/floats per point).

http://java.sun.com/javase/6/docs/api/java/awt/geom/GeneralPath.html

http://java.sun.com/javase/6/docs/api/java/awt/geom/Path2D.Float.html#curveTo(double,%20double,%20double,%20double,%20double,%20double)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.