10-16-2022, 07:11 PM
(10-16-2022, 01:14 PM)OldMoses Wrote:(10-16-2022, 12:17 AM)james2464 Wrote: This video explains the reflection of a vector, but I don't know what 'n' is. At 10:27 he says "don't forget if n is unit length you know that n.n is 1 and you can cross that out". But there are still more n's in the formula and I can't figure out what they are supposed to represent. He just said n=1 !! Or n.n = 1 anyway. I just wish there were numbers involved instead of just letters. That would be a huge help.
https://youtu.be/naaeH1qbjdQ
It can be very confusing mixing vector math and scalar math in the same equation. The former is treating each component (x & y) of the vector with scalar values. Dot product is giving a scalar value, not a vector, but you are then using that scalar to multiply the separate components of vectors. I find it helpful to define a UDT that holds the vector components and relegate dot product calculations to a function that receives both vectors:
Code: (Select All)TYPE V2
x AS INTEGER
y AS INTEGER
END TYPE
FUNCTION R2_Dot (a AS V2, b AS V2)
R2_Dot = a.x * b.x + a.y * b.y
END FUNCTION
I believe the "n" is the vector normal of the plane. That is, vector 'n' is orthogonal (or perpendicular) to the plane. If it is a "unit" vector, as he seems to indicate, then its length is = 1. Remember that there are two orthogonals to the plane and I suspect that you would have to obtain both and then dot each with the relative position of the ball, keeping the one that is a positive result.
Now n.n I take to mean getting a dot product of a vector with itself, i.e. we are projecting a vector onto itself which necessarily results in a value of 1. Any number over a denominator of 1 is that number. Remember that the dot product of two vectors returns a scalar number, not a vector. Two vectors going in the same direction result in 1, in opposite directions results in -1 and orthogonal vectors result in 0.
v.n/n.n is simply v.n/1 or v.n. So your denominator is taken care of and you simply have to obtain the scalar value of v.n
Clear as mud, I know, and I hope this is not confusing the issue more. I spent many hours watching Professor Leonard videos to try to wrap my head around vectors, which I use in my space flight program, and I still have a lot to learn. As for matrices, I am as yet still at a loss to use them...
Thanks for the explanation. I couldn't understand why a formula meant to reflect a vector would basically destroy the direction info by converting it into a scalar value. At this point I still don't know what to do with the scalar result, when I'm trying to get a new vector.
I decided to draw an example to scale. I'm working on this exact scenario, reflecting a ball off a 75 degree wall. The ball has a (QB64 screen) vector of (-2,5). Cartesian (-2,-5).
I used Mastercam to draw to scale and used that info to create this. I'm still unable to use the dot product formula to find the R vector. Hopefully later today I'll have it sorted out.
Code: (Select All)
Screen _NewImage(800, 600, 32)
Const PI = 3.141592654#
Dim c(10) As Long
c(0) = _RGB(30, 30, 30)
c(1) = _RGB(255, 255, 255)
c(2) = _RGB(255, 255, 0)
Line (0, 300)-(800, 300), c(0)
Line (400, 0)-(400, 600), c(0)
A = 200
B = (Cos(75 * (PI / 180))) * A
Line (400 - B, 300 - A)-(400 + B, 300 + A), c(1)
Circle (480, 100), 10, c(2)
A = 200
B = (Tan(21.80140949 * (PI / 180))) * A
Line (400 + B, 300 - A)-(400, 300), c(2)
A = 33.39745962
B = (Tan(75 * (PI / 180))) * A
Line (400 + B, 300 - A)-(400, 300), c(1)
Circle (400 + 169.2820323, 300 + 133.2050808), 10, c(2)
A = 133.2050808
B = (Tan(128.1985905 * (PI / 180))) * A
Line (400 - B, 300 + A)-(400, 300), c(2)
Line (480, 100)-(400 + 169.2820323, 300 + 133.2050808), c(2)
Locate 1, 1
Print "DOT PRODUCT HELL"
Locate 5, 40
Print "75 DEG SURFACE"
Locate 6, 63
Print "I (-2,5)"
Locate 29, 74
Print "R (?,?)"