• ### Announcements

GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Followers 0

# How do I create the equation for a curve?

## 9 posts in this topic

So if I have 3 points,like:

x                  y

z

(imagine a curve formed by them)

How do I create a quadratic for that curve,based just on the locations of those points?

0

##### Share on other sites

Are you looking for a quadratic that goes through those 3 points, or are controlled by those 3 points?

If controlled, a point p on a curve c can be found using t, where 0 < t < 1 from start to finish.

v0 = (1-t)*x + t *y

v1 = (1-t)*y + t * z

and finally:

p = (1-t)*v0 + t*v1

if you are looking for a curve that fits those 3 points, i'm not 100% sure, but I think that more than 1 curve could fit.

EDIT: I stand corrected. Essentially you create the quadratic for each point and then with those 3 equations, Solve for a,b, and c.

EDIT2: I think i feel vindicated, multivariable quadratics would allow for an infinite number of quadratics that fit those points

Edited by Burnt_Fyr
1

##### Share on other sites

We are trying to solve for the constants a,b,c so that the polynomial a+bx+cx^2 gives the appropriate points. Suppose those points are (x1,y1), (x2, y2), (x3,y3).

The typical way to solve this is by using some linear algebra (I know! linear algebra lets you solve quadratics? It's somewhat surprising but we actually know x here and so we don't need to worry about any quadratic behavior. The things were solving for are a, b, and c which are only used linearly in this equation.). If you aren't familiar with this then you'll have to solve it out entirely (and may want to either way if you're not already using a linear algebra library). What this means is that we can plug each point (x,y) into the polynomial and this gives us a constraint on the possible values of a,b,c. So we get:

a + b*x1 + c*x1^2 = y1

a + b*x2 + c*x2^2 = y2
a + b*x3 + c*x3^2 = y3

These are three equations and we have three unknowns a,b,c so it should be solvable, at least so long as the three points permit a unique solution (almost all such points do). You can now solve these three equations for a,b,c.

If you know linear algebra, then this is just solving the matrix-vector equation:

The matrix M =
| 1 x1 x1^2 |
| 2 x2 x2^2 |
| 3 x3 x3^2 |
The vector Y = {y1, y2, y3} (a column vector)
The vector X = {a,b,c} (also a column vector).
Solve M * X = Y, or X = M \ Y if you're in a language or package that support matrix math directly. Most such languages will also have built-in functions to do this sort of thing. Look for polynomial fitting or least squares (though least squares would technically be overkill).

Or, like I said, you can solve this any other way that you want, such as substitution that most people learn by
highschool algebra.

Edit:
Actually, I feel like doing that substitution out right now. Starting with the last equation:
a + b x3 + c x3^2 = y3, so a = y3 - bx3 - cx3^2
Substitute into the second equation for a:
(y3 - bx3 - cx3^2) + bx2 + cx2^2 = y2
Solve for b:
b = [ y2 - y3+ c (x3^2 - x2^2) ] / (x2 - x3)
Substitute into the first equation for b and a:
(y3 - [y2 - y3 + c ( x3^2 - x2^2) ] / (x2 - x2) - cx3^2) - [y2 - y3 + c (x3^2 - x2^2)] / (x2 - x3) x1 - cx1^2 = y1
Solve for c:
c = oh gosh I don't really feel like doing the rest of this I guess, but you get the idea. It's pretty long! So I decided to cheat and use Wolfram|Alpha to solve it for me.

This gives us some beautiful solutions:
Let C = 1/ [ (x1-x2) * (x2 - x3) * (x1 - x3) ].
a = C * [ x1*x2 * (x2-x3) * y1 - x1*x3 * (x1-x3) * y2 + x1*x2 * (x1-x2) * y3]
b = C * [-(x2 + x3) * (x2-x3) * y1 + (x1 + x3)* (x1-x3) * y2 + (x1 + x2) * (x1 - x2) * y3]
c = C * [ (x2 - x3) * y1 - (x1 - x3) * y2 + (x1 - x2) * y3 ]
Gives us the coefficients!
Edited by Ezbez
0

##### Share on other sites

Sorry guys,right now i'm in the middle of quadratics,so I might've explained this wrongly.

How do I make an equation for a curve,so i can input points in it and then it will create points for that line.

Imagine I start at x,then advance a little,advance a little untill i reach z,then do the same again,till i reach y.

(Imagine i have a car and i start at x,and i also know 3 points on that curve,so i need to get at the end,but in order to advance,i have to advance a little bit each time till i reach the next point)

Edited by noatom
0

.

Edited by DT....
1

##### Share on other sites

Sorry guys,right now i'm in the middle of quadratics,so I might've explained this wrongly.

How do I make an equation for a curve,so i can input points in it and then it will create points for that line.

Imagine I start at x,then advance a little,advance a little untill i reach z,then do the same again,till i reach y.

(Imagine i have a car and i start at x,and i also know 3 points on that curve,so i need to get at the end,but in order to advance,i have to advance a little bit each time till i reach the next point)

Are you looking for x and y coords from distance, d, traveled along the curve? (arc length)

0

##### Share on other sites

Three points is a good starting example.

A regular circle of the right diameter will pass through any three points.

Finding the radius point with compass and ruler is easy enough.

Anyone good at triangle formula?

0

##### Share on other sites

If I remember correctly, Hermite curves are the simplest ones that go through all the points. It sounds like these might fit your requirements.

http://en.wikipedia.org/wiki/Hermite_curve

1

##### Share on other sites

Quadratic Bezier curves are very simple to do with 3 points. The equation of the curve would be $$C(t) = P_0(1-t)^2 + 2P_1t(1-t)+P_2t^2$$ and you vary t from 0 to 1 to get the whole curve. You can design the curve to pass through your middle point, so you'll have to find the second control point. You can use the Hermite spline formulation to get that second control point.

0

##### Share on other sites

You have to be a little bit more precise in asking your question. Here are a few things you might be asking:

* Given three points (x1,y1), (x2,y2), (x3,y3) , where the `x's are all different, find a formula of the form y = A + B*x + C*x^2 that is satisfied by all three points.

* Given three points (x1,y1), (x2,y2), (x3,y3), find a formula like A + B*x + C*y + D*x^2 + E*x*y + F*y^2 = 0 that is satisfied by all three points.

* Given three points (x1,y1), (x2,y2), (x3,y3), find a parametric curve (A + B*t + C*t^2, D + E*t + F*t^2) that passes through all three points.

These are quite different problems, and "create a quadratic for that curve" could mean any of those (and perhaps more) things.

0

## Create an account

Register a new account