Sketcher ConstrainSnellsLaw

From FreeCAD Documentation
Revision as of 00:23, 13 January 2015 by DeepSOIC (talk | contribs) (→‎Other)

Under construction!

Constraint SnellsLaw

Menu location
Sketch → Sketcher Constraints → Constrain refraction (Snell's law)
Workbenches
Sketcher, PartDesign
Default shortcut
None
Introduced in version
-
See also
None

Description

Snell's law

Constrains two lines to follow the law of refraction of light as it penetrates through an interface, where two materials of different refraction indices meet. See Snell's law on Wikipedia for more info.

How to use

The sequence of clicks is indicated by yellow arrows with numbers. n1, n2 are labeles on this picture to show where the indices of refraction are.
  • You'll need two lines that are to follow a beam of light, and a curve to act as an interface. The lines should be on different sides of the interface.
  • Select the endpoint of one line, an endpoint of another line, and the interface edge. The interface can be a line, circle/arc, ellipse/arc of ellipse. Note the order you've selected the endpoints.
  • Invoke the constraint. A dialog will appear asking for a ratio of indices of refraction n2/n1. n2 corresponds to the medium where the second selected endpoint's line resides, n1 is for the first line.
  • The endpoints will be made coincident (if needed), constrained onto the interface (if needed), and the Snell's law will become constrained.

Note that there are several helper constraints smart-added (point-on-object, coincident), and they can be deleted if they cause redundancy, or added manually if they were not added automatically. For the actual Snell's law constraint, the endpoints of lines must coincide and lie on the interface, otherwise the behavior is undefined.

Using polyline tool, it is possible to speedup drawing of rays of light. In this case, one can select two coincident endpoints by box selection.

Scripting

The constraints can be created from macros and from the python console by using the following function:

Sketch.addConstraint(Sketcher.Constraint('SnellsLaw',line1,pointpos1,line2,pointpos2,interface,n2byn1))

where:

Sketch is a sketch object
line1 and pointpos1 are two integers identifying the endpoint of the line in medium with refractive index of n1. line1 is the line's index in the sketch (the value, returned by Sketch.addGeometry), and pointpos1 should be 1 for start point and 2 for end point.
line2 and pointpos2 are the indexes specifying the endpoint of the second line (in medium n2)
n2byn1 is a floating-point number equal to the ratio of refractive indices n2/n1

Example:

from Sketcher import *
from Part import *
from FreeCAD import *

StartPoint = 1
EndPoint = 2
MiddlePoint = 3

f = App.activeDocument().addObject("Sketcher::SketchObject","Sketch")

# add geometry to the sketch
icir = f.addGeometry(Part.Circle(App.Vector(-547.612366,227.479736,0),App.Vector(0,0,1),68.161979))
iline1 = f.addGeometry(Part.Line(App.Vector(-667.331726,244.127090,0),App.Vector(-604.284241,269.275238,0)))
iline2 = f.addGeometry(Part.Line(App.Vector(-604.284241,269.275238,0),App.Vector(-490.940491,256.878265,0)))
# add constraints
f.addConstraint(Sketcher.Constraint('Coincident',iline1,EndPoint,iline2,StartPoint)) 
f.addConstraint(Sketcher.Constraint('PointOnObject',iline1,EndPoint,icir)) 
f.addConstraint(Sketcher.Constraint('SnellsLaw',iline1,EndPoint,iline2,StartPoint,icir,1.47))

App.ActiveDocument.recompute()

Version

The constraint was introduced in FreeCAD v0.15.4387