Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find coordinates of a 2d equilateral triangle in C?

I have the coordinates (x,y) of 2 points. I want to build the third point so that these 3 points make an equilateral triangle.

How can I calculate the third point?

Thank you

like image 808
Horatiu Jeflea Avatar asked May 18 '10 23:05

Horatiu Jeflea


People also ask

How do you find the coordinates of an equilateral triangle?

If the triangle were equilateral then 2|AO| = |AC|. Since \triangle AOC is a right triangle, the Pythagorean Theorem says that |OC|^2 + |AO|^2 = |AC|^2.

How do you find the missing vertex of an equilateral triangle?

question_answer Answers(2) Substituting the value of y in equation (1) and equating it to 26. Solving the quadratic equation using the quadratic formula, [-b ± √(b2 - 4ac)]/2a. Hence, the coordinates of the third vertex of the equilateral triangle are ([1 ± √(3)] / 2, [7 ± 5√(3)] / 2). Answer.

How do you find the point C on a triangle?

Hypotenuse calculator The hypotenuse is opposite the right angle and can be solved by using the Pythagorean theorem. In a right triangle with cathetus a and b and with hypotenuse c , Pythagoras' theorem states that: a² + b² = c² . To solve for c , take the square root of both sides to get c = √(b²+a²) .

How do you determine if a point is in a 2d triangle?

A simple way is to: find the vectors connecting the point to each of the triangle's three vertices and sum the angles between those vectors. If the sum of the angles is 2*pi then the point is inside the triangle.


1 Answers

After reading the posts (specially vkit's) I produced this simple piece of code which will do the trick for one direction (remember that there are two points). The modification for the other case shold be trivial.

#include<stdio.h>
#include<math.h>

typedef struct{
  double x;
  double y;
} Point;

Point vertex(Point p1, Point p2){
  double s60 = sin(60 * M_PI / 180.0);    
  double c60 = cos(60 * M_PI / 180.0);

  Point v = {
    c60 * (p1.x - p2.x) - s60 * (p1.y - p2.y) + p2.x,
    s60 * (p1.x - p2.x) + c60 * (p1.y - p2.y) + p2.y
  };

  return v;
}
like image 137
Escualo Avatar answered Oct 14 '22 20:10

Escualo