Sketcher ConstrainSnellsLaw/en: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
(Updating to match new version of source page)
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
<languages/>
<languages/>
{{Docnav
{{GuiCommand|Name=Constraint SnellsLaw|MenuLocation=Sketch → Sketcher Constraints → Constrain refraction (Snell's law)|Workbenches=[[Sketcher Workbench|Sketcher]], [[PartDesign Workbench|PartDesign]]}}
|[[Sketcher_ConstrainAngle|Internal Angle]]
|[[Sketcher_ConstrainInternalAlignment|Internal Alignment]]
|[[Sketcher_Workbench|Sketcher]]
|IconL=Constraint_InternalAngle.png
|IconC=Workbench_Sketcher.svg
|IconR=Constraint_InternalAlignment.png
}}

{{GuiCommand
|Name=Sketcher ConstrainSnellsLaw
|MenuLocation=Sketch → Sketcher Constraints → Constrain refraction (Snell's law)
|Workbenches=[[Sketcher_Workbench|Sketcher]]
|Version=0.15
}}

==Description==


==Description==
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 [http://en.wikipedia.org/wiki/Snell%27s_law Snell's law] on Wikipedia for more info.
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 [http://en.wikipedia.org/wiki/Snell%27s_law Snell's law] on Wikipedia for more info.
[[Image:Snells law2 witheq.svg|thumb|left|200px|Snell's law]]
{{clear}}


[[File:Snells_law2_witheq.svg|x400px]]
==How to use==

[[Image:Sketcher SnellsLaw Example1.png|thumb|none|500px|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.]]
{{Caption|Snell's Law}}

==Usage==

[[Image:Sketcher SnellsLaw Example1.png|500px]]

{{Caption|The sequence of clicks is indicated by yellow arrows with numbers. n1, n2 are only labels 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.
* You will 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.
* 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.
* 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.
* 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 [[Sketcher helper constraint|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.
Note that several [[Sketcher helper constraint|helper constraints]] will be added automatically (point-on-object, coincident). 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 lay 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.
Using the {{Button|[[File:Sketcher_CreatePolyline.svg|16px]] [[Sketcher_CreatePolyline|Polyline]]}}, it is possible to speed up drawing rays of light. In this case one can select two coincident endpoints by box selection.


==Remarks==
==Remarks==

* The actual Snell's law constraint enforces the plain law equation n1*sin(theta1) = n2*sin(theta2). It needs the line ends to be made coincident and on the interface by other constraints. The necessary helper constraints are added automatically based on the current coordinates of the elements.
* The actual Snell's law constraint enforces the plain law equation n1*sin(theta1) = n2*sin(theta2). It needs the line ends to be made coincident and on the interface by other constraints. The necessary helper constraints are added automatically based on the current coordinates of the elements.
* Python routine does not add the helper constraints. These must be added manually by the script (see example in Scripting section).
* Python routine does not add the helper constraints. These must be added manually by the script (see example in Scripting section).
Line 28: Line 49:


==Scripting==
==Scripting==

The constraints can be created from [[macros]] and from the python console by using the following function:
The constraints can be created from [[Macros|macros]] and from the python console by using the following function:
{{Code|code=
{{Code|code=
Sketch.addConstraint(Sketcher.Constraint('SnellsLaw',line1,pointpos1,line2,pointpos2,interface,n2byn1))
Sketch.addConstraint(Sketcher.Constraint('SnellsLaw',line1,pointpos1,line2,pointpos2,interface,n2byn1))
Line 40: Line 62:
Example:
Example:
{{Code|code=
{{Code|code=
from Sketcher import *
import Sketcher
from Part import *
import Part
from FreeCAD import *
import FreeCAD


StartPoint = 1
StartPoint = 1
Line 52: Line 74:
# add geometry to the 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))
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)))
iline1 = f.addGeometry(Part.LineSegment(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)))
iline2 = f.addGeometry(Part.LineSegment(App.Vector(-604.284241,269.275238,0),App.Vector(-490.940491,256.878265,0)))
# add constraints
# add constraints
# helper constraints:
# helper constraints:
Line 61: Line 83:
f.addConstraint(Sketcher.Constraint('SnellsLaw',iline1,EndPoint,iline2,StartPoint,icir,1.47))
f.addConstraint(Sketcher.Constraint('SnellsLaw',iline1,EndPoint,iline2,StartPoint,icir,1.47))


App.ActiveDocument.recompute()}}
App.ActiveDocument.recompute()
}}


==Version==
The constraint was introduced in FreeCAD v0.15.4387


{{Docnav
|[[Sketcher_ConstrainAngle|Internal Angle]]
|[[Sketcher_ConstrainInternalAlignment|Internal Alignment]]
|[[Sketcher_Workbench|Sketcher]]
|IconL=Constraint_InternalAngle.png
|IconC=Workbench_Sketcher.svg
|IconR=Constraint_InternalAlignment.png
}}

{{Sketcher Tools navi{{#translation:}}}}
{{Userdocnavi{{#translation:}}}}
{{clear}}
{{clear}}

Revision as of 20:01, 29 September 2020

Sketcher ConstrainSnellsLaw

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

Description

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.

Snell's Law

Usage

The sequence of clicks is indicated by yellow arrows with numbers. n1, n2 are only labels to show where the indices of refraction are.

  • You will 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 several helper constraints will be added automatically (point-on-object, coincident). 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 lay on the interface, otherwise the behavior is undefined.

Using the Polyline, it is possible to speed up drawing rays of light. In this case one can select two coincident endpoints by box selection.

Remarks

  • The actual Snell's law constraint enforces the plain law equation n1*sin(theta1) = n2*sin(theta2). It needs the line ends to be made coincident and on the interface by other constraints. The necessary helper constraints are added automatically based on the current coordinates of the elements.
  • Python routine does not add the helper constraints. These must be added manually by the script (see example in Scripting section).
  • These helper constraints can be temporarily deleted and the endpoints dragged apart, which can be useful in case one wants to construct a reflected ray or birefringence rays.
  • Unlike the reality, refraction indices are associated with rays of light, but not according to the sides of the boundary. This is useful to emulate birefringence, construct paths of different wavelengths due to refraction, and easily construct angle of onset of total internal reflection.
  • Both rays can be on the same side of the interface, satisfying the constraint equation. This is physical nonsense, unless the ratio n2/n1 is 1.0, in which case the constraint emulates a reflection.
  • Arcs of circle and ellipse are also accepted as rays (physical nonsense).

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:

import Sketcher
import Part
import FreeCAD

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.LineSegment(App.Vector(-667.331726,244.127090,0),App.Vector(-604.284241,269.275238,0)))
iline2 = f.addGeometry(Part.LineSegment(App.Vector(-604.284241,269.275238,0),App.Vector(-490.940491,256.878265,0)))
# add constraints
# helper constraints:
f.addConstraint(Sketcher.Constraint('Coincident',iline1,EndPoint,iline2,StartPoint)) 
f.addConstraint(Sketcher.Constraint('PointOnObject',iline1,EndPoint,icir)) 
# the Snell's law:
f.addConstraint(Sketcher.Constraint('SnellsLaw',iline1,EndPoint,iline2,StartPoint,icir,1.47))

App.ActiveDocument.recompute()