mrnoob Posted December 5, 2007 Share Posted December 5, 2007 (edited) On a Cartesian plane, there is a point (x,y). There is a second point (i,n). Find the point on the line which passes through (x,y) and (i,n) which has the largest value of x which is less then or equal to z, or which has the largest value of y which is less then or equal to 2z.Pictorial example - http://img505.imageshack.us/my.php?image=gaymd0.jpg Edited December 5, 2007 by mrnoob Link to comment Share on other sites More sharing options...
weaponx Posted December 5, 2007 Share Posted December 5, 2007 What are you talking about? You can't just say "a point". A point in space? A point on a graph? A point on an image? Tell us what you are trying to accomplish. Link to comment Share on other sites More sharing options...
mrnoob Posted December 5, 2007 Author Share Posted December 5, 2007 (edited) A point on a graph. I am trying move a cursor starting at one point, then passing through a second point and continuing on until either x>=932 or y >=370 Edited December 5, 2007 by mrnoob Link to comment Share on other sites More sharing options...
nikink Posted December 5, 2007 Share Posted December 5, 2007 That would just require some kind of conditional, wouldn't it? If $x >= 932 Then Return $y ElseIf $y >=370 Then Return $x EndIf ? Link to comment Share on other sites More sharing options...
mrnoob Posted December 5, 2007 Author Share Posted December 5, 2007 Yes, thats helpful, but I need a way to find a point which is on the line that passes through the first and second pointThis may help, http://img255.imageshack.us/my.php?image=thingot2.jpg. Link to comment Share on other sites More sharing options...
weaponx Posted December 5, 2007 Share Posted December 5, 2007 There isn't so much a formula as there is a condition, since there is many many x,y values that match this criteria. If ($x >= 932 or $y >=370) Then ;Stop EndIf - or - Do ;code Until ($x >= 932 or $y >=370) Link to comment Share on other sites More sharing options...
mrnoob Posted December 5, 2007 Author Share Posted December 5, 2007 There is only one point that will satisfy what I am looking for; there are not many x,y coords that will match this criteria. Link to comment Share on other sites More sharing options...
Nahuel Posted December 5, 2007 Share Posted December 5, 2007 Given two points, you can easily find the equation of a rect. What you are trying to do, If I'm not wrong, is make the mouse move in a line which contains these previously given coordinates and continue in a straight line unitl x >= 932 or y >=370 If that's so, find the equation that contains your two origian points. In a loop, increase X in the equation, this will give you Y. You now have a new (x,y) point to make the mouse move to. Do this until x >= 932 or y >=370. Link to comment Share on other sites More sharing options...
Xandl Posted December 5, 2007 Share Posted December 5, 2007 Hello, this is the formula for a line through two points: (y - y1)/(y2 - y1) = (x - x1)/(x2 - x1) So, we can get x = ((y - y1)/(y2 - y1) * (x2 - x1)) + x1 and y = ((x - x1)/(x2 - x1) * (y2 - y1)) + y1 x is what you are looking for, y will be yMin and yMax in your plane. The same goes with y. This example shows a correct result: ConsoleWrite(lX(0,0,10,10,20)&@LF) Func lX($x1,$y1,$x2,$y2,$maxY) Return (($maxY - $y1)/($y2 - $y1) * ($x2 - $x1)) + $x1 EndFunc ciao Xandl Link to comment Share on other sites More sharing options...
Nahuel Posted December 5, 2007 Share Posted December 5, 2007 (edited) Here's an example of what I meant: Global $X Global $Y ;Point 1: Global $X_1 = 5 Global $Y_1 = 10 ;Point 2: Global $X_2 = 100 Global $Y_2 = 100 $X=$X_1 $Y=$Y_1 $Past=False;This is just to show the messagebox once. Do MouseMove($X,$Y,2000) If $X>=$X_2 And $Y>=$Y_2 And not $Past Then MsgBox(0,"","We just past by point 2!") $Past=True EndIf ;Increase X $X+=5; The higher the faster. ;Equation of a rect given two points: $Y = (($Y_2 - $Y_1)/($X_2 - $X_1))*($X-$X_1) + $Y_1 $Y=Int($Y) ConsoleWrite("X: " & $X & ", Y: " & $Y & @CR) Until ($X >= 932 or $Y >=370) -edit- @Xandl: Precisely Edited December 5, 2007 by Nahuel Link to comment Share on other sites More sharing options...
mrnoob Posted December 6, 2007 Author Share Posted December 6, 2007 Ah, thank you guys so much; (y - y1)/(y2 - y1) = (x - x1)/(x2 - x1) is exactly what I was looking for!!!! I'm curious if you figured that out or if its a common formula? Link to comment Share on other sites More sharing options...
weaponx Posted December 6, 2007 Share Posted December 6, 2007 Finding the slope. http://en.wikipedia.org/wiki/Slope 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