?
Solved

Equatin of Arc - using 2 given points

Posted on 2005-04-08
47
Medium Priority
?
504 Views
Last Modified: 2012-06-21
Hi experts

if i have two given end points (a, b) (c, d)  of an arc then
is it possible to find  the equation of the arc ?( i mean equation of the circle in which it belongs)
its urgent please...
Thanks

0
Comment
Question by:Shiju Sasidharan
  • 15
  • 14
  • 6
  • +5
47 Comments
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13735283
It depends...
Is the arc a perfect semi-circle? I'm guessing not; in which case, I believe you need to specify the radius of the circle...
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13735288
Or, you need to specify a third point..
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13735402
If it's a perfect semi-circle, then you should be able to calculate the diameter of the circle, which the arc belongs in, with something like this:

        d = sqrt( (c-a)^2 + (d-b)^2 )
   
    And therefore, to calcualte the circumference of the circle, you'd use:

        c = PI(d)

    Or the area of the circle:

        a = PI (d/2)^2


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13735424
But, obviously, if the vector of the two points (the chord of the circle), doesn't pass the center of the circle (and thus, is not the diameter), then you must specify either the radius of the circle (which I'm sure you don't know), or, a third point -- as I've already said.
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13735437
Or, actually; a third option: if you can specify the angle of which the arc covers...
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13735533
hi InteractiveMind
thanks for the quick reply
  Arc need not be semi circle in most of the case ..:-(

 
   is it possible to get centre and radius, if any two points in an arc is given ?


 
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13735548
ok if three points are there then any chance ?
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13735593
erm... I can try and think up an equation for three points.. give me a short while though..

If you can specify the ange of the arc, then this should work:

  c (circumference of circle)  =  PI * 2( Sin( 180 - (theta)) ( sqrt( (c-a)^2 + (d-b)^2 ) / Sin(theta) )

I'll see if I can come up with one for three points though..

Regards;
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13735599
* where (theta) is the angle..
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13735764
hi
     ok is there a way to find the angle of a an arc, when two end points are given?
     InteractiveMind , i only have two end points of an arc with me :-(
     i am keeping this question open for getting more ideas ...

0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13735890
No, I'm afraid that this can't be done with just two end points. To understand why, draw two circles. Both of different sizes. Now, draw 2 chords, one on each circle.. But both of the chords must be the same size..

Do you see? The chords (which can be presented as a vector of the two points you have) are the same size, but can both fit perfectly onto two different sized circles.

In which case, you would need to either specify a third point, or the angle to which the arc spans.

Sorry.

Regards;
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13735954
What is it that you're actually trying to achieve here, however?

I'm confident that there's a way round this: btw, I program also, so I have a good idea of the concepts that you're working with here...

Assuming it's an application you're working on here, what does it do? Where do you get the two points for this arc from?
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13735992
yes i got it u r right , thank u InteractiveMind
Question is updated :

 consider u r given  three points
  (a, b)          (p,q)               (c,d)
     
      where first and last are end points of the arc, and (p,q) a point in between end points
now is it possible to find centre or radius ?
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13736035
with a third point, you can use something like this:
   
    A  =  arccos( ( Ux(Vx) + Uy(Vy) ) / |U| |V| )
    theta = 360 - 2A
    c (circumference of circle)  =  PI * 2( Sin( 180 - (theta)) ( sqrt( (c-a)^2 + (d-b)^2 ) / Sin(theta) )

where U and V are the two vectors (U = (a,b) to (c,d) & V = (c,d) to (e,f)). But it's not the nicest thing to work with :) lol
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13736041
If you give me a mo, then I can probably turn your co-ordinates in a single equation.....
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13736069
ok My application problem is
i have set of points in advance , i can join these points to make a line graph. but i need to make it smooth curve. Any idea ?
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13736173
> i have set of points in advance , i can join these points to make a line graph. but i need to make it smooth curve. Any idea ?
Okay.. this "smooth curve": is it just a single arc (curve), or will it be a load of combined arcs?
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13736191
..Is this Line Graph a CF (Cumulative Frequency) graph?
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 13737399
consider u r given  three points
  (a, b)          (p,q)               (c,d)
     
      where first and last are end points of the arc, and (p,q) a point in between end points
now is it possible to find centre or radius ?

(dx1, dy1) = (p,q) - (a,b)  // differences between the points
(dx2, dy2) = (p,q) - (c,d)

(cx1, cy1) = 0.5*((p,q) + (a,b));   // centerpoints between points
(cx2, cy2) = 0.5*((p,q) + (c,d));

// just to keep the expressions below simple
K1 = -dy1 * cx1 + dx1 * cy1;
K2 = -dy2 * cx2 + dx2 * cy2;

Here are the line equations for the bisectors of the lines between points.
-dy1 * x + dx1 * y = K1
-dy2 * x + dx2 * y = K2
These two lines intersect at the center of the circle.  Using Kramer's rule:

Det = -dy1 *dx2 + dy2 * dx1; // when Determinant is 0, the three points are colinear and there is no solution
circlex = (K1 * dx2 - K2 * dx1) / Det;
circley = (-dy1 * K2 + dy2 * K1) / Det;

The circle is centered at (centerx, centery).  Radius is sqrt((centerx - a)^2 + (centery - b)^2).
0
 
LVL 31

Assisted Solution

by:GwynforWeb
GwynforWeb earned 500 total points
ID: 13737749
Drawing asmooth curve through points is not a  simple problem you need splines for this. the curves using arcs will have jagged derivatives at the joining points. I suggest see Hermite Splines (Cardinal variety), if you think you can deal with them I can explain further.


Hermite Splines (Cardinal variety)

Given points  pk=(xk,uk) then a smooth curve can be defined between 2 points pk=(xk,yk) and pk+1 (xk+1,yk) by a  parametric curve P(u)= (x(u),y(u))  0<u<1 where

      P(u) is a cubic between 2 points pk points pk+1 and with the derivatives defined as Dpk and Dpk+1 at either end

P(u)=pk(2u3-3u2+1) + pk+1(-2u3+3u2) + Dpk(u3-2u2+u) + Dpk+1(u3-u2)

 
and where

Dpk    = 0.5(1 - t)(pk+1 - pk-1)

Dpk+1 = 0.5(1 - t)(pk+2 - pk)    

t is a user defined constant and is the tension parameter. t=0 gives Catmull-Rom splines, t>0 gives a tighter curve, t<0 looser curve.


0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 13737780
I mean

P(u)=pk(2u³-3u²+1) + pk+1(-2u³+3u²) + Dpk(u³-2u²+u) + Dpk+1(u³-u²)

0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13738412

@NovaDenizen
>>circlex = (K1 * dx2 - K2 * dx1) / Det;
>>circley = (-dy1 * K2 + dy2 * K1) / Det;
u mean to say that these are the coordinates of the centre. ok then i will check it out.

@GwynforWeb
>>P(u)=pk(2u³-3u²+1) + pk+1(-2u³+3u²) + Dpk(u³-2u²+u) + Dpk+1(u³-u²)
sorry, its very difficult for me to understand ur statements, i am not a genius in maths
i only need formula to find centre of the arc, i only have is 3 points as i commented earlier.
using those values i need to calculate the centre or radius of the arc. thats all.

i will check it out  NovaDenizen's comment,
anyway the question is open ....

;-)
Shiju


0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13738473
hi

@InteractiveMind
>> this "smooth curve": is it just a single arc (curve), or will it be a load of combined arcs?
sorry i forgot to reply. yes it will be a load of combined arcs.
suppose there are 5 points then
then take points 1,2,3 and draw arc from 1 to 2.
now take points 2,3,4 and draw arc from 2 to 3.
now take points 3,4,5 and draw arc from 3 to 4.
now join 4 to 5.

;-)
Shiju

0
 
LVL 6

Expert Comment

by:Sergio_Hdez
ID: 13739766
I once built a formula to join a set of points using arcs BUT avoiding the ugly angles in the union of two arcs, as you would get using your last post idea.

The ugly point is that the curve I constructed didn't pass over the given points, but over their mid points, so if you have point 1,2,3,4 and 5, then you also have mid points that you can call 1-2 (mid point betwen 1 and 2), 2-3, 3-4 and 4-5.

The idea behind it, if you would use it, is that: Duplicate first and last point, so you have points 0,1,2,3,4,5 and 6, now, for each "real" point (from 1 to 5), for instance point 3, you draw the arc that start on previous mid point (2-3), ends on following mid point (3-4), but the trick to avoid ugly joints is not force the arc to pass on the real point 3, instead, you make this:

From 2-3, "draw" a line perpendicular to vector that goes from (2-3) to 3, and from 3-4 draw another line perpendicular to vecto from (3-4) to 3. Those two lines intersect on the center of the arc to be drawed. Repeat it with all the "real" points, and you get a "Spline" line made up of circle arcs that joint perfectly smooth... but it doesn't pass throu the original points, remember!

If you need the curve to pass throu a set of given points, and the curve to be smooth, then you HAVE to go to a spline function. It is not that difficult, I can explain a little bit for you:

The idea is that given a "control point set", and a pair of consecutive points of that set, you can easily find a pair of functions X(t) and Y(t), with t from 0 to 1, that when drawed, you get a perfect smooth curve from one point to the other. You have to repeat it from pair 1 and 2, then pair 2 and 3, and so on to the last pair 4 and 5 in our case, constructing a single curve passing on all points and being perfectly smooth.

Hermite Spline is one of the possible formulas to use, there are others, but this one is simple (in comparation) and very smooth. Other options can be X(t) and Y(t) being single polinomials (in Hermite splines you have several X(t) and Y(t), not a single pair) of grade N-1 (N= number of points), but it has a big problem: The more points you use, the more "drastic" the curve is... it doesn't tend to be gentle and smooth, it tends more to be abrupt and to go away from your paper sheet... unusable!

So you better use Splines, beliebe me, you have not a simplier solution for that!

GwynforWeb has given you the formulas I mentioned before to build the X(t) and Y(t) that will joint to adjacent points, you need to code them, and draw each one of them on screen by using somthing like this:

//The main loop should look like this (delphi pseudo-code):
var Dpk, Dpk1: double;
     CoordX, CoordY: double;
     X, Y: array of double;
//N = Number of points
//X[k] an Y[k] = coordinates of point number k.
For k:= 1 to N-1 do begin
  //For each segment
  For t:= 0 to 1 step 0.01 do begin
    Dpk:=    0.5*(1 - t)*(X[k+1] - X[k-1]);
    Dpk1:=  0.5*(1 - t)*(X[k+2] -X[k]);
    CoordX:= X[k]*(2*t^3 - 3*t^2+1) + X[k+1]*(-2*t^3+3*t^2) + X[k]*(t^3-2*t^2+t) + X[k+1]*(t^3-t^2);
    CoordY:= Y[k]*(2*t^3 - 3*t^2+1) + Y[k+1]*(-2*t^3+3*t^2) + Y[k]*(t^3-2*t^2+t) + Y[k+1]*(t^3-t^2);
    Draw_point_at( CoordX, CoordY);
  end;
end;
 
As you see, it is not so complicated, really simplier than using arcs.

Of course you could make it better, for instance, precalculate t^2 and t^3 to speed up the calcs, and draw small lines between actual point and prior point instead of just plotting isolated points, etc, but the basic code is just as simple as this example.

A more polished version of the code using the 2 ideas mentioned avobe:

//The main loop should look like this (delphi pseudo-code):
var Dpk, Dpk1: double;
     CoordX, CoordY, LastX, LastY, t2, t3: double;
     X, Y: array of double;
//N = Number of points
//X[k] an Y[k] = coordinates of point number k.
For k:= 1 to N-1 do begin
  //For each segment
  For t:= 0 to 1 step 0.01 do begin
    //Precalculate t^2 and t^3 to speed up a little...
    t2:= t^2;
    t3:= t2*t;
    Dpk:=    0.5*(1 - t)*(X[k+1] - X[k-1]);
    Dpk1:=  0.5*(1 - t)*(X[k+2] -X[k]);
    CoordX:= X[k]*(2*t3 - 3*t2+1) + X[k+1]*(-2*t3+3*t^2) + X[k]*(t3-2*t2+t) + X[k+1]*(t3-t2);
    CoordY:= Y[k]*(2*t3 - 3*t2+1) + Y[k+1]*(-2*t3+3*t^2) + Y[k]*(t3-2*t2+t) + Y[k+1]*(t3-t2);
    //The first point is not drawed, we need 2 points to draw a segment
    if NOT((k=1) and (t=0)) then
      Draw_Line(LastX, LastY, CoordX, CoordY);
    //Store this point to be used in next segment
    LastX:= CoordX;
    LastY:= CoordY;
  end;
end;
0
 
LVL 6

Assisted Solution

by:Sergio_Hdez
Sergio_Hdez earned 500 total points
ID: 13739816
Sorry, I copied badly the formula, it should be:

  CoordX:= X[k]*(2*t3 - 3*t2+1) + X[k+1]*(-2*t3+3*t^2) + Dpk*(t3-2*t2+t) + Dpk1*(t3-t2);
  CoordY:= Y[k]*(2*t3 - 3*t2+1) + Y[k+1]*(-2*t3+3*t^2) + Dpk*(t3-2*t2+t) + Dpk1*(t3-t2);
0
 
LVL 3

Expert Comment

by:mathbiol
ID: 13740410
shijusn,

You can do some algebra and get an exact solution.  Personally I like to minimize risk of algebra errors by making up variable names for as many intermediate expressions as possible.  Anyway here are the equations.

Suppose (x0, y0) is the unknown center of the circle that passes through your three points, (x1, y1), (x2, y2), (x3, y3), with unknown radius r.  Solve for x0 in

Eq1    (x1 - x0)^2 + (y1 - y0)^2 = (x2 - x0)^2 + (y2 - y0)^2

(this is true because both sides are equal to the radius squared)

Plug the expression for x0 into

Eq2     (x1 - x0)^2 + (y1 - y0)^2 = (x3 - x0)^2 + (y3 - y0)^2

(again, this is true because both sides are equal to the radius squared)

Solve for y0.  You now have an actual value for y0.  Up to this point you've done some messy but straightforward algebra.  The squares of x0 and y0 drop out, so you'll just be solving a pair of simultaneous equations.  (Let me know if you have any trouble with this -- I'll have time to do it about 5 hours from now.  We don't have to use my variable names -- we can use a, b, p, q, etc. if you prefer.)

Plug the value of y0 into Eq1 to calculate the value of x0.  Calculate r with

Eq3     r = sqrt[ (x1 - x0)^2 + (y2 - y0)^2 ]

Now that you have values for x0, y0 and r, you can, for any desired value of x, calculate the upper hemisphere y-coordinate with

Eq4     y = y0 + sqrt[ r^2 - (x - x0)^2 ]

and the lower hemisphere y-coordinate with

Eq5     y = y0 - sqrt[ r^2 - (x-x0)^2 ]

Good luck!

mathbiol

0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 13741972
Given 3 points (a,b), (c,d), and (e,f)

then the circle fitting through the 3 points is

   (x-h)² + (y-k)² = r²

where

    k = ((a²+b²)(e-c) + (c²+d²)(a-e) + (e²+f²)(c-a)) / (2(b(e-c)+d(a-e)+f(c-a)))

    h = ((a²+b²)(f-d) + (c²+d²)(b-f) + (e²+f²)(d-b)) / (2(a(f-d)+c(b-f)+e(d-b)))

    r² = (a-h)² + (b-k)²  
0
 
LVL 3

Expert Comment

by:mathbiol
ID: 13742109
shijusn,

Gwyn did the algebra, and it came out elegantly, and easy to read with his choice of letters.

Just to make sure you know how to use his equations:

Calculate k and h as he wrote.  Then calculate

r = sqrt[ (a-h)² + (b-k)² ]

Now if you have a value of x and would like to find the two corresponding y values (upper and lower hemispheres):

yupper = k + sqrt[  r² - (x-h)² ]

ylower = k - sqrt[  r² - (x-h)² ]

I’m sorry I did not notice earlier that NovaDenizen’s solution is equivalent to this approach – it is also exact.

mathbiol
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13742853
hi
@mathbiol
 excellent , i got ur statements. very helpful way of teaching thank u
 i tried ur solved equations u gave and finally reached GwynforWeb's result

@GwynforWeb
  u gave me what i asked , thank u
  but i think i need to go for somthing like Hermite Splines as u said

@Sergio_Hdez
     Can u please make ur formula simple so that i can put values as GwynforWeb has given

Now another critical problem is, three points may not be in the circle always, it may be another curve. and i am really stuck here
ok see, A B and C are points in the Arc. where A and B are end points

my "aim is to convert a line graph into Curved graph"
and i only have is set of points.

;-)
Shiju
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13742874

@Sergio_Hdez
 u were also referring to Hermite Splines, and converging to my solution

 
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13743588
@Sergio_Hdez
>>For k:= 1 to N-1 do begin
>>    Dpk:=    0.5*(1 - t)*(X[k+1] - X[k-1]);
>>    Dpk1:=  0.5*(1 - t)*(X[k+2] -X[k]);
 can u please check it out.
if my array index starts from 0 to N-1, there may have problems
well, i tried ur code it works,  but in each  point there seems to be a slight jumping on sharp edges
is it possible to bend smoothly on edges ?

0
 
LVL 3

Expert Comment

by:mathbiol
ID: 13744593
shijusn

There are lots of numerical methods for lots of different problems.  Can you tell us more about yours?  You have three points, and you'd like to draw a smooth curve through them.  You were originally thinking "circle", but now you're thinking that a circle might not be the best sort of curve for your problem....  Is this right?  Can you tell us a bit more about what you will do with the curve once you've got it?  Perhaps you'd like to display it on the screen as part of some sort of graphic.  Perhaps you'd like to interpolate -- that means that you've got an x-coordinate value somewhere in between the endpoints, and you'd like to calculate a y-coordinate value that sits on the smooth curve that passes through your three points....

mathbiol
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13746385
@mathbiol
 yes, u guessed it right
 i have a set of co-ordinates and i can easily join points to make a line graph. but that doesnt solve my problem. i would like to join these points using a smooth curve. and i started thinking the following method (i mentioned it before)
suppose there are 5 points then
then take points 1,2,3 and draw curve from 1 to 2.
now take points 2,3,4 and draw curve from 2 to 3.
now take points 3,4,5 and draw curve from 3 to 4.
now join 4 to 5.



0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13746520
To make this work, I suppose that you'd need to use up to 2 different arcs, between two points..The first arc is based on the first point, and the second arc.. and the second arc would be based upon the next arc, and the previous arc... lol, and so on..

Not at all easy; I truly think that you should ask yourself if it's *really* worth all the bother... ?

Regards;
0
 
LVL 85

Expert Comment

by:ozo
ID: 13746612
If you want your curve to go through every point and join smoothly you might
draw curve from 1 to 2, taking the points 1,1,2,3
draw curve from 2 to 3, taking the points 1,2,3,4
draw curve from 3 to 4, taking the points 2,3,4,5
draw curve from 4 to 5, taking the points 3,4,5,5
where the curve from b to c, taking the points a,b,c,d is
(1-t)*(t+1)*(b+(c-a)*t) + t*(2-t)*(c+(b-d)*(1-t))
where t goes from 0 to 1
0
 
LVL 85

Expert Comment

by:ozo
ID: 13746817
Sorry, that should have been
(1-t)*b + t*c + t*(1-t)*((1-t)*(b-a) + t*(c-d))
or
(1-t)*b + t*c + t*(1-t)²*(b-a) + t²*(1-t)*(c-d)
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13747390
hi
@ozo
  thank u for the comment. i am little bit confused
  ok if i am drawing  curve from 1 to 2, taking the points 1,1,2,3
  for each x value from point 1 to point 2  
   i need to use this formula for getting  y  value like this

   for point1_x_value     to      point2_x_value
         for t = 0 to 1 step 0.01
            y = (1-t)*b + t*c + t*(1-t)²*(b-a) + t²*(1-t)*(c-d)
            drawpoint(x,y)
         next
   next
 am i got correctl ?
0
 
LVL 3

Assisted Solution

by:mathbiol
mathbiol earned 500 total points
ID: 13748229
shijusn,

I guess the circle solution didn't give you the shape you would like....  In that case (without knowing more about what your goals are), I would agree with GwynforWeb that you should go with splines.  I will give you a basic idea of how they work.  Splines are a fun project.

You can work with three or more points.  The algorithm is the same, regardless of how many points you have.  Let’s call them Pi = (xi, yi).  I will assume that whatever points you decide to work with are exactly where you want them – in other words, you really do want the drawn curve to go exactly through your points Pi.

To explain the basic idea, I will assume you have three points.  We would like to find a function f1(x) that gives us the curve from P1 to P2 and a function f2(x) that goes from P2 to P3.  We want f1 and f2 to be continuous at P2, in other words f1(x2) and f2(x2) should both equal y2.  In addition we want all the derivatives at P2 to match up with each other, so that the two curve segments blend together as smoothly as possible.

Let’s choose a nice, easy form of the functions fi – let’s make them polynomials.  A quadratic would restrict the shape of the curve segments too much.  So let’s use cubics: fi(x) = ai x³ + bi x² + ci x + di.  We know the value of f1 at P1 and f2 at P2, so:

Eq1     a1 x1³ + b1 x1² + c1 x1 + d1 = y1
Eq2     a2 x3³ + b2 x3² + c2 x3 + d2 = y3

The continuity at P2 gives us

Eq3     a1 x2³ + b1 x2² + c1 x2 + d1 = y2
Eq4     a2 x2³ + b2 x2² + c2 x2 + d2 = y2

Now we need to differentiate fi(x) with respect to x.  The first derivative is

     fiprime(x) = 3 ai x² + 2 bi x + ci

We want f1prime evaluated at x2 to be equal to f2prime evaluated at x2:

Eq5     3 a1 x2² + 2 b1 x2 + c1 - 3 a2 x2² - 2 b2 x2 – c2 = 0

Do the same thing using the second derivative:

Eq6     6 a1 x2 + 2 b1 - 6 a2 x2 - 2 b2 = 0

Now we turn the reversible jacket inside out to show the lining.  Notice that we actually know the values of the xi, but we would like to find the values of the ai.  So change your point of view and think of the ai as the variables and the xi as the coefficients.  This is easier to do if you rewrite the equations.  I’ll show you Eq1 rewritten as an example:

Eq1     x1³ a1 + x1² b1 + x1 c1 + d1 = y1

Okay, we’ve got six linear equations in eight unknowns.  If we had two more equations, we’d be able to solve for the ai!

No matter how many points you start out with, you’ll always get to this same situation, of being just two equations short of a solution.

GwynforWeb suggested using the Hermite approach, in which you specify the derivatives at the endpoints.  The natural cubic spline approach has you setting the second derivatives to zero at the endpoints.  They’re both reasonable ways of coming up with two more equations.  Or there may be something special about your situation that allows you to specify something else about the endpoints.

There are routines and numerical recipes that solve the linear system for you, or you can write your own.

The more you tell us about the problem you started with, the easier it is for us to express opinions about appropriate endpoint assumptions and number of points to use.

mathbiol

P.S. Does anyone know how to get subscripts to come out in a posting?
0
 
LVL 85

Accepted Solution

by:
ozo earned 500 total points
ID: 13748742
Between point1 and point2
         for t = 0 to 1 step 0.01
            y = (1-t)*point1_y_value + t*point2_y_value + t*(1-t)²*(point1_y_value-point0_y_value) + t²*(1-t)*(point2_y_value-point3_y_value)
            x = (1-t)*point1_x_value + t*point2_x_value + t*(1-t)²*(point1_x_value-point0_x_value) + t²*(1-t)*(point2_x_value-point3_x_value)
            drawpoint(x,y)
         next
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13752058

@ozo
   Thank u ozo, i tried ur method. it worked, it draws smooth curves.
But if absolute value of difference between two adjacent y-coordinates are high then instead of bending, it takes a sharp bending(at palce between both the points) like 'V' shape
but it works fine otherwise . any idea ?
in such case i need either a straight line or a purely bend curve.
i hope i have expressed my problem clearly. thank u

@Sergio_Hdez
    i tried ur code and worked, and got a similar problem of sharp edge bending.
But if absolute value of difference between two adjacent y-coordinates are high,  i get a straight line, and its ok for that case, but in the opposite case i get smooth curve ONLY if y coordinate differences are less

@mathbiol
  thank u , ur comments are very explanative.
  just like a teacher's advice
  i have read ur statements ,  and stuck with the following statements
>>If we had two more equations, we&#8217;d be able to solve for the ai!
  that means we couldnt follow the method ??





0
 
LVL 3

Expert Comment

by:mathbiol
ID: 13754303
shijusn,

Here's what I meant:
If you have a system of eight linear equations in eight unknowns, then you can solve for the unknowns.  I derived six spline equations.  So we need two more in order to find a solution.

There are at least two reasonable ways to come up with two more equations for your problem.  You could use the Hermite approach or the natural spline approach.

Both will give you a smooth result no matter what your initial points are.

mathbiol

P.S.  Do all my apostrophes come out as
&#8217;
on other people's computers?  (I use an international English keyboard so as to be able to type easily in other languages.)
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 13760484
It sounds to me like you are looking for a Bezier curve. It's a form of spline that has predictable derivatives at its end points. I.E. you can make them join neatly. Interestingly, they also have very neat recursive drawing solutions so they are also very quick to draw. I havent got the maths at my fingertips but a quick google for 'Bezier' found many examples and discussions.

I think the Bezier curves are a subset of the Hermite curves that mathbiol has introduced, or is it the other way around?

Paul
0
 
LVL 85

Expert Comment

by:ozo
ID: 13760663
if absolute value of difference between two adjacent y-coordinates are high
the shape of the cubic spline I gave should be the same as the shape of the curve when absolute value of difference between two adjacent y-coordinates are low, just stretched
what are
point0_y_value, point1_y_value, point2_y_value, point3_y_value
when you see a sharp bend?
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13761152
@PaulCaswell
     i think Bezier curves dont meet all endpoints we specify it. i am looking for hermite
@ozo
     see if my 6 points are like this
     line segment  from a to b  has a sharp bending at the middle of the line  ab
    this is the case with bc, cd , de and ef
bending is like this
        /
      /
      \
       \
 
 
       b*             d*           f*

  a*            c*            e*        

0
 
LVL 85

Expert Comment

by:ozo
ID: 13765268
for 0,1,0,1,0,1 you should get

0
0.109
0.232
0.363
0.496
0.625
0.744
0.847
0.928
0.981
1
0.972
0.896
0.784
0.648
0.5
0.352
0.216
0.104
0.028
0
0.028
0.104
0.216
0.352
0.5
0.648
0.784
0.896
0.972
1
0.972
0.896
0.784
0.648
0.5
0.352
0.216
0.104
0.028
0
0.019
0.072
0.153
0.256
0.375
0.504
0.637
0.768
0.891
1

I see no sharp bend there.
0
 
LVL 3

Expert Comment

by:mathbiol
ID: 13766755
shijusn,

Thank you for showing us what your points are like. GwynforWeb suggested you use a spline fit.  We can now choose which type of spline is best for your points.

Let's use ozo's values as an example:
     (x,y)
P1 = (0,0) (you called this a)
P2 = (1,1) (you called this b)
P3 = (2,0)
P4 = (3,1)
P5 = (4,0)
P6 = (5,1)

Now we're cooking! Your spline should be periodic!  In other words, we would like the curve to look the same between P3 and P4 as it does between P1 and P2.  So we will use three points, exactly as I derived the six equations in the earlier comment, plus two new constraints:
(1) the curve should have the same slope at P1 and P3
(2) the curve should have the same second derivative at P1 and P3

From (1) we get

Eq 7    3 a1 x1² + 2 b1 x1 + c1 - 3 a2 x3² - 2 b2 x3 – c2 = 0

From (2) we get

Eq 8    6 a1 x1 + 2 b1 - 6 a2 x3 - 2 b2 = 0

Now we can solve for the unknowns ai and use the resulting polynomial functions to plot your curve.

You can either use these derivations to make your own code, or use one of many spline packages, with periodic endpoint conditions.

mathbiol
0
 
LVL 14

Author Comment

by:Shiju Sasidharan
ID: 13788547
hi
Thank u experts, It was really a great discussion.
it worked fine. and ur comments have opened new areas for me to learn and research
I am accepting answers from ozo, mathbiol GwynforWeb and Sergio_Hdez
(Sharing u equal points bcoz 4 of u were equally helpful)

;-)
Shiju
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Guide to the PMT, FV, IPMT and PPMT Functions In MS Excel we have the PMT, FV, IPMT and PPMT functions, which do a fantastic job for interest rate calculations.  But what if you don't have Excel ? This article is for programmers looking to re…
This article seeks to propel the full implementation of geothermal power plants in Mexico as a renewable energy source.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question