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 an equation system for the 2-dimensional coordinates based on the given constraints. This equations system 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. So after a change of a length constraint the sketch flips to something totally different. An example is the division of a distance into three equal partitions. The following picture shows three lines in a row with equalty and parallel constraint set.

Image This works well, as long as only larger distance 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 thanged their orientation. This gives still a valid solution for the set of constraints, but is not what was intended.

Image folded row

A solution is to define an angle of 180° between the lines. This constraint has only one solution. The sketch is robust against large changes of the distance. Image 180°

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.