【问题标题】:(processing) why is `curveVertex` skipping points?(处理)为什么`curveVertex`会跳过点?
【发布时间】:2020-06-26 23:05:13
【问题描述】:

我正在使用处理 3.5.3,我正在使用 beginShapecurveVertexendShape 绘制曲线。我的窗口是 1200 像素宽,我正在绘制一系列具有均匀间隔 x 值的点。 x 值之间的间距为 1200/2000,小于一个像素。我知道,这是对curveVertex 的严重滥用,但它确实有效。每一帧都需要十秒钟的时间来渲染(因为我使用的数学,而不是因为处理),我将每一帧保存为.png

问题是我在应该有曲线的地方得到了这些直线补丁。看起来大范围的 x 值被跳过了。我知道它会跳过多个顶点,因为直接的补丁跨越多个 x 像素,最坏的情况可能是五十个左右。大多数帧都很好,但是会有一个帧丢失了巨大的补丁。知道是什么原因造成的吗?

编辑:这是代码和一些显示问题的框架。最相关的部分在draw()

float r; // parameter for recurence
float dr; // change in r per frame
int lod = 2000; // level of detail for curves
int k; // recurrence depth
float yscale = 16; // scale down the y-axis by this factor

// transforms from [0, 1] to screen coordinates
void vertex(float x, float y) {
  curveVertex(x * width, (1 - y) * height);
}

void setup() {
  size(1200, 800);
  background(0);
  stroke(255);
  noFill();
  r = 3.7;
  k = 30;
  dr = 0.0005;
}

void draw() {
  background(0);
  
  // animate r
  r += dr;
  if (r >= 4) {
    exit();
  }
  
  // draw the pdf of Xk
  stroke(255);
  beginShape();
  vertex(0, fn(0, k) / yscale);
  for (int i = 0; i <= lod; i++) {
    float x = i / (float)lod;
    vertex(x, fn(x, k) / yscale);
  }
  vertex(1, fn(1, k) / yscale);
  endShape();
  
  textSize(24);
  text(String.format("r = %.4f", r), 24, 24);
  
  saveFrame("output/frame_#####.png");
}

// pdf of Xn+1 = r*Xn*(1-Xn), where X0 is uniform
float fn(float x, int n) {
  if (n == 0) {
    return 1;
  }
  else if (x > r/4) {
    return 0;
  }
  else {
    float d = sqrt(1 - 4/r*x);
    return (fn(0.5 + 0.5*d, n-1) + fn(0.5 - 0.5*d, n-1)) / (r*d);
  }
}

这是一个特别糟糕的框架:

【问题讨论】:

  • 邮政编码和图片输出。
  • @micycle 已发布,谢谢

标签: processing curve


【解决方案1】:

我将您的代码转换为渲染为 PShape,然后遍历 PShape 的顶点以确定顶点本身是否存在(并且没有被连接),或者它们是否完全丢失:

绿色的顶点——它们在部分中丢失。

PShape 中的curveVertex() 仅在P2D 渲染器模式下工作。有趣的是,在这种模式下(与默认的JAVA2D 渲染器相比)之前的直线部分不存在...

...这使我查看了给定顶点的值:我尝试将它们限制在屏幕的尺寸上:

通过改变这个:

curveVertex(x * width, (1 - y) * height);

进入这个:

curveVertex(constrain(x * width, 0, width), constrain((1 - y) * height, 0, height));

现在我们开始明白发生了什么:

受约束@r = 3.7055:

不受约束@r = 3.7055:

判决

方程为某些坐标点提供了非常大的值,而处理或曲线算法本身正在跳过它们。一旦将值限制到更合理的水平,直线部分就会消失,每个点都会连接起来。

【讨论】:

  • 谢谢,我现在觉得有点傻,我应该能够弄清楚这一点。感谢您投入所有工作。
猜你喜欢
  • 2020-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-13
  • 1970-01-01
  • 1970-01-01
  • 2010-11-15
  • 2017-11-10
相关资源
最近更新 更多