three.js - 在 Threejs 中找到网格上最接近其他点的点?
问题描述
你好 StackOverflow 社区!我的场景中有一个点漂浮在周围,还有一组复杂的网格。我需要在这些网格中的任何一个上找到离原始点最近的点。我想我可以用 SphereCast 之类的东西来做到这一点,但我在 Threejs 文档中没有找到任何东西。
这是我需要做的2D表示:
基本上,我有 P1 和一组中的所有其他表面,我需要找到 P2。
谢谢!
解决方案
实际上,您似乎想重现光线投射中实现的内容。但我认为这取决于您在示例中考虑的形状,因为您需要表面方程来获得解析解。
我找到了基本形状(球体、三角形等)的光线投射的这个例子,但是没有形状的方程就没有一般的解决方案。例如,对于射线-球体相交,它们给出以下 C++ :
{
float t0, t1; // solutions for t if the ray intersects
#if 0
// geometric solution
Vec3f L = center - orig;
float tca = L.dotProduct(dir);
// if (tca < 0) return false;
float d2 = L.dotProduct(L) - tca * tca;
if (d2 > radius2) return false;
float thc = sqrt(radius2 - d2);
t0 = tca - thc;
t1 = tca + thc;
#else
// analytic solution
Vec3f L = orig - center;
float a = dir.dotProduct(dir);
float b = 2 * dir.dotProduct(L);
float c = L.dotProduct(L) - radius2;
if (!solveQuadratic(a, b, c, t0, t1)) return false;
#endif
if (t0 > t1) std::swap(t0, t1);
if (t0 < 0) {
t0 = t1; // if t0 is negative, let's use t1 instead
if (t0 < 0) return false; // both t0 and t1 are negative
}
t = t0;
return true;
}
我认为在 Three.js 中,因为大多数材质都是由小三角形组成的,所以每个光线投射演算都依赖于三角形光线投射。
推荐阅读
- android-layout - 根据某些条件使用字符串文件更改片段或活动中的视图标签
- scala - Scala Seq GroupBy 与 Future
- python - 从 Azure 服务器使用 python 脚本发送电子邮件
- android - 如何获取依赖项的本地缓存文件路径
- react-native - google-translate-api 在 react-native 中给出错误
- python - 替换 NaN 返回 ValueError: 条件数组必须与自身形状相同
- android - 在kotlin中对包含数字的字符串进行排序
- normalizr - 反规范化逆向处理策略
- dart - 错误:未定义的类“LocaleListResolutionCallback”。(PROJECT_NAME 的 undefined_class] lib/generated/i18n.dart:36)
- ios - 某些应用内购买未列出并显示“此应用内购买已被购买”