Sketcher ConstrainSnellsLaw: Difference between revisions

From FreeCAD Documentation
mNo edit summary
No edit summary
 
(21 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
{{Page_in_progress}}
<translate>
<translate>


<!--T:13-->
<!--T:13-->
{{Docnav
{{Docnav
|[[Sketcher_ConstrainLock|Lock]]
|[[Sketcher_ConstrainAngle|Internal Angle]]
|[[Sketcher_ToggleDrivingConstraint|Toggle driving/reference constraint]]
|[[Sketcher_ConstrainInternalAlignment|Internal Alignment]]
|[[Sketcher_Workbench|Sketcher]]
|[[Sketcher_Workbench|Sketcher]]
|IconL=Sketcher_ConstrainAngle.svg
|IconL=Sketcher_ConstrainLock.svg
|IconR=Sketcher_ConstrainInternalAlignment.svg
|IconR=Sketcher_ToggleDrivingConstraint.svg
|IconC=Workbench_Sketcher.svg
|IconC=Workbench_Sketcher.svg
}}
}}
Line 15: Line 16:
{{GuiCommand
{{GuiCommand
|Name=Sketcher ConstrainSnellsLaw
|Name=Sketcher ConstrainSnellsLaw
|MenuLocation=Sketch → Sketcher Constraints → Constrain refraction (Snell's law)
|MenuLocation=Sketch → Sketcher constraints → Constrain refraction (Snell's law)
|Workbenches=[[Sketcher_Workbench|Sketcher]]
|Workbenches=[[Sketcher_Workbench|Sketcher]]
|Shortcut={{KEY|K}} {{KEY|W}}
|Version=0.15
|Version=0.15
}}
}}
Line 23: Line 25:


<!--T:2-->
<!--T:2-->
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.
The [[Image:Sketcher_ConstrainSnellsLaw.svg|24px]] [[Sketcher_ConstrainSnellsLaw|Sketcher ConstrainSnellsLaw]] tool 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.

<!--T:19-->
[[File:Snells_law2_witheq.svg|x400px]]


</translate>
[[Image:Snells_law2_witheq.svg|x400px]]
<translate>
<!--T:20-->
<!--T:20-->
{{Caption|Snell's Law}}
{{Caption|Snell's Law}}
Line 33: Line 35:
==Usage== <!--T:18-->
==Usage== <!--T:18-->


</translate>
<!--T:3-->
[[Image:Sketcher SnellsLaw Example1.png|500px]]
[[Image:Sketcher_SnellsLaw_Example1.png|500px]]
<translate>

<!--T:21-->
<!--T:21-->
{{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.}}
{{Caption|The sequence of clicks is indicated by yellow arrows with numbers, n1 and n2 show where the indices of refraction are}}


<!--T:4-->
<!--T:4-->
* 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.
# Prepare two lines to represent a beam of light, and an edge to act as an interface. The lines should be on different sides of the interface. The interface can be a [[Sketcher_CreateLine|line]], an [[Sketcher_CreateArc|arc]], a [[Sketcher_CreateCircle|circle]] or a [[Sketcher_CompCreateConic|conic]].
* Select the endpoint of one line, an endpoint of another line, and the interface edge. The interface can be a [[Sketcher_CreateLine|Line]], an [[Sketcher_CompCreateArc|Arc]], a [[Sketcher_CompCreateCircle|Circle]] or a [[Sketcher_CompCreateConic|Conic]]. Note the order you've selected the endpoints.
# Select an endpoint of the first line, an endpoint of the second line, and the interface edge. Note the selection order of the endpoints.
# There are several ways to invoke the tool:
* 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.
#* Select the {{MenuCommand|Sketch → Sketcher constraints → [[Image:Sketcher_ConstrainSnellsLaw.svg|16px]] Constrain refraction (Snell's law)}} option from the menu.
* The endpoints will be made coincident (if needed), constrained onto the interface (if needed), and the Snell's law will become constrained.
#* Use the keyboard shortcut: {{KEY|K}} then {{KEY|W}}.
# The {{MenuCommand|Refractive index ratio}} dialog opens.
# Enter the {{MenuCommand|Ratio n2/n1}}. Where {{MenuCommand|n2}} is for the medium where the second selected line resides, and {{MenuCommand|n1}} is for the first line's medium.
# A Snell's law constraint is added. If required the endpoints are made [[Sketcher_ConstrainCoincident|coincident]] and constrained [[Sketcher_ConstrainPointOnObject|onto the interface]]. These additional constraints are called [[Sketcher_helper_constraint|helper constraints]].


==Notes==
<!--T:5-->
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.

<!--T:6-->
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== <!--T:22-->


<!--T:7-->
<!--T:7-->
* 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, otherwise the behavior is undefined. 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).
* In Python the helper constraints must be added manually (see [[#Scripting|Scripting]]).
* 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.
* 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.
* 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.
* 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).
* Arcs of circle and ellipse are also accepted as rays. But this is also physical nonsense.


==Scripting== <!--T:23-->
==Scripting== <!--T:23-->
Line 65: Line 65:
<!--T:8-->
<!--T:8-->
The constraints can be created from [[Macros|macros]] and from the [[Python|Python]] console by using the following function:
The constraints can be created from [[Macros|macros]] and from the [[Python|Python]] console by using the following function:

</translate>
</translate>
{{Code|code=
{{Code|code=
Line 70: Line 71:
}}
}}
<translate>
<translate>

<!--T:9-->
<!--T:9-->
where:
where:
:* <tt>Sketch</tt> is a sketch object
:* {{incode|Sketch}} is a sketch object
:* <tt>line1</tt> and <tt>pointpos1</tt> are two integers identifying the endpoint of the line in medium with refractive index of ''n1''. <tt>line1</tt> is the line's index in the sketch (the value, returned by Sketch.addGeometry), and <tt>pointpos1</tt> should be 1 for start point and 2 for end point.
:* {{incode|line1}} and {{incode|pointpos1}} are two integers identifying the endpoint of the line in medium with refractive index of ''n1''. {{incode|line1}} is the line's index in the sketch (the value, returned by Sketch.addGeometry), and {{incode|pointpos1}} should be 1 for start point and 2 for end point.
:* <tt>line2</tt> and <tt>pointpos2</tt> are the indexes specifying the endpoint of the second line (in medium ''n2'')
:* {{incode|line2}} and {{incode|pointpos2}} are the indexes specifying the endpoint of the second line (in medium ''n2'')
:* <tt>interface</tt> is the index specifying the line indicating the position of the interface between medium ''n1'' and medium ''n2''
:* {{incode|interface}} is the index specifying the line indicating the position of the interface between medium ''n1'' and medium ''n2''
:* <tt>n2byn1</tt> is a floating-point number equal to the ratio of refractive indices ''n2''/''n1''
:* {{incode|n2byn1}} is a floating-point number equal to the ratio of refractive indices ''n2/n1''


<!--T:25-->
The [[Scripting_Sketcher_constraints_in_Python|Scripting Sketcher constraints in Python]] page explains the values which can be used for {{incode|line1}}, {{incode|pointpos1}}, {{incode|line2}}, {{incode|pointpos2}} and {{incode|interface}} and contains further examples on how to create constraints from Python scripts.
The [[Sketcher_scripting|Sketcher scripting]] page explains the values which can be used for {{incode|line1}}, {{incode|pointpos1}}, {{incode|line2}}, {{incode|pointpos2}} and {{incode|interface}} and contains further examples on how to create constraints from Python scripts.


<!--T:10-->
<!--T:10-->
Example:
Example:

</translate>
</translate>
{{Code|code=
{{Code|code=
Line 90: Line 94:
StartPoint = 1
StartPoint = 1
EndPoint = 2
EndPoint = 2
MiddlePoint = 3


f = App.activeDocument().addObject("Sketcher::SketchObject","Sketch")
f = App.activeDocument().addObject("Sketcher::SketchObject","Sketch")
Line 112: Line 115:
<!--T:14-->
<!--T:14-->
{{Docnav
{{Docnav
|[[Sketcher_ConstrainLock|Lock]]
|[[Sketcher_ConstrainAngle|Internal Angle]]
|[[Sketcher_ToggleDrivingConstraint|Toggle driving/reference constraint]]
|[[Sketcher_ConstrainInternalAlignment|Internal Alignment]]
|[[Sketcher_Workbench|Sketcher]]
|[[Sketcher_Workbench|Sketcher]]
|IconL=Sketcher_ConstrainAngle.svg
|IconL=Sketcher_ConstrainLock.svg
|IconR=Sketcher_ConstrainInternalAlignment.svg
|IconR=Sketcher_ToggleDrivingConstraint.svg
|IconC=Workbench_Sketcher.svg
|IconC=Workbench_Sketcher.svg
}}
}}


</translate>
</translate>
{{Sketcher Tools navi{{#translation:}}}}
{{Sketcher_Tools_navi{{#translation:}}}}
{{Userdocnavi{{#translation:}}}}
{{Userdocnavi{{#translation:}}}}
{{clear}}

Latest revision as of 21:15, 11 March 2024

This documentation is a work in progress. Please don't mark it as translatable since it will change in the next hours and days.

Sketcher ConstrainSnellsLaw

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

Description

The Sketcher ConstrainSnellsLaw tool 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 and n2 show where the indices of refraction are

  1. Prepare two lines to represent a beam of light, and an edge to act as an interface. The lines should be on different sides of the interface. The interface can be a line, an arc, a circle or a conic.
  2. Select an endpoint of the first line, an endpoint of the second line, and the interface edge. Note the selection order of the endpoints.
  3. There are several ways to invoke the tool:
    • Select the Sketch → Sketcher constraints → Constrain refraction (Snell's law) option from the menu.
    • Use the keyboard shortcut: K then W.
  4. The Refractive index ratio dialog opens.
  5. Enter the Ratio n2/n1. Where n2 is for the medium where the second selected line resides, and n1 is for the first line's medium.
  6. A Snell's law constraint is added. If required the endpoints are made coincident and constrained onto the interface. These additional constraints are called helper constraints.

Notes

  • 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, otherwise the behavior is undefined. The necessary helper constraints are added automatically based on the current coordinates of the elements.
  • In Python the helper constraints must be added manually (see Scripting).
  • 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. But this is also 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)
  • interface is the index specifying the line indicating the position of the interface between medium n1 and medium n2
  • n2byn1 is a floating-point number equal to the ratio of refractive indices n2/n1

The Sketcher scripting page explains the values which can be used for line1, pointpos1, line2, pointpos2 and interface and contains further examples on how to create constraints from Python scripts.

Example:

import Sketcher
import Part
import FreeCAD

StartPoint = 1
EndPoint = 2

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()