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

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

问题描述

已为我提供了带有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天全站免登陆