首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在CGAL中计算直线上的点

如何在CGAL中计算直线上的点
EN

Stack Overflow用户
提问于 2010-08-17 18:26:24
回答 1查看 974关注 0票数 6

给定CGAL中的一条3D线,如何计算该线上的一个点,即距离端点的已知距离?

EN

回答 1

Stack Overflow用户

发布于 2022-08-05 20:37:07

你只需减去你感兴趣的点,得到一个斜率向量,然后沿着它走。A MWE如下:

代码语言:javascript
复制
// Compile with: clang++ -DBOOST_ALL_NO_LIB -DCGAL_USE_GMPXX=1 -O2 -g -DNDEBUG -Wall -Wextra -pedantic -march=native -frounding-math main.cpp -lgmpxx -lmpfr -lgmp

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>

using K = CGAL::Exact_predicates_exact_constructions_kernel;
using Point_3 = K::Point_3;

class InterPointInterpolator {
 public:
  InterPointInterpolator(const Point_3 &a, const Point_3 &b) : a(a), b(b) {}
  // Returns points interpolated from a at t=0 to b at t=1
  Point_3 operator()(const double t) const {
    const auto m = b - a;
    return a + t * m;
  }
 private:
  Point_3 a;
  Point_3 b;
};

int main(){
  InterPointInterpolator ipi(Point_3(0, 0, 0), Point_3(10, 5, 20));
  for(int i=0;i<=10;i++){
    const auto interpolated_point = ipi(i/10.0);
    std::cout<<interpolated_point<<std::endl;
  }

  return 0;
}

输出:

代码语言:javascript
复制
0  0   0
1  0.5 2
2  1   4
3  1.5 6
4  2   8
5  2.5 10
6  3   12
7  3.5 14
8  4   16
9  4.5 18
10 5   20
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3505668

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档