Okay, I don't know how to explain this but ill try...
I need this to work for a project that im programming in flash
I have a line with a specified length, going from a specified base-point
this line rotates so that it always points at the mouse-cursor.
but if the distance between its base-point and the mouse-cursor is less than the line-length, I want to curve the line, with a specified amount of segments, so that its end-point is equal to the mouse-point.
I don't know how to do the curve effect properly though.
I tried letting the total curvature of the line be PI*2 radians(360 degrees) if the distance is 0, and 0 if the distance is greater than the length, and have a constant change between that
that of course, wouldnt produce the correct result, the line-end-point and the mouse-point are only equal when the distance is zero or equal to the lineLength.
The distance from the end point to the initial point shouldn't change at a constant rate. It's a trigonometric issue someone told me.
this flash demonstrates it, and you might get a better idea of what I'm after.
I heard the entire arc in radians should be the
arc cosine of(distance / lineLength) * 2
this produced a better result but thats still not it.
you can see that here:
I really hope someone here can help me with this.
I would *really* appreciate it.
Any comments or small help is welcome, and if there's anything else i need to specify to make it easier for you to help me then just tell me..
Thanks in advance!
Curve a line to reach desired distance fom its base?
Started by clox, Jul 02 2008 09:07 AM
1 reply to this topic
#1
Posted 02 July 2008 - 09:07 AM
#2
Posted 03 July 2008 - 10:39 AM
You could solve with a minimization function that finds the nearest circle that passes for your two points.
http://en.wikipedia.org/wiki/Circle
This is a system of three equations:
1st the general circle eq
2nd first point (line starting point)
3rd second point (line ending point)
Solving this gives a system of cirlces (meaning you still have one free parameter: the radius).
Or, put simply, infinite circles all with their centers laying on a line passing in the middle of your two points.
Now to isolate the two circles that do what you want we use trigonometry.
Your line length (actual distance between two points) is right on mark
the distance is the sin of the angle that encludes it.
This boils down to this:
Radius = LineLength / (arcsin(PointsDistance))
So if you put this in your system, you end up with two identical circles, one on each side of the line passing for your two points.
Let's see how to do this
this is the general circle formula
(x-alpha)^2 + (y-beta)^2 = r^2
this can be rewritten as
x^2 + y^2 + ax + by + c = 0
now with
x=x1
y=y1
we have
x1^2 + y1^2 + a*x1 + b*y1 + c = 0
then we can isolate a
a = -( x1^2 + y1^2 + b*y1 + c) / x1
then, take again the general eq, put in a, and then put in P2
x^2 + y^2 + (-( x1^2 + y1^2 + b*y1 + c) / x1) x + by + c = 0
x=x2
y=y2
we have
x2^2 + y2^2 + (-( x1^2 + y1^2 + b*y1 + c) / x1) * x2 + b*y2 + c = 0
and now we solve for b
b = (x2^2 + y2^2 + all the rest) / (y2 - x2/x1 * y1)
So now we have some formula (bear with me as i let you get all the numbers and symbols) with just one parameter left out: c
we have that
alpha = - a / 2
beta = - b / 2
c = alpha + beta - r^2
so
c = - a / b - b / 2 - r^2
and, from the previously stated trigonometric formula, we have
Radius = LineLength / arcsin ( PointDistance)
so c = - a/2 - b/2 - (LineLength/arcsin(PointDistance))^2
Now you have a complete equation possibily with a further degree of freedom
In fact this equation points to two identical circles.
You have to manually choose which one suits you best.
Hope it is clear enough, it's sometime since i did this last time, and i have never been too clever at explaining things.
http://en.wikipedia.org/wiki/Circle
This is a system of three equations:
1st the general circle eq
2nd first point (line starting point)
3rd second point (line ending point)
Solving this gives a system of cirlces (meaning you still have one free parameter: the radius).
Or, put simply, infinite circles all with their centers laying on a line passing in the middle of your two points.
Now to isolate the two circles that do what you want we use trigonometry.
Your line length (actual distance between two points) is right on mark
the distance is the sin of the angle that encludes it.
This boils down to this:
Radius = LineLength / (arcsin(PointsDistance))
So if you put this in your system, you end up with two identical circles, one on each side of the line passing for your two points.
Let's see how to do this
this is the general circle formula
(x-alpha)^2 + (y-beta)^2 = r^2
this can be rewritten as
x^2 + y^2 + ax + by + c = 0
now with
x=x1
y=y1
we have
x1^2 + y1^2 + a*x1 + b*y1 + c = 0
then we can isolate a
a = -( x1^2 + y1^2 + b*y1 + c) / x1
then, take again the general eq, put in a, and then put in P2
x^2 + y^2 + (-( x1^2 + y1^2 + b*y1 + c) / x1) x + by + c = 0
x=x2
y=y2
we have
x2^2 + y2^2 + (-( x1^2 + y1^2 + b*y1 + c) / x1) * x2 + b*y2 + c = 0
and now we solve for b
b = (x2^2 + y2^2 + all the rest) / (y2 - x2/x1 * y1)
So now we have some formula (bear with me as i let you get all the numbers and symbols) with just one parameter left out: c
we have that
alpha = - a / 2
beta = - b / 2
c = alpha + beta - r^2
so
c = - a / b - b / 2 - r^2
and, from the previously stated trigonometric formula, we have
Radius = LineLength / arcsin ( PointDistance)
so c = - a/2 - b/2 - (LineLength/arcsin(PointDistance))^2
Now you have a complete equation possibily with a further degree of freedom
In fact this equation points to two identical circles.
You have to manually choose which one suits you best.
Hope it is clear enough, it's sometime since i did this last time, and i have never been too clever at explaining things.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











