我正在尝试在3d曲线的每个点周围绘制圆圈。基本上尝试为曲线创建管状结构。但是如图所示,圆的方向是错误的。下面是我在计算frenet框架后对圆对象的Model矩阵的计算。我要去哪里错了?
作为引用,绿线是切线,蓝色是法线,红色是双法线。
Frenet Frame Calculations
:
glm::vec3 pointback = curve_points[i-1];
glm::vec3 pointmid = curve_points[i];
glm::vec3 pointforward = curve_points[i+1];
glm::vec3 forward_tangent_vector = glm::vec3(glm::normalize(pointforward - pointmid)) ;
glm::vec3 backward_tangent_vector = glm::vec3(glm::normalize(pointmid - pointback)) ;
glm::vec3 second_order_tangent = glm::normalize(forward_tangent_vector - backward_tangent_vector);
glm::vec3 binormal = glm::normalize(glm::cross(forward_tangent_vector, second_order_tangent));
glm::vec3 normal = glm::normalize(glm::cross(binormal, forward_tangent_vector));
Model Matrix for Circle calculations
glm::mat3 tbn = glm::mat3(forward_tangent_vector,binormal,normal);
glm::vec3 normal_axis = glm::vec3(0, 1, 0);
//normal_axis = forward_tangent_vector;
glm::vec3 circleNormal = glm::normalize(tbn * normal_axis);
glm::vec3 rotationAxis = glm::cross(normal_axis, circleNormal);
float rotationAngle = glm::acos(glm::dot(normal_axis, circleNormal));
R = glm::rotate(R, glm::degrees(rotationAngle), rotationAxis);
T = glm::translate(T, pointmid);
glm::mat4 Model = T*R;
最佳答案
最简单的方法是使用Frenet-Serret帧,通常称为TBN帧或TBN矩阵。就是这样:
vec3 T = normalize( next - current );
vec3 B = normalize( cross( T, next + current ) );
vec3 N = normalize( cross( B, T ) );
float x = cos( angle );
float y = sin( angle );
vec3 tangent = T;
vec3 normal = normalize( B * x + N * y );
vec3 vertex = current + B * x + N * y; // note: not normalized!
一个易于理解的解释可以在这里找到:
http://www.blackpawn.com/texts/pqtorus/