Sketcher Tutorial

This tutorial is work in progress!

Introduction
The Sketcher is a tool to generate 2D-objects for usage in parts design. The sketcher is different to traditional drawing tools. A way to show the difference is the construction of a triangle. A triangle is fully defined by 3 values, which can be any from the following list: side length, angle, height, area. The one exception is three angles, which will not define the size.

In order to construct a triangle from 3 length in the traditional way, the following has to be done:
 * draw the base line
 * make two circles with a radius given by the other two side lengths, or alternatively calculate the coordinates of the third vertex
 * draw the missing two sides from the endpooints of the base line to the crossing point of the two circles or the calculated vertex.



The Triangle page shows a collection of formulas to calculate the missing information in order to draw a triangle from the minimum specification. Those are needed, if the triangle has to be defined by precalculated coordinates.

The Sketcher is different. The formulas and the above helper constructions are not needed. In order to understand the difference, it is best to construct a triangle by yourself.

First sketch: a triangle
An open document is needed in order to make a sketch. When there is no open document, a new one will be created by clicking on The sketcher workbench has to be selected:



A new sketch will be created by clicking at. A dialog appears, where the oriention of the new sketch in the 3D-space can be selected. It doesn't matter in this case, so the xy-plane can be confirmed. A new empty sketch will be created and opened in edit mode. A grid with a coordinate system will be shown with a red point at the origin.

In the Sketcher it is ok to draw an arbitrary triangle with the polyline tool and define its properties in a later step. Each click in the drawing plane sets a vertex. The triangle needs to be closed. So for the last line a click is needed on the first created vertex. A red point should be visible near the mouse pointer before clicking.



This will make sure, that the last vertex is identical to the first one and the profile is closed. Those symbols that appear beneath the drawing pointer do indicate auto-constraints. They are set automatically at clicking at this location. The red dot beneath the drawing pointer indicates a coincidence constraint between two vertices. The vertices of this different drawing elements should have an identical location.

The created triangle is flexible. A vertex can be touched with the mouse and dragged around. The sides of the triangle follow the vertex. The same can be done with a line.

Each lenght of the side is now easy defined by selecting it with the mouse: selected item turns green. And then clicking on the length tool. A dialog opens and the wanted length can be put in. The picture below shows a triangle with side lengths set to 35 mm, 27 mm and 25 mm. The baseline was set horizontally by selecting it and clicking on the horizontal constraint tool.

These length-definitions are called constraints. Constraints are used to define a fixed design from the flexible geometric input. The sketcher provides all constraints needed to define any kind of triangle. Only the area can not be used to define one. So the created triangle can be redefined by changing the value of a constraint or by deleting constraints and add other ones. Here comes a list of triangles with other given properties. It is no problem to turn the just created triangle into one of these.


 * One or two angles given: Two sides of the triangle needs to be selected. A click on [[Image:Constraint_InternalAngle.png|32px]] opens a dialog to define the angle.




 * Right triangle: Two sides of the triangle needs to be selected. A click on[[Image:Constraint_Perpendicular.png|32px]] sets a right angle between the two sides.




 * Equilateral: One side has to be set to a defined length. Then all sides needs to be selected. A click on[[Image:Constraint_EqualLength.png|32px]] defines two equal length constrains in order to give all sides the same length.




 * Isosceles triangle (two identical length) with given height: Select first the two sides with the equal length. A click on [[Image:Constraint_Symmetric.png|32px]] sets a equality between the two sides. Then select the base line and the top vertex and click the [[Image:Constraint_Length.png|32px]] length tool.



Constraints can be selected by clicking on the symbol or by clicking in the constraint-list. They can be deleted or in case of contraints with a value edited after a double click. A given triangle can be later changed into another type of triangle by editing or changing the constraints. The sketcher is a part of the parametric FreeCAD-modelling approach. What you have created, can be easily changed at a later time, if for example a variant of the design is needed.

The above shown triangles have white lines. This is a sign, that the sketch has some degrees of freedom left. It can be tested by dragging on some lines or points. If the line or point moves, this item is not fully defined. A sketch with no degrees of freedom left turns green.

The isoscele triangle is missing the length setting for the base line and it can move and rotate freely in the sketcher drawing plane.

If the triangle properties are defined, it still needed to be fixed in the drawing plane. The sketcher drawing plane has a coordinate system. The origin of the coordinate system is visable as the red dot in the center of the pink x-axis and light-green y-axis. The easiest way to fix it, is selecting a vertex and clicking at. This adds a horizontal and a vertical distance from the vertex to the origin of the coordinate system. The triangle may still have an degree of freedom for rotation. So one sides needs a horizontal or vertical constraint or an defined angle to one of the coordinate system axes. The next picture shows a fully constraint sketch. All lines and vertices have now a green color.



Profiles for solid parts
closed profiles no intersection of lines

Construction lines
helper lines to define more complex profiles

External Geometry
One of the main usage of the Sketcher is the construction of parts in the Part-Design-workbench. There allready existing geometry can be used similar to construction lines. As this tutorial takes its focus more on the basic sketcher functionality, have a look here for usage of external geometry: Sketcher_External

More about Constraints
The sketcher does not know the triangle formulas from the wikipedia. Instead it sets up a system of equation for the 2-dimensional coordinates based on the given constraints. This system of equations is then solved numerically.

In this way a wide variety of geometric problem can be solved. But there is also a disadvantage. If the set of equations has multiple solutions, we may get something totally different from what we expect. This is especially annoying, if the same design should be used for different dimensions. The typical symptom is that after a change of a length constraint the sketch flips to something totally different. A simple example is the division of a distance into three equal partitions. The following picture shows three lines in a row with equality and parallel constraint set. The total distance is set to 10 mm.



This works well, as long as only larger distances are put in. When the distance is reduced above a certain ratio, the lines are folding together. So we do not get anymore a third of the given distance but the distance itself or two third of it. Some lines of our row have changed their orientation. This gives still a valid solution for the set of constraints, but is not what was intended. So following image of the same sketch shows this. The length constraint was set to 1000 mm and then reduced to 5 mm.



The solution is to define an angle of 180° between the partition lines as replacement of the parallel constraint. The 180°-constraint has only one solution. The sketch is now robust against large changes of the distance. It has to be said, that also a 0°-constraint serves for the same purpose, where appropriate.

Image 180°

The 180°-constraint is the solution for a lot of problems, but comes not without a disadvantage. FreeCAD has problems to show the 180°-constraint in the sketcher plane. In most of the cases the 180°-arc is not shown as expected in the sketcher drawing plane. This is a known issue for FreeCAD version 14. It is not clear, if this issue can be fixed.

In case of several incremental dimensions in a straight line, it may be advisable to draw a zig-zag-line first and then set the 180°-constraints. This helps, not forgetting one, or setting one twice.

It is also possible to set a 180°-constraint for two parallel lines without an intersection point. This works nearly perfect, but then the "fit hole content on the screen" button  should not be used. Otherwise FreeCAD makes a viewport with a size of millions of km, where it is difficult to find the sketch again. Those two lines have now an intersection point in "infinity" and FreeCAD tries to show both the 180°-constraint at infinity distance and the sketch on the screen, which is not useful in this case.

Problematic combination of constraints

Another possible approch to make three equal partitions, is to nest two symmetries. Image Experience show, that this approach is a hard numerical problem for the solver. The sketch may freeze. This approach should be avoided.

Another problem is the change of orientation of angles. This can happen if, angle changes above 180° are made.

So in general it can be recommended, to set the constraints in a clear tree dependency. Circle dependencies are more problematic.

Often there are more than one possibility to set a constraint. Those should be selected, that have only solution for the geometry.

Construction Lines do not forget to make subsection

In the first part was shown, that helper constructions are not necessary for the triangle. But nevertheless the sketcher provides construction geometry, which is useful for more complex problems. Any line can be converted to a construction line with the button. The construction lines are shown in the sketch as blue lines. They can be used for constraints in the same way as other lines, but are not shown and not used when the sketch is closed.

example traditional drafting dividing a line in three parts.

Exercise: resilient sketch do not forget to make subsection

Frame 3D-Image

Image with horizontal constraints

Image with distorted sketch