Given two points what is the best possible way to generate two more points such that they form square
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | strapple | 3515 |
| 6 | tourist | 3470 |
| 7 | dXqwq | 3436 |
| 8 | Radewoosh | 3415 |
| 9 | Otomachi_Una | 3413 |
| 10 | Um_nik | 3376 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 158 |
| 2 | adamant | 152 |
| 3 | Proof_by_QED | 146 |
| 3 | Um_nik | 146 |
| 5 | Dominater069 | 144 |
| 6 | errorgorn | 141 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 9 | TheScrasse | 134 |
| Название |
|---|



Let the points be A(a,b) and B(c,d). Calculate the slope of AB. Multiply it by -1 to get the slope of a line perpendicular to AB. This slope is tan theta for the perpendicular line . Now , calculate AB distance =r, and use P(x,y)=P(a+r*cos theta,b+r*sin theta). Similarly generate the fourth vertex of the square.
Math is your friend... :)
You can take a diagonal and rotate it 90 degrees. So finally from (x1; y1) and (x2; y2) you get:
x3 = (x1 + x2 + y1 — y2) / 2; y3 = (y1 + y2 + x2 — x1) / 2
x4 = (x1 + x2 + y2 — y1) / 2; y4 = (y1 + y2 + x1 — x2) / 2
and if you have two points of one side then you can get:
x3 = x1 — y2 + y1; y3 = y1 — x1 + x2;
x4 = x2 — y2 + y1; y4 = y2 — x1 + x2;
or
x3 = x1 + y2 — y1; y3 = y1 + x1 — x2;
x4 = x2 + y2 — y1; y4 = y2 + x1 — x2;