Beam simulation

Hi Everyone,

I’m a long time blender user and have a personal work-related project that I would like to make happen.

In a nut shell: Ultrasonic Testing forms part of industrial non-destructive testing and is a method used in many industries to evaluate the condition of materials and composites and identify defects that could potentially cause harm to production equipment or people in the vicinity of the equipment when it should fail. You can read all about it here if you’re interested: https://en.wikipedia.org/wiki/Ultrasonic_testing

The particular implementation of UT that I specialize in would be testing of steel welds. Through all the training qualification courses you’re taught how to anticipate the beam reflection & refraction to accurately plot defects within the welds. I’ve automated this drawing process in blender using a simple script.


The above example is of a more advanced type of UT inspection but the basic principles are still the same.

I want to step it up now by being able to ‘simulate’ the beam refraction & reflection on complex geometries. I’ve added a picture to explain what i would like to achieve:
image

For now I’m only looking to simulate 1 beam at a predetermined angle. Being able to put it on any geometry and see at what angle the beam would reflect in by drawing the beam while moving the “UT Probe” left and right as per the “scenario 2” referenced in the above image.

So my question is: Experts of UPBGE - how would you approach this problem? What should I consider and where you recommend I invest my time? Up till now I’ve played around with the logic bricks and made stuff move around on the screen and had a good time playing with physics in UPBGE. All I’m asking is a nudge in the right direction.

Kind regards,
Kyle

Incident = incoming.reflect(hitNormal)

1 Like

ray_reflect_demo.blend (830.1 KB)

I think you need

if dot(incoming,normal)<0:
     reflect:
else:
     refract

still

edit - the code was working and I am not sure why :stuck_out_tongue:
(maybe because of the angles)
fixed

import bge,math
from mathutils import Matrix, Vector

def main():

    cont = bge.logic.getCurrentController()
    own = cont.owner

    mat = own.worldTransform.copy()
    #get a copy of world transform matrix
    l = 8
    for x in range(l):
        rot = Matrix.Rotation(math.radians( -45 + ((90/l)*x )) , 4, 'X')
        new = mat @ rot
        #rotate from -45 to 45 at a step every x units
        vec = new @ Vector([0,10,0])    
        #ray end point
         
        ray = own.rayCast(vec, own.worldPosition,0,"",0,0,0)
        if ray[0]:
            #we hit something
            bge.render.drawLine(own.worldPosition, ray[1],(0,0,1))
            new = -(own.worldPosition-ray[1]).normalized().reflect(ray[2])
            #print(ray[1])
            bge.render.drawLine(ray[1]+new, ray[1],(1,0,0))
main()


1 Like

Thank you @BluePrintRandom !!

This is great start to what I need to work on.
I’ll post some updates once I’ve got something worth showing.

Thank you again for taking the time to help me

1 Like