colors - 使用一组 2D 点进行颜色插值
问题描述
我正在尝试对表面上的光弹性物理问题进行建模。我成功地获得了一个 X,Y 数组 - 表面的坐标,并且对于每个点,我都有一个 RGB 格式的相应颜色。我使用 Python scatter 进行绘图,结果已经很好,但是由于缺乏我无法改进的分辨率,仍然存在一些不连续性:( 我只是想问一下如何以连续的方式生成相同的曲面图(使用新的“中间”点,它们的颜色已经相对于邻域点进行了插值)。我不一定要在 python 中编码,欢迎每个软件。谢谢!
解决方案
我用javascript写了这个:https ://jsfiddle.net/87nw05kz/
重要的部分是计算颜色。它找到被着色的像素到每种颜色的距离的平方反比,并使用它来确定每种颜色应影响该像素的程度。
function calculateColor(x, y) {
let total = 0;
for (let i = 0; i < colors.length; i++) {
let c = colors[i];
let d = distance(c.x, c.y, x, y);
if (d === 0) {
return c;
}
d = 1 / (d * d);
c.d = d;
total += d;
}
let r = 0, g = 0, b = 0;
for (let i = 0; i < colors.length; i++) {
let c = colors[i];
let ratio = c.d / total;
r += ratio * c.r;
g += ratio * c.g;
b += ratio * c.b;
}
r = Math.floor(r);
g = Math.floor(g);
b = Math.floor(b);
return {r:r,g:g,b:b};
}
推荐阅读
- for-loop - 使用循环组合命令
- hyperledger-fabric - ChainCode 容器生命周期说明
- c - 根据用户输入更改#define 值
- xml - 如何为文件指定默认命名空间并指定 sites.xsd 作为默认命名空间的架构位置?
- selenium - xpath 检索名称/文本
- php - PHP 日期比较给出了意想不到的结果
- php - 带有 php 的 aws elasticache - 无法设置键/值对
- android - 导航架构组件测试应用在 Android 8.0.0 手机上运行良好,但在 Android 6.01 上失败
- tpm - 如何使用 TPM2 签署消息?
- c++ - 如何移动小数并显示特定数字?C++