Main Menu

Understanding Slopes and Intercepts.

Started by ScottieB, January 23, 2014, 04:21:48 PM

Previous topic - Next topic

ScottieB

The code is below.
I am trying to wrap my head around slopes and intercepts.
I need for a game I've been working on.
The green dot is the y-intercept.
The blue dot is the x-intercept.
The trail of red dots is both that do collision detection.
The question I got is this.
Just how does this convert to regular screen co-ordinates when the only thing that seems right is Cartesian.
During raycasting this is suppose to increase the speed tremendiously.
Can anyone help?
I sorta get it but It's weird.
Thanks
ScottieB


It's short.
***********************************************

x_res = GetScreenWidth()
y_res = GetScreenHeight()

x1# = -x_res
y1# =  0

x2# =  x_res
y2# = 0

line x1# + x_res / 2,y1# + y_res / 2,x2# + x_res / 2,y2# + y_res / 2

x1# = 0
y1# = -y_res

x2# = 0
y2# = y_res

line x1# + x_res / 2,y1# + y_res / 2,x2# + x_res / 2,y2# + y_res / 2

x_step = 40
y_step = 40

For y = -200 to 200 step y_step
   for x = -200 to 200 step x_step
            
      box x + x_res / 2,y + y_res / 2, x + x_step + x_res / 2,y + y_step + y_res / 2,0

   next x
next y 

x1# = -200
y1# =  175

x2# =  175
y2# = -225

ink rgb(255,0,0)
line x1# + x_res / 2,y1# + y_res / 2,x2# + x_res / 2,y2# + y_res / 2

; Rise over run.

m# = (y2# - y1#) / (x2# - x1#)  ; Slope of a line.

; y = mx + b 

y# = y2# - (m# * x2#)  ; y-intercept (point line form).

ink rgb(0,255,0)
circle 0 + x_res / 2,y# + y_res / 2,10,1

m# = (x2# - x1#) / (y2# - y1#)  ; Slope of a line.
   
; x = my + b 

x# = x2# - (m# * y2#)  ; x-intercept

ink rgb(0,0,255)
circle x# + x_res / 2,0 + y_res / 2,10,1

x1# = 0
y1# = 0

ink rgb(255,0,0)   
for check = 0 To 9

   circle x1# + x_res / 2,y1# + y_res / 2,10,1

   x1# = x1# + -x#
   y1# = y1# + y#
      
next check   

sync

waitkey

kevin

There's bunch of similar examples in the source code board,  look under collision in the PlayBasic Source Code Forum Index