How to find the coordinates of the 2nd equilateral triangle in C?

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

How to calculate the third point?

thank

+5
source share
5 answers

After reading the posts (specifically vkit), I created this simple piece of code that will do the trick in one direction (remember that there are two points). Modification for another case will 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;
}
+8
source

First, you can rotate the second point 60 ° to find the location of the third point.

Something like that:

// find offset from point 1 to 2
dX = x2 - x1;
dY = y2 - y1;
//rotate and add to point 1 to find point 3
x3 = (cos(60°) * dX - sin(60°) * dY) + x1;
y3 = (sin(60°) * dX + cos(60°) * dY) + y1;
+7

A B. Bisect AB, C. AB (Y A -Y B/X A -X B), m. (-1/m) m 2. CD, sin (60) * length (AB), m 2 ( , AB). ABD - .

, , "" . , . , (, 0 ).

+4

BlueRaja :


:

, P (x1, y1) Q (x2, y2).

, tranforms .

, P . Q P 60 ( -60, ).

, , R, P - .

.

API, .. . .

, , , ; -)


BlueRaja: , .

P (x1, y1) Q (x2, y2) , (R): (x3, y3).

T - PQ.

PQR ( , )

PRT (1/2 ).

, :

2*Area = |D|

where

     | 1 x1 y1|
D =  | 1 x2 y2|
     | 1 x3 y3|

(), x3 y3.

+4
source
pc <- c((x1+x2)/2,(y1+y2)/2) #center point
ov <- c(y2-y1,x1-x2) #orthogonal vector
p3 <- pc+sqrt(3/4)*ov #The 3dr point in equilateral triangle (center point + height of triangle*orthogonal vector)
0
source

All Articles