Refraction script idea

Next
 From:  Fubax
10709.1 
I have an idea for a script than could generate refracted rays. It would be useful for generating lens schematic.



Idea is that it would work like Extend function, but creating new line segment as follows:
• Select line to refract
• Select transition line or surface
• Type transition refraction index (eg. air to glass 1/1.52)
Result would be a new line segment at a refracted angle.

Here's how refraction line is constructed manually, without any trigonometry. Just scaling perpendicular to normal, then mirroring.


  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Fubax
10709.2 In reply to 10709.1 
Following, the script could work as follows:

1. Extend refraction line to transition surface-or-line
2. If extended successfully, proceed
3. Get normal from transition surface-or-line
4. Create new line to refract
5. Scale sine of that line to the normal by refraction transition index (typed).
6. Mirror that line along transition surface and normal

I don't know how to write scripts for MoI, so someone maybe wants to do it.

EDITED: 30 May 2022 by FUBAX

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Frenchy Pilou (PILOU)
10709.3 In reply to 10709.2 
I believe that James can do that with Elephant without not so difficulties! ;)
---
Pilou
Is beautiful that please without concept!
My Moi French Site My Gallery My MagicaVoxel Gallery
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10709.4 In reply to 10709.1 
Hi Fubax, the node editor might be an easier place to start if you haven't done any script programming before at all:
https://moi3d.com/wiki/nodeeditor

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Fubax
10709.5 In reply to 10709.4 
Hello, I can try the nodeeditor, thank you for suggesting that.

This is the equation I came up with for producing refracted line



And here's the GLSL code that could do just that, I need to look into MoI scripting.

GLSL code:
vec3 refract(float n_trans, vec3 incident, vec3 normal)
{
	// Scale normal (assuming normal is an unit vector)
	normal *= dot(incident, normal);
	// Preserve incident vector length as squared value
	float sq_length = dot(incident, incident);
	// Scale incident vector tangentially to normal,
	// by transition refraction index (eg. air/glass=1/1.52)
	incident = n_trans*(incident-normal)+normal;
	// Normalize length of refracted incident, to scale along sine
	return -incident*rsqrt(dot(incident, incident)/sq_length);
}


Maybe someone could implement that.

EDITED: 1 Jun 2022 by FUBAX


  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Mik (MIKULAS)
10709.6 In reply to 10709.5 
It would be useful also if the node respected law of reflection. It means to have point/flat light source (solid) with rays (curves) as an input and curved surface - reflector (rotate conic curve) with Rho as a variable. Rays impacted of surface would be reflected to the detector (plane) in specific distance. This would be very nice educative tool. 2D would be enough :-)

Mik
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All