Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding center of 2D triangle?

Tags:

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.

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.

like image 222
ray Avatar asked Feb 07 '09 22:02

ray


People also ask

How do you find the center of a triangle given three points?

Step 1: Identify the coordinates of each vertex. Step 2: Add all the x values from the three vertices coordinates and divide by 3. Step 3: Add all the y values from the three vertices coordinates and divide by 3. Step 4: Determine the centroid coordinate.

What is the formula to find the Centre of gravity of a triangle?

Measure the length of the side and then divide it by 2 to get the midpoint of the triangle. Mark the point as A. Find the second side length and divide it into half. If the length of the side is 14 then the midpoint of that side is 14/2 = 7.


1 Answers

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; 

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.

like image 166
strager Avatar answered Oct 04 '22 22:10

strager