0
votes

So I am drawing a graph with lineTo.

What I want to do is loop through every x coordinate on the lineTo get its Y coordinate and push that to an array, but how do I know what the Y coordinate is at each X coordinate?

2
Do you want to know the y values between two x points? Is it something like drawing a graph in your exercise book and reading the value at a certain x? In other words, are you asking how to interpolate the values between the given points, which were used to draw the graph? - anemgyenge
I dont want to say Yes incase I misunderstood you, ill try and explain it simply. I have a lineTo function, I want to take the starting X point of the lineTo and the finishing X point of the lineTo and loop through every X value inbetween and get its corresponding Y value (where the line on the Y value at X) and then push that Y value to an array. - George Reith

2 Answers

0
votes
var lineStartX=10;
var lineStartY=10;
var lineEndX=450;
var lineEndY=300;
this.lineStyle(5, 0xFF00FF, 100);
this.moveTo(lineStartX, lineStartY);
this.lineTo(lineEndX, lineEndY);

var ratio=(lineEndY-lineStartY)/(lineEndX-lineStartX);
for (var yV:Number=0; yV<=lineEndY-lineStartY; yV+=5) {
 var xV=yV/ratio+lineStartX;

 //Vizualize// 
 this.lineStyle(2, 0xFFF0F0, 100);
 this.moveTo(xV, yV+lineStartY);
 this.lineTo(xV+1, yV+lineStartY+1);
}

for (var xV:Number=0; xV<=lineEndX-lineStartX; xV+=5) {
 var yV=xV*ratio+lineStartY;
}
0
votes

You might have more success putting each point into an array first, and then iterating through the array to draw the lines. This way, if you want to know any specific coordinate, it will be referenced in the array.