If you have some insight in vector math, then you should be able to use this:
sync on
r = make vector2(1)
r = make vector2(2) : `Base vectors
r = make vector2(3) : `Temp vector
r = make vector2(4) : `Temp vector
`Initialize the base vectors
set vector2 1, 40, -20
set vector2 2, -40, -20
`Define origin
oX = screen width() / 2
oY = screen height() / 4 * 3
`Draw
TilesX = 10
TilesY = 10
do
cls
`Along relative x direction
`Vector 3 will hold the beginning point, 4 will contain the end of the map in the Y-direction
copy vector2 3, 2 : multiply vector2 3, TilesY
set vector2 4, oX, oY : add vector2 3, 3, 4
for x = 0 to TilesX
line x vector2(4), y vector2(4), x vector2(3), y vector2(3)
add vector2 3, 3, 1
add vector2 4, 4, 1
next x
`Along relative y direction
`Vector 3 will hold the beginning point, 4 will contain the end of the map in the X-direction
copy vector2 3, 1 : multiply vector2 3, TilesX
set vector2 4, oX, oY : add vector2 3, 3, 4
for y = 0 to TilesY
line x vector2(4), y vector2(4), x vector2(3), y vector2(3)
add vector2 3, 3, 2
add vector2 4, 4, 2
next y
`Finding the point along in that coordinate system:
set vector2 3, mousex() - oX, mousey() - oY
d1# = dot product vector2(1, 3)
d2# = dot product vector2(2, 3)
d3# = dot product vector2(1, 2)
la# = length vector2(1)
lb# = length vector2(2)
coordX# = (d1#*lb#*lb# - d2#*d3#) / ((la#*lb#)^2 - d3#^2)
coordY# = (d2#*la#*la# - d1#*d3#) / ((la#*lb#)^2 - d3#^2)
set cursor 0, 0
print coordX#, " : ", coordY#
sync
loop
remstart
Vectors = <>, <a> = base vector 1, <b> = base vector 2
<v> = x * <a> + y * <b>
<v>.<a> = x * <a>^2 + y * <b>.<a>
<v>.<b> = x * <a>.<b> + y * <b>^2
(Cramer)
=> | <v>.<a> <b>.<a> |
| <v>.<b> <b>^2 |
x = ------------------- = (<a>.<v>*<b>^2 - <b>.<v>*<a>.<b>) / ((|a|*|b|)^2 - (<a>.<b>)^2)
| <a>^2 <a>.<b> |
| <a>.<b> <b>^2 |
| <a>^2 <v>.<a> |
| <a>.<b> <v>.<b> |
x = ------------------- = (<a>^2*<v>.<b> - <v>.<a>*<a>.<b>) / ((|a|*|b|)^2 - (<a>.<b>)^2)
| <a>^2 <a>.<b> |
| <a>.<b> <b>^2 |
If vector a and b are perpendicular, then <a>.<b> = 0, so
<v>.<a> = x * <a>^2
<v>.<b> = y * <b>^2
and
x = <v>.<a> / <a>^2
y = <v>.<b> / <b>^2
remend
Cheers!
Sven B