10-16-2022, 04:02 PM
(10-16-2022, 01:27 PM)bplus Wrote: What confuses me about vectors is that a line or line segment has 2 normal vectors each points 90 degrees off the line in question with 180 degrees difference between them. The length or magnitude of the normal vectors aren't needed nearly as much as the actual angle ie which way the normal vector points. It is from that that the reflective angle is compared to incoming angle.
I usually resort to adding the third dimension and apply the right hand rule and a cross product calculation in these cases. It requires that one keep track of the point order of the lines, say, taking the clockwise point components and subtracting the counterclockwise point components from it to get a clockwise pointing line vector with a z of 0. This probably also requires a WINDOW redefinition that tracks with mathematical cartesian coordinates as opposed to general screen coordinates, I haven't played with that approach in screen coordinates yet.
Then cross product that vector<v> with a khat vector<v2> defined as <0, 0, 1> and the result vector<re> should be (if the right hand rule is done properly) a normal to each line in question that always points inward to the ball space. Then just put the x & y of <re> back into a 2D vector (the z will be zero anyway). There's probably an easier way, but I don't know it.
Code: (Select All)
TYPE V3
x AS INTEGER
y AS INTEGER
z AS INTEGER
END TYPE
'Description:
'Obtain cross product vector of vectors v and v2
'Right hand rule v is index, v2 is middle, re is thumb
SUB R3_Cross (re AS V3, v AS V3, v2 AS V3)
re.x = v.y * v2.z - v.z * v2.y
re.y = -(v.x * v2.z - v.z * v2.x)
re.z = v.x * v2.y - v.y * v2.x
END SUB 'R3_Cross
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
sha_na_na_na_na_na_na_na_na_na: