Question about e.normal

About advanced scenes, and the Thyme scripting language used in Algodoo.

Question about e.normal

Postby Xray » Sat Nov 03, 2018 7:55 am

I am working on a scene in which I need to determine which side of a rectangle that a laser is hitting it. I tried using e.normal, but the results that I am getting just don't seem to make sense. I am probably not using it correctly. Here is what I am trying to do: Imagine a door. One side of the door occasionally gets hit by a laser, and the other side of that same door occasionally gets hit. There are times when BOTH sides of the door get hit at the same time by the same laser (mirrors may reflect the beam from one side to the other side). I need a simple script that will calculate which side of the door is being hit by the laser, and if both sides are being hit at the same time. I assume that e.normal is the correct function to use for this task, but if there might be a better way, please let me know. Please provide an example script.

Thanks!

UPDATE: I figured out a way to do what I described above without using e.normal. It's an alternative method which so far seems to work quite well. I still do not know how to use e.normal in a script, so if anyone would like to leave a little tutorial about e.normal here, it would be much appreciated. I don't currently need it, but once I understand how to use it, then I may find that I will need it in some future scene. Thanks for any information that anyone wants to share about it!
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Question about e.normal

Postby FRA32 » Wed Nov 07, 2018 4:55 pm

E.normal returns the normal around which a laser is being reflected(the surface normal) OR the normal of the closest surface in case of a collision(usually the direction an object is pushed towards if it's inside another one). It is always perpendicular to the reference surface, which, in case of regular polygons and circle's, allows unique identification of the face that was hit. For your example, given that your door is a simple box, identifying whether an individual side is being hit is a matter of asking:

e.normal == [-1,0] ? {_side1 = true} : {};
e.normal == [1,0] ? {_side2 = true} : {};

However! due to the fact that laser events tend to skip out between frames(i.e. not every simulation step a laser event is generated), it can happen that, despite both sides being hit, it only registers one of both events. To counter this, and the lack of "onLaserStopHit" events, you can either add a second laser that activates for a short time whenever the main laser turns off and tells the door that the laser stopped, or you could register the status of the laser over muliple frames and reset the values to false every, say, three frames via poststep. This way, Algodoo can literally "tripple check" if the door is being hit or not, which I made use of in my laser-based logic toolbox scene. If you want, I can upload a scene showing how e.normal works, too :)
FRA32
 
Posts: 227
Joined: Wed Dec 03, 2014 9:51 pm

Re: Question about e.normal

Postby Xray » Wed Nov 07, 2018 9:24 pm

FRA32 -- Thanks very much for the information!

Questions:
What do those array values represent? I assume x and y, but what exactly are those values, what are their ranges, and what do they indicate? I searched the forum for any details about e.normal and I found very little on the subject.

I think an example scene would be helpful, especially if you could please explain how e.normal is being used in the scene.

Thanks again!

By the way, I created an "onLaserStop" scene which you can find here: OnLaserStop event
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Question about e.normal

Postby FRA32 » Wed Nov 07, 2018 11:30 pm

Here is an example scene showing what e.normal actually represents. The 2 coordinate of the array actually present the X-Width and Y-Height of a line sticking straight out of the surface!
FRA32
 
Posts: 227
Joined: Wed Dec 03, 2014 9:51 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests