Click here to Skip to main content
15,888,330 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: How to find 3rd coordinate of a triangle given 2 others Pin
Arash Partow17-Oct-08 18:05
Arash Partow17-Oct-08 18:05 
AnswerRe: How to find 3rd coordinate of a triangle given 2 others Pin
Chesnokov Yuriy17-Oct-08 20:55
professionalChesnokov Yuriy17-Oct-08 20:55 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
Arash Partow18-Oct-08 4:31
Arash Partow18-Oct-08 4:31 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
Member 419459318-Oct-08 7:11
Member 419459318-Oct-08 7:11 
AnswerRe: How to find 3rd coordinate of a triangle given 2 others Pin
cp987618-Oct-08 17:32
cp987618-Oct-08 17:32 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
cp987618-Oct-08 23:38
cp987618-Oct-08 23:38 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
Arash Partow19-Oct-08 6:32
Arash Partow19-Oct-08 6:32 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
cp987619-Oct-08 11:42
cp987619-Oct-08 11:42 
Arash Partow wrote:
I'm not sure what you're on about, but the simplest solution to the problem is to assume a square,
from that you get:

c_1,2 = mid(AB) +/- (perp(A-B) * |AB|/ 2)

code:


template<typename t="">void generate_right_triangle(const wykobi::point2d<t>& a, const wykobi::point2d<t>& b, wykobi::point2d<t>& c1, wykobi::point2d<t>& c2){ T distance = wykobi::distance(a,b); wykobi::point2d<t> mid = wykobi::segment_mid_point(a,b); wykobi::vector2d<t> v = wykobi::normalize(wykobi::perpendicular(a - b)) * (distance / T(2.0)); c1 = mid + v; c2 = mid - v;}


But what if AC != BC? My simple solution solves this case and does not need wykobi.

All I did was solve for the triangle with A at (0,0) and with AB along the x-axis. The equations solve easily for C, then all you ahve to do is a rotation (using the vector AB) then translate to place A in the correct position. The general problem is done with 4 lines of code and no wykobi:

Input: (xa, ya), (xb, yb) and length of BC = a,  to find (xc,yc) st angle(acb) = 90 
c = sqrt((xb-xa)^2+(yb-ya)^2)
b = sqrt(c^2-a^2)
xc = xa + (b * (xb-xa) - a*(yb-ya))*b/c^2
yc = ya + (b * (yb-ya) + a*(xb-xa))*b/c^2

for the other solution change the sign of 'a' in the last two equations

BTW - It's a pity people 1-vote solutions they don't understand.

Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
CPallini19-Oct-08 11:52
mveCPallini19-Oct-08 11:52 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
Arash Partow19-Oct-08 11:56
Arash Partow19-Oct-08 11:56 
AnswerRe: How to find 3rd coordinate of a triangle given 2 others Pin
darrellp28-Nov-08 20:03
darrellp28-Nov-08 20:03 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
cp987629-Nov-08 14:03
cp987629-Nov-08 14:03 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
darrellp29-Nov-08 14:48
darrellp29-Nov-08 14:48 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
cp987629-Nov-08 15:20
cp987629-Nov-08 15:20 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
darrellp29-Nov-08 19:58
darrellp29-Nov-08 19:58 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
cp987629-Nov-08 23:06
cp987629-Nov-08 23:06 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
darrellp30-Nov-08 7:17
darrellp30-Nov-08 7:17 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
cp98761-Dec-08 15:11
cp98761-Dec-08 15:11 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
darrellp1-Dec-08 17:19
darrellp1-Dec-08 17:19 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
darrellp1-Dec-08 19:27
darrellp1-Dec-08 19:27 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
cp98762-Dec-08 19:54
cp98762-Dec-08 19:54 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
Member 41945933-Dec-08 3:27
Member 41945933-Dec-08 3:27 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
cp98763-Dec-08 10:19
cp98763-Dec-08 10:19 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
Member 41945933-Dec-08 10:58
Member 41945933-Dec-08 10:58 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
cp98763-Dec-08 13:04
cp98763-Dec-08 13:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.