![]() |
|
Geometry - how to find points on line perpendicular/parallel to given line? |
spacepionier
Member #11,917
May 2010
|
I'm having trouble sorting a simple concept for some reason. known: I was trying first to calculate point M from the distance equation unfortunately with no luck. Could you please help me and post a code in any programming language ( I will try to convert it to C# or VB.net then) or give me some hints or links where I could read about the soultion and refresh my highschool math Thank you in Advance! |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
I'm sure there easier ways to do this, but I would probably use sin,cos and atan2; EDIT: Obviously there are better solutions below
|
Evert
Member #794
November 2000
![]() |
Probably the easiest way to do this is to follow the Gram-Schmidt process. EDIT: oh, looks like this is 2D? In that case it's much easier to find a vector that is perpendicular to the direction vector you already have. Those two vectors then span the space and if you express your coordinates with respect to those vectors you should be good. EDIT2: Basically, what SiegeLord said below. |
verthex
Member #11,340
September 2009
![]() |
1
2float Ax, Ay, Bx, By,cXm,cYm,Lx, Ly, Mx, My, Nx, Ny, d;
3float greenx, greeny;// I think these two have to be given theres no other way to find L or N
4
5cXm = (AX - Bx)/2;
6cym = given;
7
8Mx = cXm;
9My = cym + d;
10
11Lx = Mx;
12Ly = My + greeny;
13
14Nx = cXm - x;
15Ny = d;
|
SiegeLord
Member #7,827
October 2006
![]() |
First, you need to calculate the unit vector perpendicular to the segment AB. You do that by simply rotating the AB vector by 90 degrees (look up 2D rotation matrices on Wikipedia). In short, the vector that points in the direction cL (and cM) is (y2 - y1, x1 - x2). To get the point M, then, you just normalize that vector, multiply it by d and add it to the point c. See how that works out for you... if you can't follow that I suggest brushing up on your basic linear algebra "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
gnolam
Member #2,030
March 2002
![]() |
Pfft. Trig functions are completely unnecessary. [EDIT] -- |
SiegeLord
Member #7,827
October 2006
![]() |
Way to go, everyone, for making the OP work for his answer "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
Woo, I actually learned something
|
Evert
Member #794
November 2000
![]() |
SiegeLord said: Way to go, everyone, for making the OP work for his answer
Well, he did ask for code or hints. Guess which one of those is easier to give. |
spacepionier
Member #11,917
May 2010
|
Thank you very much for quick reply.. Yes, it would be good to get a code sample but looking on all replies I will have to find my old Linear Algebra book gnolam: Would you mind to give some descripion to attached equations? SiegeLord: will I be able to find coordinates of those M,L,N points using method you suggested? I found a similar post on the forum Could you please guys point the links from where I could try to sort out this issue ? some theory. Thanks very much again for all replies! |
gnolam
Member #2,030
March 2002
![]() |
u: the vector from A to B. Hats denote unit vectors. -- |
spacepionier
Member #11,917
May 2010
|
Finally got it Thank you all for the input! ----------------------------------------------------------------------------------- EDIT: Just one quick question..I have all equations in place and my local axes are always parpendicular/parallel to the element, but depending on how I draw element - from left to right or from right to left I am getting axes above or below element. would it be possible to ammend those equations so that my local axes would be always above element and y axis would be always pointing upwards and x axis would be pointing in the same direction as element ie if element is drawn from right to left my X axis would go from 0,0 (local) to the left. I have attached a screen shot from my excel calculation with graph showing local axes below element because of the direction of element (from right to left) I am sorry for edit but culd not reply.. Thank you in advance. ---------------------------------------------------------------------------------- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Good to hear you got it fixed. And edits are ok here so long as you have a good excuse. -- |
|