找到二维三角形的中心? [英] Finding center of 2D triangle?

查看:49
本文介绍了找到二维三角形的中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经获得了一个带有 x 和 y 坐标、旋转变量等的 2D 三角形的结构.从这些 x 和 y 坐标创建的点开始,我应该围绕该点绘制一个三角形并使用旋转变量适当地旋转它.

I've been given a struct for a 2D triangle with x and y coordinates, a rotation variable, and so on. From the point created by those x and y coordinates, I am supposed to draw a triangle around the point and rotate it appropriately using the rotation variable.

我熟悉使用 GL_TRIANGLES 在 OpenGL 中绘制三角形.我的问题是以某种方式提取三角形的中间并在其周围绘制顶点.

I'm familiar with drawing triangles in OpenGl with GL_TRIANGLES. My problem is somehow extracting the middle of a triangle and drawing the vertices around it.

是的,我正在寻找的是质心.

edit: Yes, what I am looking for is the centroid.

推荐答案

三角形的中心有不同的类型".详细信息:三角形的中心.找到三角形中心的一种快速方法是平均所有点的坐标.例如:

There are different "types" of centers of a triangle. Details on: The Centers of a Triangle. A quick method for finding a center of a triangle is to average all your point's coordinates. For example:

GLfloat centerX = (tri[0].x + tri[1].x + tri[2].x) / 3;
GLfloat centerY = (tri[0].y + tri[1].y + tri[2].y) / 3;

找到中心后,您需要围绕中心旋转三角形.为此,请平移以使中心现在位于 (0, 0).执行您的旋转.现在反转您之前执行的翻译.

When you find the center, you will need to rotate your triangle about the center. To do this, translate so that the center is now at (0, 0). Perform your rotation. Now reverse the translation you performed earlier.

这篇关于找到二维三角形的中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆