Jump to content

Math Problem!


mrnoob
 Share

Recommended Posts

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 by mrnoob
Link to comment
Share on other sites

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

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

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

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 by Nahuel
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...