Plotting curves

Hi there, can anybody here help me figure out how to plot curves in Unity, a little bit like a scientific calculator does? Is this even possible?

Thanks!
Caitlyn

It shouldn’t be too difficult to do a basic version of it, but it depends a lot on what exactly you need to do. the basic version would simply be to loop through a range of x-values, process the function, and set a vertex of a line at that point. The code could look something like:

var range : float = 10.0;
var step : float = 0.1;

function Start() {
var lr: LineRenderer = gameObject.AddComponent(LineRenderer);
lr.SetVertexCount(range / step);
var thisIndex:int=0;
for (x=0.0;x<range;x+=step) {
var y : float = x*x - 2*x + 5; //your function here
lr.SetPoint(thisIndex, Vector3(x,y,0));
thisIndex++;
}
}

Do you need the user to be able to type in the equation or can it be hardcoded into the script? Reading in equations is very hard, but a compiled script is a piece of cake.

Do you need it to properly graph functions where there’s more than one y-value for a given x-value? (e.g. circle functions, etc)

Sweet! I was just wondering about this myself. I figured this would be the general way to do it, but I had no idea how to code it. Thanks!