圆柱算法

发布于 2024-12-13 21:41:36 字数 329 浏览 0 评论 0原文

我正在尝试在 OpenGL 中绘制一个圆柱体。我发现了这个算法,但我无法理解它。

http://paulbourke.net/miscellaneous/sphere_圆筒/

“给定两个垂直向量 A 和 B 1可以在圆柱体的每个边缘周围创建顶点,因此,对于 4 个顶点面,顶点可能由以下给出,其中 theta2 - theta1 是确定 的某个适当的小角度。近似的粗糙度。”

我怎样才能找到A和B?我正在使用glm。 glm可以计算叉积吗?

I am trying to draw a cylinder in OpenGl. I found this algorithm but I can't make any sense of it.

http://paulbourke.net/miscellaneous/sphere_cylinder/

"Given the two perpendicular vectors A and B one can create vertices around each rim of the cylinder. So, for a 4 vertex facet the vertices might be given by the following where theta2 - theta1 is some suitably small angle that determines the roughness of the approximation."

How can I find A and B ?? I am using glm. can glm calculate cross product?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萧瑟寒风 2024-12-20 21:41:36

A 和 B 形成正交(最好是正交)笛卡尔二维坐标系的基础。将它们想象成 X 轴和 Y 轴。回想一下,圆的参数方程为

p(t) = r (X cos(t) + Y sin(t))

现在将 X 和 Y 替换为 A、B,您就得到了圆柱体圆形横截面的方程。要使其成为圆柱体,请通过垂直于 A 和 B 的矢量进行拉伸,即 C = A × B

p(s, t) = s * C + r (A cos(t) + B sin(t))

A and B form the base of a orthogonal (prefarably orthonormal), cartesian 2D coordinate system. Think of them like X and Y axes. Recall that the parametric equation for a circle is

p(t) = r (X cos(t) + Y sin(t))

Now replace X and Y with A, B, and you got the equation for the circular cross section of a cylinder. To make it a cylinder you extrude by the vector perpendicular to A and B, i.e. C = A × B

p(s, t) = s * C + r (A cos(t) + B sin(t))
帥小哥 2024-12-20 21:41:36

上面几串有答案:

创建这两个向量的方法有很多种,它们通常需要形成与圆柱轴不共线的任何向量。该向量与圆柱轴 (P2-P1) 的叉积给出了其中一个向量(例如 A),将该新向量与该轴的叉积得出了另一个向量 (B)。然后对这两个垂直向量进行归一化。

因此,让我们一步一步进行:

  1. 创建任何与圆柱轴向量不共线的向量。
  2. 求该向量与圆柱轴的叉积。叉积的结果是向量,称为向量 A。
  3. 求向量 A 与圆柱轴的叉积会得到向量 B
  4. 标准化向量 A 和 B

有关叉积的更多信息,您可以阅读 此处

There are an answer a few strings upper:

There are a number of ways of creating these two vectors, they normally require the formation of any vector that is not colinear with the cylinder axis. The cross product of that vector with the cylinder axis (P2-P1) gives one of the vectors (A say), taking the cross product of this new vector with the axis gives the other vector (B). These two perpendicular vectors are then normalised.

So lets go step by step:

  1. Create any not collinear with cylinder axis vector.
  2. Find the cross product of this vector with cylinder axis. Result of cross product is vector called vector A.
  3. Finding the cross product of vector A with cylinder axis results in vector B
  4. Normalize vetors A and B

More about cross product you can read here

苏璃陌 2024-12-20 21:41:36

是的,glm 可以构建叉积矩阵,请参阅 GLM APIglm::gtx::matrix_cross_product::matrixCross3glm::gtx::matrix_cross_product::matrixCross4)。

Yes, glm can build cross product matrices, see the GLM API (glm::gtx::matrix_cross_product::matrixCross3 and glm::gtx::matrix_cross_product::matrixCross4).

不再见 2024-12-20 21:41:36

我在 C# 中为 Unity3D 创建了一个模块,它可以按程序创建圆柱体并允许您调整其参数。您应该能够轻松转换为 C++,因为几何计算在任何地方都是相同的,我认为代码很容易理解:) 观看 视频 查看其内容并从 GitHub

I have created a module for Unity3D in C# that creates a cylinder procedurally and allows you to tweak its parameters. You should be able to easily convert to C++ as the geometry calculation is the same everywhere and I'd like to think the code is easy to understand :) Watch the video to see what it's about and download the code from GitHub.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文