I have a math problem. I have location (x,y) of point A, B, and a number (x). I want to calculate the location of point C, D. CD is perpendicular with AB and AC = AD = x.
This is the picture describe my problem:
Can anyone help me on this?
Thanks
I have a math problem. I have location (x,y) of point A, B, and a number (x). I want to calculate the location of point C, D. CD is perpendicular with AB and AC = AD = x.
This is the picture describe my problem:
Can anyone help me on this?
Thanks
You did not specify a programming language, but from your previous questions it seems that you have some experience with (Objective-)C and Core Graphics on iOS, so this would be a solution using C and Core Graphics data structures:
// Your input data:
CGPoint A = ...
CGPoint B = ...
CGFloat x = ...
// Vector from A to B:
CGPoint vecAB = CGPointMake(B.x - A.x, B.y - A.y);
// Length of that vector:
CGFloat lenAB = hypotf(vecAB.x, vecAB.y);
// Perpendicular vector, normalized to length 1:
CGPoint perp = CGPointMake(-vecAB.y/lenAB, vecAB.x/lenAB);
CGPoint C = CGPointMake(A.x + x * perp.x, A.y + x * perp.y);
CGPoint D = CGPointMake(A.x - x * perp.x, A.y - x * perp.y);
Your question is similar to How do you find a point at a given perpendicular distance from a line? . If you want further mathemetical details, you can refer: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html