Draft CubicBezCurve: Difference between revisions

From FreeCAD Documentation
(Image 600px)
(the fourth point in each segment is defined implicitly;)
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
{{UnfinishedDocu}}
<translate>
<translate>


<!--T:1-->
<!--T:1-->
{{Docnav|[[Draft BezCurve|BezCurve]]|[[Draft_Label|Label]]|[[Draft_Module|Draft]]|IconL=Draft BezCurve.svg|IconC=Workbench_Draft.svg|IconR=Draft_Label.svg }}
{{Docnav|[[Draft BezCurve|BezCurve]]|[[Draft_Label|Label]]|[[Draft_Module|Draft]]|IconL=Draft BezCurve.svg|IconC=Workbench_Draft.svg|IconR=Draft_Label.svg }}



<!--T:2-->
<!--T:2-->
Line 18: Line 16:


<!--T:4-->
<!--T:4-->
The [[Draft CubicBezCurve|CubicBezCurve]] tool creates a [http://en.wikipedia.org/wiki/Bezier_curve Bezier Curve] of third degree. This is one of the most commonly used curves in computer graphics applications. This tool allows you to create a big spline made of several 3rd-degree Bezier segments, in a way that is similar to the Bezier tool in Inkscape. A general Bezier curve of any degree can be created with [[Draft BezCurve|Draft BezCurve]].
The [[Draft CubicBezCurve|CubicBezCurve]] tool creates a [http://en.wikipedia.org/wiki/Bezier_curve Bezier Curve] of third degree (four points required). This is one of the most commonly used curves in computer graphics applications. This tool allows you to create a big spline made of several 3rd-degree Bezier segments, in a way that is similar to the Bezier tool in Inkscape. A general Bezier curve of any degree can be created with [[Draft BezCurve|Draft BezCurve]].


<!--T:5-->
<!--T:5-->
Line 24: Line 22:


</translate>
</translate>
[[Image:cub_bez_curve.png|263px]]
[[File:Draft_CubicBezCurve_example.png|600px]]
<translate>
<translate>
<!--T:6-->
<!--T:6-->
{{Caption|Spline defined by three cubic Bezier segments. Each cubic Bezier 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 Bezier segment if the operation is continued.}}
{{Caption|Cubic Bezier curve defined by three control points}}


==How to use== <!--T:7-->
==How to use== <!--T:7-->
Line 39: Line 37:
# At this moment you already have one Bezier curve of 3rd degree. The command can be completed by pressing {{KEY|Esc}} or the {{Button|Close}} button, or you may repeat the process of clicking and holding (5), and dragging and releasing (6) to add more 3rd-degree Bezier segments.
# At this moment you already have one Bezier curve of 3rd degree. The command can be completed by pressing {{KEY|Esc}} or the {{Button|Close}} button, or you may repeat the process of clicking and holding (5), and dragging and releasing (6) to add more 3rd-degree Bezier segments.


<!--T:21-->
Note that with this workflow you need two click-hold-release sequences to create a single Bezier curve of third degree.
Note that with this workflow you need two click-hold-release sequences to create a single Bezier curve of third degree.
* The first click-hold defines the first end point.
* The first click-hold defines the first end point.
Line 46: Line 45:
* The second control point is not explicitly given, but is determined from the location of the pointer during the second release.
* The second control point is not explicitly given, but is determined from the location of the pointer during the second release.


=== Note when creating many Bezier segments ===
=== Note when creating many Bezier segments === <!--T:22-->


<!--T:23-->
* The second release also correspond to the first control point of the subsequent Bezier curve.
* The second release also correspond to the first control point of the subsequent Bezier curve.
* This means that the second click-hold was also the first end point of the second Bezier curve.
* This means that the second click-hold was also the first end point of the second Bezier curve.
Line 53: Line 53:
* 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.
* 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.


<!--T:24-->
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:
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:


Line 64: Line 65:
<translate>
<translate>


=== How to place the control points exactly ===
=== How to place the control points exactly === <!--T:25-->


<!--T:26-->
The graphical operation of this tool only allows the user to specify the first control point of the curve when it is being drawn. The second control point can be adjusted after the object is created: double click on the curve object in tree view, or select it and press {{Button|[[File:Draft_Edit.svg|16px]] [[Draft Edit|Edit]]}}. Then drag the second control point to the desired position.
The graphical operation of this tool only allows the user to specify the first control point of the curve when it is being drawn. The second control point can be adjusted after the object is created: double click on the curve object in tree view, or select it and press {{Button|[[File:Draft_Edit.svg|16px]] [[Draft Edit|Edit]]}}. Then drag the second control point to the desired position.


<!--T:27-->
In order to choose exactly both end points and both control points, the Python command {{incode|Draft.makeBezCurve()}} must be used. See the [[#Scripting|Scripting]] section.
In order to choose exactly both end points and both control points, the Python command {{incode|Draft.makeBezCurve()}} must be used. See the [[#Scripting|Scripting]] section.


==Options== <!--T:9-->
==Options== <!--T:9-->


<!--T:28-->
See the options in [[Draft BezCurve|Draft BezCurve]].
See the options in [[Draft BezCurve|Draft BezCurve]].


==Properties== <!--T:10-->
==Properties== <!--T:10-->


<!--T:29-->
See the properties in [[Draft BezCurve|Draft BezCurve]].
See the properties in [[Draft BezCurve|Draft BezCurve]].


Line 100: Line 105:
<translate>
<translate>


<!--T:30-->
{{Caption|Examples of Bezier curves produced by using 2, 3, 4, 5, 6, 7, and 8 points. The solid lines indicate cubic Bezier segments; the other lines are quadratic or linear.}}
{{Caption|Examples of Bezier curves produced by using 2, 3, 4, 5, 6, 7, and 8 points. The solid lines indicate cubic Bezier segments; the other lines are quadratic or linear.}}



Revision as of 17:50, 19 September 2019

Draft CubicBezCurve

Menu location
Draft → Bezier tools → CubicBezCurve
Workbenches
Draft, Arch
Default shortcut
None
Introduced in version
0.19
See also
Draft Wire, Draft BSpline, Draft BezCurve

Description

The CubicBezCurve tool creates a Bezier Curve of third degree (four points required). This is one of the most commonly used curves in computer graphics applications. This tool allows you to create a big spline made of several 3rd-degree Bezier segments, in a way that is similar to the Bezier tool in Inkscape. A general Bezier curve of any degree can be created with Draft BezCurve.

The Draft BezCurve and the Draft CubicBezCurve tools use control points to define the position and curvature of the spline; on the other hand the Draft BSpline tool specifies the exact points through which the curve will go.

Spline defined by three cubic Bezier segments. Each cubic Bezier 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 Bezier segment if the operation is continued.

How to use

  1. Press the Draft CubicBezCurve button.
  2. Click a first point on the 3D view, and hold the mouse button (1); this is the first end point.
  3. Drag the pointer to another point on the 3D view, and release the mouse button (2); this is the first control point.
  4. Move the pointer to another point on the 3D view, and click and hold the mouse button on this point (3); this is the second end point.
  5. Move the pointer to another point on the 3D view to adjust the final curvature of the spline, and then release the mouse button (4).
  6. At this moment you already have one Bezier 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 Bezier segments.

Note that with this workflow you need two click-hold-release sequences to create a single Bezier curve of third degree.

  • The first click-hold defines the first end point.
  • The first release defines the first control point.
  • The second click-hold defines the second end point, and the general direction of the spline.
  • The second release defines the final curvature of the spline.
  • The second control point is not explicitly given, but is determined from the location of the pointer during the second release.

Note when creating many Bezier segments

  • The second release also correspond to the first control point of the subsequent Bezier curve.
  • This means that the second click-hold was also the first end point of the second Bezier 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

How to place the control points exactly

The graphical operation of this tool only allows the user to specify the first control point of the curve when it is being drawn. The second control point can be adjusted after the object is created: double click on the curve object in tree view, or select it and press Edit. Then drag the second control point to the desired position.

In order to choose exactly both end points and both control points, the Python command Draft.makeBezCurve() must be used. See the Scripting section.

Options

See the options in Draft BezCurve.

Properties

See the properties in Draft BezCurve.

Scripting

See also: Draft API and FreeCAD Scripting Basics.

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

For each cubic Bezier 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 Bezier instead, with only one control point.
  • If only 2 points are given, it creates a linear Bezier, that is, a straight line.
  • If 5 points are given, the first 4 create a cubic Bezier 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 Bezier segment; the 4th and the other two points are used to create a quadratic Bezier segment.
  • If 7 points are given, the first 4 create a cubic Bezier segment; the 4th and the other three points are used to create a second cubic Bezier segment.
  • In general, the last point in a group of four is shared with the following three points maximum to create another Bezier 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 Bezier curves produced by using 2, 3, 4, 5, 6, 7, and 8 points. The solid lines indicate cubic Bezier 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.makeCircle(100, placement=App.Placement(p1, rot), face=False)
c1.Label = "B1_E1"
c2 = Draft.makeCircle(50, placement=App.Placement(p2, rot), face=True)
c2.Label = "B1_c1"
c3 = Draft.makeCircle(50, placement=App.Placement(p3, rot), face=True)
c3.Label = "B1_c2"
c4 = Draft.makeCircle(100, placement=App.Placement(p4, rot), face=False)
c4.Label = "B1_E2"
c5 = Draft.makeCircle(50, placement=App.Placement(p5, rot), face=True)
c5.Label = "B2_c3"
c6 = Draft.makeCircle(50, placement=App.Placement(p6, rot), face=True)
c6.Label = "B2_c4"
c7 = Draft.makeCircle(100, placement=App.Placement(p7, rot), face=False)
c7.Label = "B2_E3"
c8 = Draft.makeCircle(50, placement=App.Placement(p8, rot), face=True)
c8.Label = "B3_c5"
App.ActiveDocument.recompute()

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

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

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

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

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

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

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