Mar 2, 2024 Replies: 2 A bit more tricky than what I thought but then my math is a bit rusted. First challenge is to figure out if the moving point has breached the perimeter of the triangle (from inside to outside) and then correct for it and then bounce/reflect it correctly. For the attached project the start angle is 135 degrees from the centre point of the triangle. It is moving 1 vector length at a time. Code: Dim startAngle As Double = 135 Making use of Barycentric coordinates to determine if the moving point is inside or outside the triangle. First 10 bounces Many bounces later. Change the "Sleep" at the end of "Sub draw" to Sleep(0) to speed up the drawing. B4X: Sleep (0) The code can in all probability be massively improved but this is what my small brain came up with for now. Attachments b4jTriangleBounce.zip b4jTriangleBounce.zip 3.2 KB · Views: 482 Last edited: Mar 2, 2024 Click to expand...
A bit more tricky than what I thought but then my math is a bit rusted. First challenge is to figure out if the moving point has breached the perimeter of the triangle (from inside to outside) and then correct for it and then bounce/reflect it correctly. For the attached project the start angle is 135 degrees from the centre point of the triangle. It is moving 1 vector length at a time. Code: Dim startAngle As Double = 135 Making use of Barycentric coordinates to determine if the moving point is inside or outside the triangle. First 10 bounces Many bounces later. Change the "Sleep" at the end of "Sub draw" to Sleep(0) to speed up the drawing. B4X: Sleep (0) The code can in all probability be massively improved but this is what my small brain came up with for now.
Johan Schoeman Expert Licensed User Longtime User Mar 3, 2024 #2 100 simultaneous rays Change this line of code to increase/decrease the number or rays B4X: numrays = 100 Change this if you want to do more than 500 simultaneous rays B4X: Dim pos(500) As PVector Dim speed(500) As PVector Dim oldPos(500) As PVector Dim jump As Int Dim slope(500) As Double Dim startAngle(500) As Double Dim outAngle(500) As Double Attachments b4jTriangleBounce.zip b4jTriangleBounce.zip 3.3 KB · Views: 352
100 simultaneous rays Change this line of code to increase/decrease the number or rays B4X: numrays = 100 Change this if you want to do more than 500 simultaneous rays B4X: Dim pos(500) As PVector Dim speed(500) As PVector Dim oldPos(500) As PVector Dim jump As Int Dim slope(500) As Double Dim startAngle(500) As Double Dim outAngle(500) As Double
Johan Schoeman Expert Licensed User Longtime User Mar 8, 2024 #3 A correction for the rays that are emitted to 0 and 180 degrees (a bit of an oversight by me) Attachments b4jTriangleBounce.zip b4jTriangleBounce.zip 3.3 KB · Views: 358