How to control a graph of f(x) = y

In summary, the conversation discussed various techniques for creating a function that starts at a given point and ends at another given point, with control over the "curve amount" in between. These techniques include interpolation procedures such as hermite interpolation, b-splines, NURBS, and catmull-clark splines, as well as using a quadratic polynomial. The conversation also touched on the use of Lagrange polynomials and bezier curves to achieve the desired effect. The problem was slightly ill-defined, but the desired outcome was to have a smooth curve passing through three points, with the ability to move the middle point along a perpendicular line between the start and end points.
  • #1
Xcrypt
21
0
I'm programming a camera for a game, and to achieve some effect I think the best solution would be some kind of function.

jrsjg1.jpg


What I need to achieve, is a function that:

- 'starts' at x1, with a y value of y1.
- 'ends' at x2, with a y value of y2.
- I also need some parameter to control the 'curve amount' of the graph in between x1 and x2

('starts' and 'ends' mean that only the solution for the set of x values ['start' - 'end'] matter)

Unfortunately my calculus knowledge is very limited so I hope that someone here could explain to me what the correct solution is, and/or how to get there.
 
Physics news on Phys.org
  • #2
Well, one idea might be to pick an x value in between x1 and x2 and force the graph to pass through there to enforce the "curve amount" requirement. From there, I could show you how to construct a quadratic polynomial that will fit all three points.
 
  • #3
Robert1986 said:
Well, one idea might be to pick an x value in between x1 and x2 and force the graph to pass through there to enforce the "curve amount" requirement. From there, I could show you how to construct a quadratic polynomial that will fit all three points.
Well, please go on then :)
 
  • #4
Xcrypt said:
I'm programming a camera for a game, and to achieve some effect I think the best solution would be some kind of function.

jrsjg1.jpg


What I need to achieve, is a function that:

- 'starts' at x1, with a y value of y1.
- 'ends' at x2, with a y value of y2.
- I also need some parameter to control the 'curve amount' of the graph in between x1 and x2

('starts' and 'ends' mean that only the solution for the set of x values ['start' - 'end'] matter)

Unfortunately my calculus knowledge is very limited so I hope that someone here could explain to me what the correct solution is, and/or how to get there.

Hey Xcrypt and welcome to the forums.

The subject you are looking for is known as interpolation. For your problem, there are many different forms of interpolation procedures that produce a variety of different effects.

If you want to just get the techniques then any book that covers hermite interpolation, b-splines, NURBS, catmull-clark splines amongst others will give you the formulas and the techniques.

I know that this book: http://books.google.com.au/books/about/Computer_animation.html?id=lP5uw516QXIC&redir_esc=y has examples in terms of code that work so you might be interested in getting this for your own bookshelf but it's fairly old and there's probably a lot of better books since that came out.
 
  • #5
Thanks, just the techniques would do, the code (should) come naturally when you understand the techniques :)

Are these techniques you are naming covered in a calculus book?
I have heard many of them by name, but I haven't looked into them yet
 
  • #6
Xcrypt said:
Thanks, just the techniques would do, the code (should) come naturally when you understand the techniques :)

Are these techniques you are naming covered in a calculus book?
I have heard many of them by name, but I haven't looked into them yet

They are applications of calculus, but I doubt you'll find them in a standard calculus book. You usually find them in specialized books for things like computer graphics, engineering and areas where these are used and where specific information about the application is also talked about.
 
  • #7
I don't know what your exact situation is, but it seems that a quadratic polynomial might be the best way to go. If it doesn't then look up some of the stuff chiro mentioned.

So, we are going to pick three points on this curve and find a quadratic polynomial that fits these data. A quadratic has the form:

[tex]p(x)=a_2x^2 + a_1x + a_0[/tex]

and we want to find a quadratic such that:

[tex]p(x_i) = y_i, i = 1,2,3[/tex]

that is, we have three equatations in three unknowns. The unknowns are the [itex]a_i, i = 1,2,3[/itex]. Now, just solve this system for the three unknows, and you will have your polynomial. Also, you can pick a 4th point and construct a cubic polynomial in a similar manner. In general, if you pick n points, you can construct an (n-1)th degree polynomial that fits those points.
 
  • #8
Thanks, Robert1986 and chiro :)
 
  • #9
update:

I've found a 2nd degree polynomial that goes through 3 points.

x=0.0, y=1.0
x=0.3, y=0.3
x=1.0, y=0.0

Solved: ((40/21)*((x)^(2)))-((61/21)*(x))+1
(check http://www.freemathhelp.com/equation-grapher.html )

But this is not what I want because it's going under the x-axis instead of making a smooth curve. I think I'll use a bezier curve instead :)
 
  • #10
Lagrange polynomials are pretty handy
You could set up three points, x1, x2 and a new x3 in the middle, shift the coefficient of the x3 polynomial up and down and you should be able to change the 'curve ammount'
 
Last edited:
  • #11
I think the problem as stated is slightly ill-defined. Do you only want that shape on a bounded subset, or does the function need to have a horizontal asymptote as x goes to infinity?
 
  • #12
I'm not sure what a bounded subset is, but I certainly don't want an asymptote. The problem is slightly ill defined because I don't have much knowledge about calc + I'm not used to expressing math terms in English. But I hope you can get a 'feel' for what I want to achieve?

Anyway, I solved the problem with bezier curve now, still it would be nice to know how to do it with 'normal' polynomials.

I'll try to define better how I want to define the curve:

There should be three points making up the curve:
P1 (starting point)
P3 (end point)
P2, Length(P1,P2) = Length(P2,P3) (mid point)

You should be able to 'move' P2 around on a line that is perpendicular to [P1,P3], and goes through the point .5*(P1+P3)
 
  • #13
Xcrypt said:
I'm not sure what a bounded subset is, but I certainly don't want an asymptote. The problem is slightly ill defined because I don't have much knowledge about calc + I'm not used to expressing math terms in English. But I hope you can get a 'feel' for what I want to achieve?

Anyway, I solved the problem with bezier curve now, still it would be nice to know how to do it with 'normal' polynomials.

I'll try to define better how I want to define the curve:

There should be three points making up the curve:
P1 (starting point)
P3 (end point)
P2, Length(P1,P2) = Length(P2,P3) (mid point)

You should be able to 'move' P2 around on a line that is perpendicular to [P1,P3], and goes through the point .5*(P1+P3)

When he said asymptote I think he meant f(x)->0 as x -> infinity, like what's happening on your graph.
The bounded subset just means that you're only interested in the values of x between p1 and p3. :smile:

My idea about the lagrange polynomials would be able to do that!

The lagrange polynomials are handy little polynomials.
Let x1,x2,x3 be the x coordinates of p1,p2,p3 and y1,y2,y3 the y coordinates, then you can make 3 poynomials, which give zero at two of the three points and the value 1 at the other, like this;
[itex]P_1 (x1) = 1[/itex] , [itex]P_1 (x2) = P_1 (x3)=0[/itex]
[itex]P_2 (x2) = 1[/itex] , [itex]P_2 (x1) = P_2 (x3)=0[/itex]
[itex]P_3 (x3) = 1[/itex] , [itex]P_3 (x1) = P_3 (x2)=0[/itex]

To make this work you'd just have

[itex]P_1(x) = \frac{(x-x2)(x-x3)}{(x1-x2)(x1-x3)}[/itex]
[itex]P_2(x) = \frac{(x-x1)(x-x3)}{(x2-x1)(x2-x3)}[/itex]
[itex]P_3(x) = \frac{(x-x1)(x-x2)}{(x3-x1)(x3-x2)}[/itex]

I hope you can see that these will give the values I gave earlier, so to be able to do what you want (what I think you want at least) you define your f(x,a), where a defines the y value at x2;

[itex]f(x,a) = y_1 P_1(x) + a P_2(x) + y_3 P_3(x)[/itex]

Using the properties of the polynomials you can easily verify that this will give you the desired results.

Is this the kind of thing you are looking for?
 
  • #14
I think so, yes. Thanks
 

1. How do I change the scale of the x and y axes on a graph?

To control the scale of the x and y axes on a graph, you can adjust the range of values displayed on each axis. This can be done by changing the minimum and maximum values for each axis, or by using a logarithmic scale. Most graphing software programs have options to customize the axis scales.

2. Can I change the color or style of the graph line?

Yes, you can control the appearance of the graph line by changing its color, thickness, and style. In most graphing software programs, you can do this by selecting the graph line and then choosing the desired color and line style from a menu or toolbar.

3. How can I add labels and titles to my graph?

To add labels and titles to your graph, you can use the labeling or annotation feature in your graphing software. This allows you to add text boxes, arrows, and other shapes to the graph to label different points or explain the data. You can also add a title to your graph to summarize the data being presented.

4. Is it possible to add multiple graphs on the same plot?

Yes, it is possible to add multiple graphs on the same plot. This can be useful for comparing data or showing different relationships between variables. In most graphing software programs, you can add multiple graph lines or data sets to the same plot by selecting the option to add a new data series.

5. Can I customize the appearance of the grid lines on my graph?

Yes, you can customize the appearance of the grid lines on your graph. You can change the color, thickness, and style of the grid lines to make them more visible or to match the overall design of your graph. In some software programs, you can also choose to show or hide specific grid lines or change the spacing between them.

Similar threads

Replies
4
Views
2K
Replies
4
Views
1K
  • Programming and Computer Science
Replies
14
Views
601
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
985
  • Precalculus Mathematics Homework Help
Replies
7
Views
866
Replies
11
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
822
Replies
13
Views
954
Back
Top