# Math Problem!

## 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

##### Share on other sites

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.

##### Share on other sites

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 by mrnoob

##### Share on other sites

That would just require some kind of conditional, wouldn't it?

If \$x >= 932 Then

Return \$y

ElseIf \$y >=370 Then

Return \$x

EndIf

?

##### Share on other sites

Yes, thats helpful, but I need a way to find a point which is on the line that passes through the first and second point

This may help, http://img255.imageshack.us/my.php?image=thingot2.jpg.

##### 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)

##### Share on other sites

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.

##### 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.

##### 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

##### 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

##### Share on other sites

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?

## Create an account

Register a new account

×

• Wiki

• Back

• Git