2D三角形发现中心 [英] finding center of 2D triangle

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

问题描述

(是的,不幸的是,这是一门功课的问题)

(Yes, unfortunately, this is a homework question)

我已经给出用于与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.

我熟悉OpenGL绘图三角形与GL_TRIANGLES。我的问题是某种提取一个三角形的中间和绘图它周围的顶点。

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.

我希望我已经正确的措辞这一点,因为我有点糊涂了。

I hope I've worded this properly, as I'm a little confused.

感谢。

编辑:是的,我所寻找的是质心

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

推荐答案

有不同的三角形的中心类型。 三角形的中心<:上详细/ A>。查找三角形的中心快速的方法是平均所有点的坐标。例如:

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.

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

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