| 
 | 
     
    
    
    
     
    
    
    
 
    
    
 
    
     
    
    
    
     
    
    
    
     
    
    
    
 
    
    
 
    
    
 | 
       | 
      
 
 
	
	
	
	
	
	
	
	
		  | 
	
	 | 
 
 
		
	
	
	
		
	
	
	
		
		
		
			
			 
			
				November 26th, 2004, 08:56 PM
			
			
			
		  
	 | 
 
	
		
		
		
			  | 
			
 
  
			
				
				
				Shrapnel Fanatic 
				
				
				
			 | 
			  | 
			
				
				
					Join Date: Mar 2003 
					Location: CHEESE! 
					
					
						Posts: 10,009
					 
					 
	Thanks: 0 
	
		
			
				Thanked 7 Times in 1 Post
			
		
	 
					
					
					
					     
				 
				
			 | 
		 
		 
		
	 | 
 
    
	
     
	
	
		
		
		
			
			
				 
				OT: 2D/3D math
	
			 
             
			
		
		
		
		Anyone know how to determine the closest point on a line to a point? Rapidly running out of ideas... 
 
Thanks. 
		
	
		
		
		
		
		
		
			
				__________________ 
				If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!  
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++ 
  Some of my webcomics. I've got 400+ webcomics at Last count, some dead. 
Sig updated to remove non-working links.
			  
		
		
		
		
		
		
	
		
		
	
	
	 | 
 
 
 
	 
	
		 
	 
 
	
	
		
	
	
	
		
		
		
			
			 
			
				November 26th, 2004, 10:10 PM
			
			
			
		  
	 | 
 
	
		
		
		
			  | 
			
 
  
			
				
				
				Major 
				
				
				
			 | 
			  | 
			
				
				
					Join Date: Jan 2004 
					Location: Taganrog, Russia 
					
					
						Posts: 1,087
					 
					 
	Thanks: 0 
	
		
			
				Thanked 0 Times in 0 Posts
			
		
	 
					
					
					
					     
				 
				
			 | 
		 
		 
		
	 | 
 
    
	
     
	
	
		
		
		
			
			
				 
				Re: OT: 2D/3D math
			 
             
			
		
		
		
		crossing of perpendicular from this point with a line itself? 
		
	
		
		
		
		
		
		
		
		
		
	
		
		
	
	
	 | 
 
 
 
	 
	
		 
	 
 
	
	
		
	
	
	
		
		
		
			
			 
			
				November 26th, 2004, 10:15 PM
			
			
			
		  
	 | 
 
	
		
		
		
			  | 
			
 
  
			
				
				
				Brigadier General 
				
				
				
			 | 
			  | 
			
				
				
					Join Date: Apr 2002 
					Location: Kailua, Hawaii 
					
					
						Posts: 1,860
					 
					 
	Thanks: 0 
	
		
			Thanked 1 Time in 1 Post
		
	 
					
					
					
					     
				 
				
			 | 
		 
		 
		
	 | 
 
    
	
     
	
	
		
		
		
			
			
				 
				Re: OT: 2D/3D math
			 
             
			
		
		
		
		yeah for 2D: 
line: Ax + By + C = 0 
Point: (x1, y1)
 
[saving you the gory details]
 Code:
  
 
                                      |Ax1 + By1 + C| 
distance between point and line: D = ----------------- 
                                     square root (A^2 + B^2) 
 
 
 
notation:  | | is absoute value, ^2 is raised to power 2
 
For 3D, it takes a little more...
 
Slick.  
		
	
		
		
		
		
		
		
			
				__________________ 
				Slick.
			 
		
		
		
		
		
		
	
		
		
	
	
	 | 
 
 
 
	 
	
		 
	 
 
	
	
		
	
	
	
		
		
		
			
			 
			
				November 26th, 2004, 11:03 PM
			
			
			
		  
	 | 
 
	
		
		
		
			  | 
			
 
  
			
				
				
				Brigadier General 
				
				
				
			 | 
			  | 
			
				
				
					Join Date: Dec 2001 
					
					
					
						Posts: 1,859
					 
					 
	Thanks: 0 
	
		
			
				Thanked 0 Times in 0 Posts
			
		
	 
					
					
					
					     
				 
				
			 | 
		 
		 
		
	 | 
 
    
	
     
	
	
		
		
		
			
			
				 
				Re: OT: 2D/3D math
			 
             
			
		
		
		
		Mathematics! Formulas! Variables! Discussion! 
Run away! Run away! Math is taking over the world!    
		
	
		
		
		
		
		
		
			
				__________________ 
				A* E* Se++ GdQ $ Fr! C Csc Sf+ Ai- M Mp* S++ Ss- R! Pw Fq Nd Rp+ G++ Mm+ Bb++ Tcp+ L Au 
 
Download  Sev Today! --- Download  BOB and  SOCk today too! --- Thanks to Fyron and Trooper for hosting.
  
			 
		
		
		
		
		
		
	
		
		
	
	
	 | 
 
 
 
	 
	
		 
	 
 
	
	
		
	
	
	
		
		
		
			
			 
			
				November 26th, 2004, 11:15 PM
			
			
			
		  
	 | 
 
	
		
		
		
			  | 
			
 
  
			
				
				
				Shrapnel Fanatic 
				
				
				
			 | 
			  | 
			
				
				
					Join Date: Mar 2003 
					Location: CHEESE! 
					
					
						Posts: 10,009
					 
					 
	Thanks: 0 
	
		
			
				Thanked 7 Times in 1 Post
			
		
	 
					
					
					
					     
				 
				
			 | 
		 
		 
		
	 | 
 
    
	
     
	
	
		
		
		
			
			
				 
				Re: OT: 2D/3D math
			 
             
			
		
		
		
		Code:
  
 
                                      |Ax1 + By1 + C| 
distance between point and line: D = ----------------- 
                                     square root (A^2 + B^2) 
 
 
 
So...
 Code:
  
 
                                      |A*x1 + B*y1 + C| 
distance between point and line: D = ----------------- 
                                     square root (A^2 + B^2) 
 
 
 
??
 
In that case, what are A, B and C?  
		
	
		
		
		
		
		
		
			
				__________________ 
				If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!  
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++ 
  Some of my webcomics. I've got 400+ webcomics at Last count, some dead. 
Sig updated to remove non-working links.
			  
		
		
		
		
		
		
	
		
		
	
	
	 | 
 
 
 
	 
	
		 
	 
 
	
	
		
	
	
	
		
		
		
			
			 
			
				November 26th, 2004, 11:20 PM
			
			
			
		  
	 | 
 
	
		
		
		
			  | 
			
 
  
			
				
				
				Brigadier General 
				
				
				
			 | 
			  | 
			
				
				
					Join Date: Apr 2002 
					Location: Kailua, Hawaii 
					
					
						Posts: 1,860
					 
					 
	Thanks: 0 
	
		
			Thanked 1 Time in 1 Post
		
	 
					
					
					
					     
				 
				
			 | 
		 
		 
		
	 | 
 
    
	
     
	
	
		
		
		
			
			
				 
				Re: OT: 2D/3D math
			 
             
			
		
		
		
		use some algebra to transform the equation of the line to: 
 
line: Ax + By + C = 0 
 
then use whatever you came up with for A, B & C in the formula I gave to find the distance between the point and the line. 
 
Slick. 
		
	
		
		
		
		
		
		
			
				__________________ 
				Slick.
			 
		
		
		
		
		
		
	
		
		
	
	
	 | 
 
 
 
	 
	
		 
	 
 
	
	
		
	
	
	
		
		
		
			
			 
			
				November 26th, 2004, 11:30 PM
			
			
			
		  
	 | 
 
	
		
		
		
			  | 
			
 
  
			
				
				
				Shrapnel Fanatic 
				
				
				
			 | 
			  | 
			
				
				
					Join Date: Mar 2003 
					Location: CHEESE! 
					
					
						Posts: 10,009
					 
					 
	Thanks: 0 
	
		
			
				Thanked 7 Times in 1 Post
			
		
	 
					
					
					
					     
				 
				
			 | 
		 
		 
		
	 | 
 
    
	
     
	
	
		
		
		
			
			
				 
				Re: OT: 2D/3D math
			 
             
			
		
		
		
		Or, you know, I could do that thing I almost never think of and explain myself... 
 
I'm programming. I have the start XY of the line, the end XY of the line and the XY of the point. And I have no idea how to teach a computer algebra derivation. 
		
	
		
		
		
		
		
		
			
				__________________ 
				If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!  
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++ 
  Some of my webcomics. I've got 400+ webcomics at Last count, some dead. 
Sig updated to remove non-working links.
			  
		
		
		
		
		
		
	
		
		
	
	
	 | 
 
 
 
	 
	
		 
	 
 
	
	
		
	
	
	
		
		
		
			
			 
			
				November 26th, 2004, 11:56 PM
			
			
			
		  
	 | 
 
	
		
		
		
			  | 
			
 
  
			
				
				
				Major 
				
				
				
			 | 
			  | 
			
				
				
					Join Date: Jan 2004 
					Location: Taganrog, Russia 
					
					
						Posts: 1,087
					 
					 
	Thanks: 0 
	
		
			
				Thanked 0 Times in 0 Posts
			
		
	 
					
					
					
					     
				 
				
			 | 
		 
		 
		
	 | 
 
    
	
     
	
	
		
		
		
			
			
				 
				Re: OT: 2D/3D math
			 
             
			
		
		
		
		If  P1(x1,y1) - startpoint 
and P2(x2,y2) - endpoint 
Then equation of the line will be: 
x*(y2-y1) - y*(x2-x1) - x1*y2 + x2*y1 = 0 
 
so A = y2-y1; B = -(x2-x1); C = -(x1*y2 - x2*y1). 
 
But how to find coordinates of the point in the cross of line and perpendicular? 
		
	
		
		
		
		
		
		
		
		
		
	
		
		
	
	
	 | 
 
 
 
	 
	
		 
	 
 
	
	
		
	
	
	
		
		
		
			
			 
			
				November 27th, 2004, 12:23 AM
			
			
			
		  
	 | 
 
	
		
		
		
			  | 
			
 
  
			
				
				
				Shrapnel Fanatic 
				
				
				
			 | 
			  | 
			
				
				
					Join Date: Mar 2003 
					Location: CHEESE! 
					
					
						Posts: 10,009
					 
					 
	Thanks: 0 
	
		
			
				Thanked 7 Times in 1 Post
			
		
	 
					
					
					
					     
				 
				
			 | 
		 
		 
		
	 | 
 
    
	
     
	
	
		
		
		
			
			
				 
				Re: OT: 2D/3D math
			 
             
			
		
		
		
		Thanks. I'll try to figure it out tommorrow; my brain just crashed. 
		
	
		
		
		
		
		
		
			
				__________________ 
				If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!  
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++ 
  Some of my webcomics. I've got 400+ webcomics at Last count, some dead. 
Sig updated to remove non-working links.
			  
		
		
		
		
		
		
	
		
		
	
	
	 | 
 
 
 
	 
	
		 
	 
 
	
	
		
	
	
	
		
		
		
			
			 
			
				November 27th, 2004, 12:56 AM
			
			
			
		  
	 | 
 
	
		
		
		
			  | 
			
 
  
			
				
				
				Brigadier General 
				
				
				
			 | 
			  | 
			
				
				
					Join Date: Apr 2002 
					Location: Kailua, Hawaii 
					
					
						Posts: 1,860
					 
					 
	Thanks: 0 
	
		
			Thanked 1 Time in 1 Post
		
	 
					
					
					
					     
				 
				
			 | 
		 
		 
		
	 | 
 
    
	
     
	
	
		
		
		
			
			
				 
				Re: OT: 2D/3D math
			 
             
			
		
		
		
		here's the long story (note that this assumes a knowledge of algebra): 
 
you start with a line and a point.  find the slope of the line and call it "m". 
 
the slope of all lines perpendicular to that line now have a slope of -1/m. 
 
next you find the equation of the line going through the point with the slope of -1/m.  Here is that equation in the "point-slope" form:  (y-y1) = (-1/m) (x-x1) 
 
now you solve the equations for both lines simultaneously to get the point where the perpendicular line meets the original line.  There are various algebraic methods for this (too cumbersome for this forum's text editor).  you will end up with the solution (x2, y2) which is the intersection of the original line and the perpendicular line going through the point (x1, y1).  it also is the closest point on the original line to (x1, y1). 
 
now you use the distance formula to find the distance beween (x1, y1) and (x2, y2).   
 
Distance = square root ((x2-x1)^2 + (y2-y1)^2) 
 
and there you go. I had taken out all the intermediate stuff in the original solution.  All it takes is putting the original line into the form: Ax + By + C = 0 then using the formula I gave.  This is one of the standard algebraic forms for a line. 
 
========================================= 
 
As far as doing this on a computer, just step through the procedure I laid out here.  If you only start with 2 points instead of an equation for the line that joins them, you can easily figure out the equation: 
 
given 2 points: (x3, y3) and (x4, y4) 
 
the slope "m" of the line that joins them is:  m = (y4-y3) / (x4-x3) 
 
the equation of the line can be written using either of the original points. I'll use the first one: 
 
(y-y3) = m (x-x3) 
 
using some algebra, you can transform this into: 
 
mx - y + (y3-mx3) = 0 
 
therefore 
A = m = (y4-y3) / (x4-x3) 
B = -1 
C = (y3-mx3) = (y3-[(y4-y3)/(x4-x3)]x3) 
 
 
Slick. 
		
	
		
		
		
		
		
		
			
				__________________ 
				Slick.
			 
		
		
		
		
		
		
	
		
		
	
	
	 | 
 
 
 
	 
	
		 
	 
 
 
	
		
	
	
	
	
	
	
	
		
	
		 
		Posting Rules
	 | 
 
	
		
		You may not post new threads 
		You may not post replies 
		You may not post attachments 
		You may not edit your posts 
		 
		
		
		
		
		HTML code is On 
		 
		
	  | 
 
 
	 | 
	
		
	 | 
 
 
     |  
 |