圆柱算法
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
A 和 B 形成正交(最好是正交)笛卡尔二维坐标系的基础。将它们想象成 X 轴和 Y 轴。回想一下,圆的参数方程为
现在将 X 和 Y 替换为 A、B,您就得到了圆柱体圆形横截面的方程。要使其成为圆柱体,请通过垂直于 A 和 B 的矢量进行拉伸,即 C = A × B
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
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
上面几串有答案:
因此,让我们一步一步进行:
有关叉积的更多信息,您可以阅读 此处
There are an answer a few strings upper:
So lets go step by step:
More about cross product you can read here
是的,glm 可以构建叉积矩阵,请参阅 GLM API (
glm::gtx::matrix_cross_product::matrixCross3
和glm::gtx::matrix_cross_product::matrixCross4
)。Yes, glm can build cross product matrices, see the GLM API (
glm::gtx::matrix_cross_product::matrixCross3
andglm::gtx::matrix_cross_product::matrixCross4
).我在 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.