RE: Angle Collisions - bplus - 10-17-2022
(10-17-2022, 04:10 PM)Pete Wrote: I hear good artists copy and great artists steal. I guess that makes you a good artist. If you were a great artist, I'd turn you in for the reward!
Pete
It is really good practice to copy and to give credit. So Pete you are a credit to Basic for not turning me in!
RE: Angle Collisions - james2464 - 10-17-2022
(10-17-2022, 04:10 PM)Pete Wrote: I hear good artists copy and great artists steal. I guess that makes you a good artist. If you were a great artist, I'd turn you in for the reward!
Pete
Copying the masters was great for learning. I started with Bob Ross and took his advice!
RE: Angle Collisions - james2464 - 10-17-2022
(10-17-2022, 04:53 PM)bplus Wrote: (10-17-2022, 03:46 PM)james2464 Wrote: Yes sir that's correct! Also it's my painting https://i.imgur.com/8eYU28D.jpg (I occupied my pandemic time by oil painting)
Time well spent, very nice!
Thanks! It was a good distraction that's for sure.
RE: Angle Collisions - james2464 - 10-18-2022
Well I finally got something that works, although it's just a single reflection. But I finally clued in on what the dot product is used for, and then it was a matter of completing the calculations to the reflection point.
So this is a utility program, using both the mouse to locate the ball and arrow keys to rotate the angled wall.
Code: (Select All) 'vector reflection demo
'james2464
Screen _NewImage(800, 600, 32)
Const PI = 3.141592654#
Dim Shared x, y, h, dx, dy, nx, ny, na As Single
Dim c(10) As Long
c(0) = _RGB(30, 30, 30)
c(1) = _RGB(255, 255, 255)
c(2) = _RGB(255, 255, 0)
c(3) = _RGB(255, 0, 0)
'0,0 origin
xx = 400
yy = 300
Line (0, yy)-(800, yy), c(0)
Line (xx, 0)-(xx, 600), c(0)
x = 70: y = 90 'ball position
na = 60 'reflecting surface angle
flag = 0
Do
_Limit 10
Cls
'chip starting pos - using mouse
mouseclick1 = 0
Do While _MouseInput
Loop
mx% = _MouseX
my% = _MouseY
If mx% < xx - 400 Then mx% = xx - 400
If mx% > xx + 400 Then mx% = xx + 400
If my% < yy - 300 Then my% = yy - 300
If my% > yy + 300 Then my% = yy + 300
lc% = _MouseButton(1)
If lc% = -1 Then mouseclick1 = 1
x = 0 - xx + mx%
y = yy - my%
'origin lines
Line (0, yy)-(800, yy), c(0)
Line (xx, 0)-(xx, 600), c(0)
'Locate 3, 1
'Print "Calculations"
'Print "Motion vector I ("; -x; ","; y; ")"
h = _Hypot(-x, y)
'Print h; "(hypot)"
'Print
nx = Sin(na * (PI / 180))
ny = Cos(na * (PI / 180))
'Print "Normal X:"; nx
'Print "Normal Y:"; ny
'Print
'Print "Dot product to find N length"
dx = -x * nx * -1: dy = y * ny
'Print dx; dy
'Print
ndp = dx + dy
'Print "N length (distance from origin to line A"
'Print ndp
'Print
ard = Sqr(h ^ 2 - ndp ^ 2)
'Print "Distance from N-A to R"
'Print ard
'Print "Point R location"
'Print nx * ard; ny * ard
'Print nx * ndp; ny * ndp
w2x = ny * ard: w2y = nx * ard
u2x = nx * ndp: u2y = ny * ndp
rx = w2x + u2x: ry = w2y - u2y
Circle (xx + rx, yy + ry), 10, c(3) 'point R
Line (xx, yy)-(xx + rx, yy + ry), c(3) 'line from origin to point R
'reflecting surface
A = (Sin(na * (PI / 180))) * 200
B = (Cos(na * (PI / 180))) * 200
Line (xx, yy)-(xx + B, yy + A), c(1)
Line (xx, yy)-(xx - B, yy - A), c(1)
Circle (xx + x, yy - y), 10, c(2) 'point I
Line (xx, yy)-(xx + x, yy - y), c(2)
Locate 1, 1
Print "Vector Reflection"
Print "Use up and down arrow keys to rotate wall"
Locate 35, 1
Print "Wall angle:"; na
Locate 1, 70
Print "I ="; x; ","; y;
Locate 35, 70
Print "R ="; Int(rx); ","; Int(-ry)
change_angle1 = uparrowkey
change_angle2 = downarrowkey
_Display
Loop Until flag = 1
Function uparrowkey
uparrowkey = 0
If _KeyDown(18432) Then ' IF up arrow key was pressed
na = na + 1. ' increase reflection angle
uparrowkey = 1 ' record that this happened
End If
End Function
Function downarrowkey
downarrowkey = 0
If _KeyDown(20480) Then ' IF down arrow key was pressed
na = na - 1. ' decrease reflection angle
downarrowkey = 1 ' record that this happened
End If
End Function
RE: Angle Collisions - Pete - 10-18-2022
Nice. This is reminding me of that pendulum routine Bill threw together at the old .rip site.
Pete
RE: Angle Collisions - Dav - 10-18-2022
(10-17-2022, 03:46 PM)james2464 Wrote: Yes sir that's correct! Also it's my painting https://i.imgur.com/8eYU28D.jpg (I occupied my pandemic time by oil painting)
very nice painting!
- Dav
RE: Angle Collisions - Pete - 10-18-2022
I learned to paint by numbers. That's right, I'm the guy who spray paints your house number on your curb! Steve says... What the hell is a curb???
Pete
RE: Angle Collisions - james2464 - 10-18-2022
(10-18-2022, 02:22 AM)Dav Wrote: (10-17-2022, 03:46 PM)james2464 Wrote: Yes sir that's correct! Also it's my painting https://i.imgur.com/8eYU28D.jpg (I occupied my pandemic time by oil painting)
very nice painting!
- Dav
Thanks!
RE: Angle Collisions - james2464 - 10-18-2022
Changed from arrow keys to mouse wheel for rotating the wall
Code: (Select All) 'vector reflection demo
'james2464
Screen _NewImage(800, 600, 32)
Const PI = 3.141592654#
Dim Shared x, y, h, dx, dy, nx, ny, na As Single
Dim c(10) As Long
c(0) = _RGB(30, 30, 30)
c(1) = _RGB(255, 255, 255)
c(2) = _RGB(255, 255, 0)
c(3) = _RGB(255, 0, 0)
'0,0 origin
xx = 400
yy = 300
Line (0, yy)-(800, yy), c(0)
Line (xx, 0)-(xx, 600), c(0)
x = 70: y = 90 'ball position
na = 60 'reflecting surface angle
flag = 0
Do
_Limit 10
Cls
'chip starting pos - using mouse
mouseclick1 = 0
Do While _MouseInput
na = na + _MouseWheel
Loop
mx% = _MouseX
my% = _MouseY
If mx% < xx - 400 Then mx% = xx - 400
If mx% > xx + 400 Then mx% = xx + 400
If my% < yy - 300 Then my% = yy - 300
If my% > yy + 300 Then my% = yy + 300
lc% = _MouseButton(1)
If lc% = -1 Then mouseclick1 = 1
x = 0 - xx + mx%
y = yy - my%
'origin lines
Line (0, yy)-(800, yy), c(0)
Line (xx, 0)-(xx, 600), c(0)
h = _Hypot(-x, y)
nx = Sin(na * (PI / 180)) 'normalize wall angle
ny = Cos(na * (PI / 180)) 'normalize wall angle
dx = -x * nx * -1: dy = y * ny: ndp = dx + dy
'dot product V.N - used to find distance of N
'The distance of N is from the point of origin to the middle of line A
'line A is a line from point I to point R (parallel to the angled wall)
ard = Sqr(h ^ 2 - ndp ^ 2) 'distance from mid point of line A to point R
w2x = ny * ard: w2y = nx * ard
u2x = nx * ndp: u2y = ny * ndp
rx = w2x + u2x: ry = w2y - u2y 'point R
Circle (xx + rx, yy + ry), 10, c(3) 'point R
Line (xx, yy)-(xx + rx, yy + ry), c(3) 'line from origin to point R
'angled wall
A = (Sin(na * (PI / 180))) * 200
B = (Cos(na * (PI / 180))) * 200
Line (xx, yy)-(xx + B, yy + A), c(1)
Line (xx, yy)-(xx - B, yy - A), c(1)
Circle (xx + x, yy - y), 10, c(2) 'point I
Line (xx, yy)-(xx + x, yy - y), c(2)
Locate 1, 1
Print "Vector Reflection"
Print "Use mouse wheel to rotate wall"
Locate 35, 1
Print "Wall angle:"; na
Locate 1, 70
Print "I ="; x; ","; y;
Locate 35, 70
Print "R ="; Int(rx); ","; Int(-ry)
_Display
Loop Until flag = 1
RE: Angle Collisions - bplus - 10-18-2022
(10-18-2022, 03:57 AM)james2464 Wrote: Changed from arrow keys to mouse wheel for rotating the wall
Code: (Select All) 'vector reflection demo
'james2464
Screen _NewImage(800, 600, 32)
Const PI = 3.141592654#
Dim Shared x, y, h, dx, dy, nx, ny, na As Single
Dim c(10) As Long
c(0) = _RGB(30, 30, 30)
c(1) = _RGB(255, 255, 255)
c(2) = _RGB(255, 255, 0)
c(3) = _RGB(255, 0, 0)
'0,0 origin
xx = 400
yy = 300
Line (0, yy)-(800, yy), c(0)
Line (xx, 0)-(xx, 600), c(0)
x = 70: y = 90 'ball position
na = 60 'reflecting surface angle
flag = 0
Do
_Limit 10
Cls
'chip starting pos - using mouse
mouseclick1 = 0
Do While _MouseInput
na = na + _MouseWheel
Loop
mx% = _MouseX
my% = _MouseY
If mx% < xx - 400 Then mx% = xx - 400
If mx% > xx + 400 Then mx% = xx + 400
If my% < yy - 300 Then my% = yy - 300
If my% > yy + 300 Then my% = yy + 300
lc% = _MouseButton(1)
If lc% = -1 Then mouseclick1 = 1
x = 0 - xx + mx%
y = yy - my%
'origin lines
Line (0, yy)-(800, yy), c(0)
Line (xx, 0)-(xx, 600), c(0)
h = _Hypot(-x, y)
nx = Sin(na * (PI / 180)) 'normalize wall angle
ny = Cos(na * (PI / 180)) 'normalize wall angle
dx = -x * nx * -1: dy = y * ny: ndp = dx + dy
'dot product V.N - used to find distance of N
'The distance of N is from the point of origin to the middle of line A
'line A is a line from point I to point R (parallel to the angled wall)
ard = Sqr(h ^ 2 - ndp ^ 2) 'distance from mid point of line A to point R
w2x = ny * ard: w2y = nx * ard
u2x = nx * ndp: u2y = ny * ndp
rx = w2x + u2x: ry = w2y - u2y 'point R
Circle (xx + rx, yy + ry), 10, c(3) 'point R
Line (xx, yy)-(xx + rx, yy + ry), c(3) 'line from origin to point R
'angled wall
A = (Sin(na * (PI / 180))) * 200
B = (Cos(na * (PI / 180))) * 200
Line (xx, yy)-(xx + B, yy + A), c(1)
Line (xx, yy)-(xx - B, yy - A), c(1)
Circle (xx + x, yy - y), 10, c(2) 'point I
Line (xx, yy)-(xx + x, yy - y), c(2)
Locate 1, 1
Print "Vector Reflection"
Print "Use mouse wheel to rotate wall"
Locate 35, 1
Print "Wall angle:"; na
Locate 1, 70
Print "I ="; x; ","; y;
Locate 35, 70
Print "R ="; Int(rx); ","; Int(-ry)
_Display
Loop Until flag = 1
Nice app, I would have done it this way https://staging.qb64phoenix.com/showthread.php?tid=967&pid=8074#pid8074
|