EvAsion Posted April 15, 2008 Share Posted April 15, 2008 Given several points, and a 3 dimensional line (determined by a point and a rotation from that point), how can i determine the point closest to that line. Note: (x,y,z not x,y) |-- Periodic Table --||-- Dynamic Class Timetable --||-- Navigation in Counter-Strike --| Link to comment Share on other sites More sharing options...
weaponx Posted April 15, 2008 Share Posted April 15, 2008 What does this have to do with AutoIt? Link to comment Share on other sites More sharing options...
EvAsion Posted April 15, 2008 Author Share Posted April 15, 2008 (edited) i don't know. Edit: i want to calculate this with autoit.. Problem is i don't know how to calculate the closest distance betweeen the line and a certain point(so determine the closest point on the line to a certain point).. but i can easily calculate the distance between 2 points. Edit2: Oh wait i could draw a line perpendicular to the line from the point.. and then determine the point of intersection.. calculate the distance between the point and the point of intersection.. do it for all the points.. yay... now i just need to convert it from my head into autoit. Edited April 15, 2008 by EvAsion |-- Periodic Table --||-- Dynamic Class Timetable --||-- Navigation in Counter-Strike --| Link to comment Share on other sites More sharing options...
d4rk Posted April 15, 2008 Share Posted April 15, 2008 (edited) i don't know.how about going somewhere ? funadvice.com ? Edited April 15, 2008 by d4rk [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
EvAsion Posted April 15, 2008 Author Share Posted April 15, 2008 how about going somewhere ? funadvice.com ?I would.. but i have to sign up!?! |-- Periodic Table --||-- Dynamic Class Timetable --||-- Navigation in Counter-Strike --| Link to comment Share on other sites More sharing options...
mrbig1479 Posted April 15, 2008 Share Posted April 15, 2008 I would probebly do 1. start in the begining of that line . and jumping in small steps on the line direction.. 2. every step check to see is the perpendicular line to the point is smaller then the last line. (mark the point also) 3. do that untill i finish the steps Link to comment Share on other sites More sharing options...
EvAsion Posted April 15, 2008 Author Share Posted April 15, 2008 (edited) I would probebly do 1. start in the begining of that line . and jumping in small steps on the line direction..2. every step check to see is the perpendicular line to the point is smaller then the last line. (mark the point also)3. do that untill i finish the stepsI could do that, but that would be incredibly inefficient. I think it would be best if i drew a line from the point, perpendicular to the original line, at a rotation where it would intersect the original line, mark the intercept, get the distance between the point and the intercept, and repeat for all the points.Edit: am i making any sense? Edited April 15, 2008 by EvAsion |-- Periodic Table --||-- Dynamic Class Timetable --||-- Navigation in Counter-Strike --| Link to comment Share on other sites More sharing options...
weaponx Posted April 15, 2008 Share Posted April 15, 2008 I converted the example found here:http://mathforum.org/library/drmath/view/54731.htmlI tested using a line from 0,0,0 to 1,0,0 with a point at 0,1,0 which should return 1 as the distance.expandcollapse popup#cs ---------------------------------------------------------------------------- Let, A(x1,y1,z1), B(x2,y2,z2) = Two points defining the line P(x,y,z) = Point whose distance from line AB is to be found We can find vectors, AB = = AP = < x-x1, y-y1, z-z1 > = I am using angle brackets < > to distinguish vectors from points. Now, let's take the cross product AB X AP. This is how you can calculate it: AB X AP = < y3*z4 - z3*y4, -(x3*z4 - x4*z3), x3*y4 - x4*y3 > Let's let (a) be the length of AB X AP. Then a = Sqrt{ (y3*z4 - z3*y4)^2 + (x3*z4 - x4*z3)^2 + (x3*y4 - x4*y3)^2 } If you divide (a) by the distance AB you will get the distance of P from line AB. Distance AB can be found using the distance formula as, AB = square root of (x3^2 + y3^2 + z3^2) Thus the distance we are looking for is a/AB. Now, did you see why it works? Because the length of the cross product (a) gives the area of the Parallelogram formed by the vectors AB and AP as shown. If you rest the parallelogram on AB as the base, its area (a) is AB*h. Where (h) is the height, which is nothing but the distance we are looking for! P o------+------o \ | \ \ |h \ \ | \ ------o--+----------o----------- A B As for the last part of your question : When a line is given only in terms of its inclinations with the coordinate axes, then the line could 'float' anywhere parallel to itself, because its not 'anchored' to (or through) any point. In such a case, its distance from point P is not fixed. #ce ---------------------------------------------------------------------------- ;A(x1,y1,z1), B(x2,y2,z2) = Two points defining the line Const $x1 = 0, $y1 = 0, $z1 = 0 Const $x2 = 1, $y2 = 0, $z2 = 0 ;P(x,y,z) = Point whose distance from line AB is to be found Const $x = 0, $y = 1, $z = 0 ;Vectors Dim $AB[3] = [$x2-$x1, $y2-$y1, $z2-$z1] Dim $AP[3] = [$x-$x1, $y-$y1, $z-$z1] ;Now, let's take the cross product AB X AP. This is how you can calculate it: $ABAP = cross($AB,$AP) ;Let's let (a) be the length of AB X AP. Then $a = Sqrt($ABAP[0]^2 + $ABAP[1]^2 + $ABAP[2]^2 ) ;Distance AB can be found using the distance formula as, AB = square root of (x3^2 + y3^2 + z3^2) $dAB = Sqrt($AB[0]^2 + $AB[1]^2 + $AB[2]^2) ;Thus the distance we are looking for is a/AB. $answer = $a/$dAB MsgBox(0,"","Distance from point " & $x & "," & $y & "," & $z & " to line from " & $x1 & "," & $y1 & "," & $z1 & " to " & $x2 & "," & $y2 & "," & $z2 & @CRLF & "= " & $answer) Func cross($V1, $V2) Local $x3 = $V1[0], $y3 = $V1[1], $z3 = $V1[2] Local $x4 = $V2[0], $y4 = $V2[1], $z4 = $V2[2] Local $CP[3] $CP[0] = $y3*$z4 - $z3*$y4 $CP[1] = -($x3*$z4 - $x4*$z3) $CP[2] = $x3*$y4 - $x4*$y3 Return $CP EndFunc Link to comment Share on other sites More sharing options...
EvAsion Posted April 16, 2008 Author Share Posted April 16, 2008 You are amazing weaponx. |-- Periodic Table --||-- Dynamic Class Timetable --||-- Navigation in Counter-Strike --| Link to comment Share on other sites More sharing options...
weaponx Posted April 16, 2008 Share Posted April 16, 2008 You are amazing weaponx."Its nothing any American with balls of steel wouldn't do for his community." -The Mask Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 16, 2008 Share Posted April 16, 2008 "Its nothing any American with balls of steel wouldn't do for his community." -The MaskThose would be adamantium, wouldn't they...? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
weaponx Posted April 16, 2008 Share Posted April 16, 2008 Haha. That would be correct. Link to comment Share on other sites More sharing options...
d4rk Posted April 16, 2008 Share Posted April 16, 2008 "balls of steel"yes, you're amazing but ball of steel , what is it ? [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
Skrip Posted April 16, 2008 Share Posted April 16, 2008 yes, you're amazing but ball of steel , what is it ?Nothing but of course this! [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left] Link to comment Share on other sites More sharing options...
d4rk Posted April 16, 2008 Share Posted April 16, 2008 Nothing but of course this!yoh, [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now