Draft CubicBezCurve

From FreeCAD Documentation
Revision as of 19:18, 1 May 2021 by Roy 043 (talk | contribs) (Removed the "How to exactly place the control points". Faulty information. The 2nd control point can be placed exactly. It is just stored by reversing the vector between it and the 2nd endpoint.)
This documentation is a work in progress. Please don't mark it as translatable since it will change in the next hours and days.

Draft CubicBezCurve

Menu location
Drafting → Bézier tools → Cubic Bézier curve
Workbenches
Draft, Arch
Default shortcut
None
Introduced in version
0.19
See also
Draft BezCurve, Draft BSpline

Description

The Draft CubicBezCurve command creates a Bézier Curve of the third degree (four points required). It uses the Draft Linestyle set on the Draft Tray.

The Bézier Curve is one of the most commonly used curves in computer graphics. This command allows you to create a continuous spline made up of several 3rd-degree Bézier segments, in a way that is similar to the Bézier tool in Inkscape. A general Bézier curve of any degree can be created with the Draft BezCurve command.

The Draft BezCurve and the Draft CubicBezCurve commands use control points to define the position and curvature of the spline. The Draft BSpline command, on the other hand, specifies the exact points through which the curve will pass.

Spline defined by three cubic Bézier segments. Each cubic Bézier is defined by four points, but when the tool is used graphically, only three such points are placed: 1-2-3 for the first segment, 3-4-5 for the second segment, and 5-6-7 for the third segment; the fourth point in each segment is defined implicitly; the last point 8 is necessary to finish the operation, and would be part of a fourth Bézier segment if the operation is continued.

Usage

  1. There are several ways to invoke the command:
    • Press the Draft CubicBezCurve button.
    • Select the Drafting → Bézier tools → Cubic Bézier curve option from the menu.
  2. For the following Mouse Navigation Models a keyboard key has to be held down:
    • If you are using OpenInventor Navigation the Ctrl key must be held down throughout the command.
    • If you are using Gesture Navigation the Alt key must be held down for each click-hold-release sequence, but is also possible to keep this key held down throughout the command.
  3. Click the first point in the 3D view, and hold the mouse button (1); this is the first end point.
  4. Drag the pointer to another point in the 3D view, and release the mouse button (2); this is the first control point.
  5. Move the pointer to another point in the 3D view, and click and hold the mouse button on this point (3); this is the second end point.
  6. Move the pointer to another point in the 3D view to adjust the final curvature of the spline, and then release the mouse button (4).
  7. At this moment you already have one Bézier curve of 3rd degree. The command can be completed by pressing Esc or the Close button, or you may repeat the process of clicking and holding (5), and dragging and releasing (6) to add more 3rd-degree Bézier segments.

Notes

Creating several Bézier segments

  • The second release also correspond to the first control point of the subsequent Bézier curve.
  • This means that the second click-hold was also the first end point of the second Bézier curve.
  • A third click-hold would be the second end point.
  • A third release would define the final curvature of the second curve, and it would also be the first control point of a third curve.

This means that for every two click-hold (c-h) and release (r) sequences, the second sequence is already part of a subsequent curve segment, as indicated in the following graphic:

|c-h -- r -- c-h -- r| 1
            |c-h -- r -- c-h -- r| 2
                        |c-h -- r -- c-h -- r| 3
                                    |c-h -- r -- c-h -- r| 4

Options

See the options of the Draft BezCurve command.

Properties

A Draft CubicBezCurve is a Draft BezCurve of the third degree and has the same properties.

Scripting

See also: Autogenerated API documentation and FreeCAD Scripting Basics.

See Draft BezCurve for general information. A cubic Bézier is created by passing the option degree=3 to makeBezCurve().

For each cubic Bézier segment four points must be used, of which the two extreme points indicate where the spline passes through, and the two intermediate points are control points.

  • If only 3 points are given, it creates a quadratic Bézier instead, with only one control point.
  • If only 2 points are given, it creates a linear Bézier, that is, a straight line.
  • If 5 points are given, the first 4 create a cubic Bézier segment; the 4th and the 5th points are used to create a straight line.
  • If 6 points are given, the first 4 create a cubic Bézier segment; the 4th and the other two points are used to create a quadratic Bézier segment.
  • If 7 points are given, the first 4 create a cubic Bézier segment; the 4th and the other three points are used to create a second cubic Bézier segment.
  • In general, the last point in a group of four is shared with the following three points maximum to create another Bézier segment.
  • To have smooth curves, with no straight segments, the number of points should be 3n + 1 or 3n, where n is the number of segments, for n >= 1.

Examples of Bézier curves produced by using 2, 3, 4, 5, 6, 7, and 8 points. The solid lines indicate cubic Bézier segments; the other lines are quadratic or linear.

Example:

import FreeCAD as App
import Draft

p1 = App.Vector(-3500, 0, 0)
p2 = App.Vector(-3000, 2000, 0)
p3 = App.Vector(-1100, 2000, 0)
p4 = App.Vector(0, 0, 0)

p5 = App.Vector(1500, -2000, 0)
p6 = App.Vector(3000, -1500, 0)
p7 = App.Vector(5000, 0, 0)
p8 = App.Vector(6000, 1500, 0)
rot = App.Rotation()

c1 = Draft.make_circle(100, placement=App.Placement(p1, rot), face=False)
c1.Label = "B1_E1"
c2 = Draft.make_circle(50, placement=App.Placement(p2, rot), face=True)
c2.Label = "B1_c1"
c3 = Draft.make_circle(50, placement=App.Placement(p3, rot), face=True)
c3.Label = "B1_c2"
c4 = Draft.make_circle(100, placement=App.Placement(p4, rot), face=False)
c4.Label = "B1_E2"
c5 = Draft.make_circle(50, placement=App.Placement(p5, rot), face=True)
c5.Label = "B2_c3"
c6 = Draft.make_circle(50, placement=App.Placement(p6, rot), face=True)
c6.Label = "B2_c4"
c7 = Draft.make_circle(100, placement=App.Placement(p7, rot), face=False)
c7.Label = "B2_E3"
c8 = Draft.make_circle(50, placement=App.Placement(p8, rot), face=True)
c8.Label = "B3_c5"

App.ActiveDocument.recompute()

B1 = Draft.make_bezcurve([p1, p2], degree=3)
B1.Label = "B_lin"
B1.ViewObject.DrawStyle = "Dashed"

B2 = Draft.make_bezcurve([p1, p2, p3], degree=3)
B2.Label = "B_quad"
B2.ViewObject.DrawStyle = "Dotted"

B3 = Draft.make_bezcurve([p1, p2, p3, p4], degree=3)
B3.Label = "B_cub"
B3.ViewObject.LineWidth = 4

B4 = Draft.make_bezcurve([p1, p2, p3, p4, p5], degree=3)
B4.Label = "B_cub+lin"
B4.ViewObject.DrawStyle = "Dashed"

B5 = Draft.make_bezcurve([p1, p2, p3, p4, p5, p6], degree=3)
B5.Label = "B_cub+quad"
B5.ViewObject.DrawStyle = "Dotted"

B6 = Draft.make_bezcurve([p1, p2, p3, p4, p5, p6, p7], degree=3)
B6.Label = "B_cub+cub"
B6.ViewObject.LineWidth = 2

B7 = Draft.make_bezcurve([p1, p2, p3, p4, p5, p6, p7, p8], degree=3)
B7.Label = "B_cub+cub+lin"
B7.ViewObject.DrawStyle = "Dashed"

App.ActiveDocument.recompute()