【问题标题】:Finding the intersection of a ray and a plane programmatically?以编程方式查找射线和平面的交点?
【发布时间】:2021-09-20 16:12:34
【问题描述】:

我理解这里的数学:http://lousodrome.net/blog/light/2020/07/03/intersection-of-a-ray-and-a-plane/

这是我对他的方程式的实现:

    Vector3 difference = plane_point - ray_origin;
    double product_1 = difference.dot(plane_normal);
    double product_2 = ray_direction.dot(plane_normal);
    double distance_from_origin_to_plane = product_1 / product_2;
    Vector3 intersection = ray_origin - ray_direction * distance_from_origin_to_plane;

但是,除非我将第一行更改为:

Vector3 difference = ray_origin - plane_point;

但我不知道为什么会这样。他的数学很合理。工作代码没有意义。

谁能解释这是怎么回事?

【问题讨论】:

  • 可以在标签中添加语言吗?
  • 不应该 ray_origin - plane_point;绝对功能?
  • intersection = ray_origin - ray_direction * distance_from_origin_to_plane; 听起来不正确,假设变量名称都是正确的。 (应该是+
  • 您确定代码中所有轴的符号都与示例中的相同吗?或者您的代码中的所有标志都在正确的位置?我感觉有什么不对劲

标签: c++ vector


【解决方案1】:

apple apple 在 cmets 中回答了它。最后一行应该是 + 而不是 -。

现在有意义的工作代码是:

    Vector3 difference = plane_point - ray_origin;
    double product_1 = difference.dot(plane_normal);
    double product_2 = ray_direction.dot(plane_normal);
    double distance_from_origin_to_plane = product_1 / product_2;
    Vector3 intersection = ray_origin + ray_direction * distance_from_origin_to_plane;

【讨论】:

    猜你喜欢
    • 2014-06-04
    • 1970-01-01
    • 2023-04-02
    • 2012-09-26
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    相关资源
    最近更新 更多