0
所以我有這樣的代碼,其從陣列獲取數據,並繪製曲線:如何查找曲線上的點並顯示它們?
void drawDataLine(int row) {
beginShape();
for (int col = 0; col < colCount; col++) {
if (data.isValid(row, col)) {
float value = data.getPoint(row, col);
float x = map(years[col], yearMin, yearMax, plotX1, plotX2);
float y = map(value, dataMin, dataMax, plotY2, plotY1);
//vertex(x,y) ;
curveVertex(x, y);
// Double the curve points for the start and stop
if ((col == 0) || (col == colCount-1)) {
curveVertex(x, y);
}
}
}
endShape();
}
我有當光標內3個像素的點的,其顯示數據值的另一個函數:
for (int col = 0; col < colCount; col++) {
if (data.isValid(row, col)) {
float radVal = ratio[col];
float value = data.getPoint(row, col);
float compareValue = compare.getPoint(row, col);
float x = map(years[col], yearMin, yearMax, plotX1, plotX2);
float y = map(value, dataMin, dataMax, plotY2, plotY1);
float ellipse1MapVal = map(value, ellipse1Min, ellipse1Max, 10, 80);
float ellipse2MapVal = map(compareValue, ellipse1Min, ellipse1Max, 10, 80);
radVal = map(radVal, radMin, radMax, 1, 7);
if (dist(mouseX, mouseY, x, y) < 3) {
if (drawCirclesPrimary || drawCirclesSecondary) {
noStroke();
if (drawCirclesPrimary) {
fill(0, 255, 0, 100);
ellipse(x, y, ellipse1MapVal, ellipse1MapVal);
}
if (drawCirclesSecondary) {
fill(255, 0, 0, 100);
ellipse(x, y, ellipse2MapVal, ellipse2MapVal);
}
fill(0);
stroke(0);
pushMatrix();
translate(x, y);
rotate(radians(radSec));
line(0, -ellipse1MapVal/2, 0, ellipse1MapVal/2);
popMatrix();
radSec += radVal;
textSize(10);
textAlign(CENTER);
text(nf(value, 0, 2) + " (" + years[col] + ")"+nf(compareValue, 0, 2), x, y-8);
}
else
text(nf(value, 0, 2) + " (" + years[col] + ")", x, y-8);
}
if ((mouseX < x+3)&&(mouseX > x-3))
{
stroke(150);
strokeWeight(1);
line(x, plotY1, x, plotY2);
} } }}
現在的問題是,curveVertex做它的插值,並做出很好的曲線,但我不能得到除我已經有的曲線以外的曲線上的點。我想要的是光標顯示圖上所有點上的值,而不是我在數組上的10個點,就像谷歌或雅虎財經上的圖表一樣。當談到處理時,我是一個noob,因此任何幫助都將不勝感激。
問候