piintheeye 100 Report post Posted July 16, 2011 Hello, I'm pretty new to Vector Algebra and am stumped. So I have 2 points that make a line as shown below as Given. I want to make a triangle like shown in Goal. I've been able to get the midpoint between X1,Y1 and X2,Y2 and I have the distance X3,Y3 should be from the line. So now I believe I just need to find the angle that is perpendicular to the given line and then I can solve for X3, Y3. I think I may need to use a cross product, but I'm not really sure. I might be completely off with how I'm going about this, so if there's a better way please let me know! [img]http://www.freeimagehosting.net/uploads/5ccc6e4941.png[/img] Thanks for any input, I really appreciate it! -p 0 Share this post Link to post Share on other sites
RDragon1 1205 Report post Posted July 16, 2011 Hint: the angle that's perpendicular is 90 degrees 0 Share this post Link to post Share on other sites
piintheeye 100 Report post Posted July 16, 2011 Hehe, I got that, but I'm confused about how that would look in code. I'm not sure how it would be written in code... I'm using C#. Thanks for the response! -p [quote name='RDragon1' timestamp='1310781096' post='4835863'] Hint: the angle that's perpendicular is 90 degrees [/quote] 0 Share this post Link to post Share on other sites
alvaro 21246 Report post Posted July 16, 2011 An important thing to remember about 2D vectors: You can rotate 90 degrees by swapping the coordinates and changing the sign of one of them (which one determines if the rotation is clockwise or counterclockwise). Does that get you closer to a solution? 0 Share this post Link to post Share on other sites
RDragon1 1205 Report post Posted July 16, 2011 Lets call the points P1, P2, P3 (where P1 is (x1,y1), P2 is (x2, y2), P3 is (x3, y3). Capital letters are points/vectors, lowercase are scalars. So P1 and P2 are known. You have some distance "d" from the line P1, P2 that you want to place P3 So you need to get a vector that points in the direction of P3. It happens to be 90 degrees from the original line. You can rotate 90 degrees around the origin by swapping X and Y. To rotate around an arbitrary point, subtract that point from the point you want to rotate, then rotate around the origin, then add the point back. So, to rotate A around B: C = rotate( (A-B), angle ) + B So rotate P1 90 degrees around P2: C = rotate( (P1-P2), 90 ) + P2 Now C is a point that's perpendicular to your line, starting at P2. Turn it into just a direction by subtracting P2 E = C - P2 Now E is a direction perpendicular to your line Change the length of E to "d" (your 'distance' to P3). First normalize it, that makes its length 1. Then multiply it by d, that makes its length d. D = normalize(E) * d Now add D to the midpoint between P1 and P2, and that's where your P3 is: P3 = (P1+P2) / 2 + D If I made an error here somewhere, I apologize in advance There's also some simplifying that can be done - notice that to calculate C we added P2, and then E subtracts P2 right back off of it 0 Share this post Link to post Share on other sites
piintheeye 100 Report post Posted July 17, 2011 Thanks for breaking it down. It works great! I even got the optimization in. Cheers, -p 0 Share this post Link to post Share on other sites