77 lines
1.5 KiB
Plaintext
77 lines
1.5 KiB
Plaintext
use "math"
|
|
|
|
struct -vector2d
|
|
init &xpos -double
|
|
init &ypos -double
|
|
|
|
fun -void !init -double &x -double &y
|
|
set &xpos $x
|
|
set &ypos $y
|
|
return true
|
|
endfun
|
|
|
|
fun -string !toString
|
|
tostring $xpos &x1
|
|
tostring $ypos &y1
|
|
add "(" $x1 &store
|
|
add $store ", " &store
|
|
add $store $y1 &store
|
|
add $store ")" &store
|
|
return $store
|
|
endfun
|
|
|
|
fun -double !atan2
|
|
pusharg $ypos $xpos
|
|
!math:atan2 &store
|
|
return $store
|
|
endfun
|
|
|
|
fun -double !modulus
|
|
multiply $xpos $xpos &x2
|
|
multiply $ypos $ypos &y2
|
|
add $x2 $y2 &z2
|
|
pusharg $z2
|
|
!math:sqrt &z
|
|
return $z
|
|
endfun
|
|
endstruct
|
|
|
|
struct -line2d
|
|
init &gradient -double
|
|
init &yint -double
|
|
|
|
fun -void !initGI -double &g -double &y
|
|
set &gradient $g
|
|
set &yint $y
|
|
return true
|
|
endfun
|
|
|
|
fun -void !initTP -point &p1 -point &p2
|
|
subtract $p2.ypos $p1.ypos &rise
|
|
subtract $p2.xpos $p1.xpos &run
|
|
divide $rise $run &gradient
|
|
|
|
multiply $gradient $p1.xpos &store
|
|
subtract $p1.ypos $store &yint
|
|
return true
|
|
endfun
|
|
|
|
fun -vector2d !getPoint -double &x
|
|
multiply $gradient $x &store
|
|
add $store $yint &y
|
|
init &ans -vector2d
|
|
pusharg $x $y
|
|
!ans.init &store
|
|
return $ans
|
|
endfun
|
|
endstruct
|
|
|
|
init &line -line2d
|
|
pusharg 3 1
|
|
!line.initGI &store
|
|
|
|
pusharg 3
|
|
!line.getPoint &store
|
|
|
|
stdlnout $store.xpos
|
|
stdlnout $store.ypos |