What to use instead of Boolean operations. Generalization of operations to Boolean algebra. Socket for spanner

BOOLEAN OPERATION

A Boolean operation is designed to create a new body based on two or more existing bodies. As a result of the operation, a new body is created, which is a combination of the original bodies. There are three ways to combine source bodies: addition, subtraction and intersection. The result of the “addition” operation will be a body that includes a part that only the first body has, a part that only the second body has, and a part that is common to both bodies. The result of the “subtraction” operation will be a body, which is the subtraction of the second body from the first, and will consist of a part that only the first body has. The result of the “intersection” operation will be a body that is the intersection of two bodies, and will consist only of a part that is common to both bodies.

Specifying a Boolean Operation

To specify a Boolean operation, use the command “3B:Create a Boolean Operation”. Calling the command:

After calling the command it becomes possible choice one of two options:

Select multiple operations.

Each option determines how to create a Boolean operation. There are two ways

- creating a Boolean operation based on two bodies (option )

- creating a Boolean operation based on several bodies (option )

When calling the command, the “Select first body” option is always activated.

There is another way to call the command: Move the cursor to one of the model operations and

click and select “Create” in the menu that appears. A list of possible commands will appear that can be invoked when you select an operation. Select “Create Boolean Operation”, and the selected body will be the first selected element of the command.

3D modeling

In this case, you can create an operation based on only two bodies.

Creating a Boolean operation based on two bodies

When performing a Boolean operation based on two bodies, you must perform the following steps:

1. Select the first body.

2. Select the second body.

3. Select the type of operation (addition, subtraction, intersection).

4. Complete entry.

The first body is selected using the option

Select the first body.

After selecting the first body, the following options become available:

Select the second body.

Deselect the second operand of a Boolean operation.

Boolean operation

The example shown shows a drawing of a part for which the necessary three-dimensional constructions have been performed and two bodies have been created using the extrusion and rotation operations. The figures show situations that arise when in various ways performing a Boolean operation. The above figure (image on the right) shows the result of the addition operation. The result of this operation is visually no different from the initial state, when there were two dissimilar bodies. But performing a Boolean operation is necessary for the constructed object to become a single whole. Then you can count various characteristics of this body: volume, surface area, etc. The source bodies can use different materials, but the resulting body has a single material.

The bottom figure shows the result of the subtraction operation on the left, and the intersection on the right.

It should be noted that the first time a Boolean operation command is executed after starting the program, the type of Boolean operation “Addition” is automatically set in the automenu. When the command to create a Boolean operation is called again, the button corresponding to the type of Boolean operation selected the last time the command was called will be pressed.

Creating Copies of Original Operations

Bodies selected to perform one Boolean operation become unavailable for another. The body obtained as a result of the Boolean operation becomes available. In certain cases, it is necessary to use the same body repeatedly in different operations. There is an option to provide this option

Create a copy of the original transactions.

When this option is called, a dialog box appears where you need to indicate which of the selected bodies we want to create a copy of.

3D modeling

If the "Create a copy" option was called, then a special action is performed before executing the Boolean operation. As a result of this action, bodies are created - copies of the original bodies, which can be used in the future. Let us explain the above with an example. The figure shows the original 2D constructions and the two Boolean operations created.

First, three bodies were created: two parallelepipeds based on a rectangular profile and a cylinder. Then a Boolean operation was performed to subtract from the first parallelepiped of the cylinder. As a result, a parallelepiped with a hole was formed. But the same operation must be performed with the second parallelepiped. To do this, at the stage of performing the first Boolean operation, we used the “Create a copy” option for the second body (cylinder). Therefore, after the first Boolean operation, there are still three bodies left: a parallelepiped with a hole, a second parallelepiped and a copy of the cylinder. Then we performed a second Boolean operation between the parallelepiped and the cylinder.

Creating a Boolean operation based on multiple bodies

After calling the command in the automenu, the option becomes available

Select multiple operations.

This option sets the mode for creating a Boolean operation based on several bodies. It also makes available the option

Using this option, you need to alternately select several bodies that will take part in the Boolean operation. Moreover, the first selected body will be the first operand of the Boolean operation.

For example: if you have selected several bodies, the system will create several Boolean operations, the first of them will be the operation with the first and second body. Subsequent ones use the operation created in the previous step as the first operand and the next body, according to the order in which they were selected.

You can deselect all operations using the option

<К>Deselect operations.

On bodies, as well as on other geometric objects, you can perform operations - a set of actions on one or more original bodies, which leads to the birth of a new body. One of the main operations for two bodies is Boolean operations.

Boolean operations are called the operations of union, intersection and subtraction of bodies, since they perform the same operations on the internal volumes of bodies (over sets of points in space located inside the bodies). The Boolean operation of combining bodies will be denoted by the formula , where are the original bodies, S is the resulting body. The Boolean operation of intersection of bodies will be denoted by the formula. The Boolean operation of subtracting bodies will be denoted by the formula. In the order of the operand bodies, we will call them the first body and the second body.

Rice. 6.6.1. Two source bodies

Rice. 6.6.2. Merging bodies

The result of the operation of combining two bodies is a body that contains points belonging to the internal volume of either the first or second body. The result of the operation of intersection of two bodies is a body that contains points belonging to the internal volume of both the first and second bodies.

The result of the operation of subtracting two bodies is a body that contains points that belong to the internal volume of the first body, but do not belong to the internal volume of the second body.

In Fig. 6.6.1 shows the initial bodies for the Boolean operation. In Fig. 6.6.2 shows the result of the operation of combining bodies, in Fig. 6.6.3 shows the result of the intersection operation, in Fig. 6.6.4 and 6.6.5 show the results of the operation of subtracting bodies.

The operation of subtracting bodies can be reduced to the operation of intersecting bodies; To do this, you need to turn the second body inside out and find points of its volume that simultaneously belong to the volume of the first body. A body S turned inside out will be denoted by

Rice. 6.6.3. Crossing bodies

Rice. 6.6.4. Body difference

Rice. 6.6.5. Body difference

When turning the body inside out internal sides the faces become the outer sides, and the outer ones become the inner ones and the directions of the cycles change to the opposite, as a result of which the internal volume of the body becomes that part of the space that was previously located outside the body. Mathematically, the operation of subtraction is reduced to the operation of intersection of bodies. When designing, the designer uses the operations of union and subtraction (they can be called differently, for example, welding and drilling operations), and the mathematical apparatus performs the operations of union and intersection, respectively. All Boolean operations contain much in common and are performed using a single algorithm.

Merging bodies

Let's consider the Boolean operation of combining bodies. The essence of the operation can be briefly described as follows: you need to find the intersection lines of the faces of the bodies, remove that part of the first body that got inside the second body and that part of the second body that got inside the first body, and build a new body from the rest. We will conditionally divide the operation into three stages. At the first stage, we will construct lines of intersection of the surfaces of the faces and, on their basis, new edges. The constructed new edges will be called intersection edges, and the edges of the bodies will be called old edges. At the second stage, we will determine the intersection points of the new edges with the old edges and at these points we will cut the old edges into several edges. At the third stage of the operation, we will rebuild the cycles of the intersecting faces. After this, we add to the intersecting faces of the bodies the faces that are topologically connected by them. Let's look at the stages of body building in more detail.

We begin the first stage of the operation of combining bodies by constructing the lines of intersection of each face of the first body with each face of the second body, if any. To do this, we use an algorithm for intersecting face surfaces.

Let the faces of the first body be described by surfaces

and the faces of the second body are described by surfaces

Based on the intersection lines of the faces of the first and second bodies

(6.6.3)

Let's construct intersection edges. In this case, we give the intersection edges the direction of the vector product of the normal of the face of the first body with the normal of the face of the second body: The direction of the edge is determined by the sign that the direction of the derivative of the intersection line coincides with the required direction of the edge. For the positive direction of the face normal we take the direction outward of the body. The normal of a face can coincide with the normal of its surface or have the opposite direction, depending on the sign of their coincidence. In Fig. 6.6.6 shows the directions of the edges of intersection of the face of the first body with two faces of the second body.

The intersection edges must be constructed so that they lie completely inside the cycles of the faces of the original bodies. Intersection edges can only approach the edges of a face at their ends. At points A, B and C (Fig. 6.6.6), the old edges of the faces must each be divided into two edges, since only part of the original face will be included in the resulting body.

At the second stage, we cut the old edges of the body, to which the intersection edges fit. Cutting an old rib is done by cutting the curve on which the rib is based. From one curve we obtain two curves, which together replace the original edge curve. One of these curves will remain the geometric carrier of the cut edge, and on the basis of the second we will construct a new edge, which will receive all the necessary information from the original edge. As was said, each edge is built on the basis of the surface intersection curve (6.1.1). A surface intersection curve consists of two surfaces and two corresponding two-dimensional curves. It is precisely two-dimensional curves on two different surfaces that are subject to dissection. Both before and after dissection, these curves must have the same parameter definition areas and correspondence of points for all parameter values.

The intersection points of the new edge with the old edge of the face are sought as the intersection points of two-dimensional curves defined on the parameter plane common to them. From each edge in formula (4.8.6) of the points of intersection of lines, one two-dimensional curve is included in the intersection line.

The parameters of the intersection points of the edges and the coordinates of the curves themselves, which are surface parameters, must be determined with a given accuracy.

If the edge being cut is based on an intersection curve defined by individual points (two-dimensional lines are broken lines and exactly coincide in space only at characteristic points), then before cutting such a curve, additional points must be inserted into both lines, corresponding to the intersection points of three surfaces - two surfaces , lying on both sides of the cut edge, and the surface of the face of another original body. For example, if the line of intersection of surfaces with surface is cut, then additional two-dimensional characteristic points corresponding to the intersection of surfaces must be inserted into the lines. The problem of intersection of three surfaces is reduced to solving a system of six scalar equations (4.12.5) with respect to six parameters. The initial approximation of the solution is known quite accurately.

Since each edge of the original bodies is included in the cycles of two adjacent faces, then after cutting the edges of the original bodies it is necessary to adjust these cycles taking into account the cut edges.

After the first two stages, we received a set of intersection edges, oriented in a certain way, joining each other and with the edges of the original bodies only at the vertices. Next, you need to rebuild the cycles of the intersecting edges.

The third stage completes the Boolean operation. In order for each of those shown in Fig. 6.6.6 faces are cut into parts, you need to rebuild its cycles and, in accordance with the cycles, change the contours that describe the area for determining the surface parameters of the face. In Fig. 6.6.7 shows two intersecting faces (thin lines with arrows show the direction of cycles of the faces of the original bodies) and the intersection edge. In Fig. Figure 6.6.8 shows those parts of the faces that will be included in the union of bodies.

Rice. 6.6.7. Initial body faces

Rice. 6.6.8. Trimmed Edges

The arrows show the direction of the reconstructed cycles of the body faces. Each loop is a list of edges in the order they appear and a list of orientation flags for those edges in the loop.

It can be seen from the figure that with the accepted orientation of the intersection edges (), they will enter the cycles of the faces of the first body with a negative flag, and they will enter the cycles of the faces of the second body with a positive flag.

The old edges of the original bodies, which will be preserved in the resulting body, will enter the rebuilt cycles, retaining their flags. When rebuilding cycles of intersecting faces, we will use the following algorithm.

Let's consider one of the two intersecting faces belonging to the first body. We take any edge of intersection of the face under consideration and start compiling a list of cycle edges from it. The intersection edge must enter the face cycle of the first body with a negative flag, therefore the cycle will have the opposite direction to the first edge. To continue the cycle, among the intersection edges and among the old edges of the face, we look for all the edges that connect with a given edge at its initial vertex. Among the found edges, we choose the one that lies to the left of the others (turns to the left at a larger angle compared to other found edges, if viewed along the cycle with outside edges). We put the selected edge in the cycle list. If the selected edge is old, then it retains its flag in the loop. If the selected edge is an intersection edge, it will receive a negative flag. Intersection edges have priority over old edges to be selected. That is, if there are two matching edges to the left of the others, one of which is the old one and the other is the intersection edge, then the intersection edge must be selected to continue the cycle.

We will continue the process of rebuilding the face cycle until the cycle is closed. This completes the construction of the next cycle. If not all intersection edges of the face under consideration were used when constructing the cycle, then we begin to build another cycle of the face from any of the remaining intersection edges. We rebuild the cycles until we use all the intersection edges. In this way we will build in general case several new cycles of the considered face of the first body.

It is convenient to search for joining edges and determine the angle of rotation at the junction point using the two-dimensional curves of the edges of the face. In this case, you can even work with edges that are contracted in space to a point (for example, an edge at the vertex of a cone or the pole of a sphere). In Fig. 6.6.9 shows that several edges join the new edge BA at point A. In this case, to continue the cycle started from the intersection edge BA A, edge AC should be selected.

We sort the newly constructed cycles into groups, each of which consists of an outer cycle and its internal cycles. The face in question may have one or more old cycles left intact. We will call untouched the old cycles of a face, not a single edge of which was included in the reconstructed cycles. Among the old untouched cycles, we will select those that need to be included in the description of the reconstructed face. They are the old inner cycles of the face lying inside the new outer cycles. We also need to determine whether the old outer edge loop will need to be included in the result if it remains intact. This must be done if for some new inner loops a new outer loop is not found and they lie inside the old outer loop. Sorting cycles is conveniently done using two-dimensional contours corresponding to each cycle.

If, as a result of sorting the outer cycles, more than one was obtained, this means that several faces were formed from the original face as a result of the operation. In Fig. 6.6.10 a - 6.6.13 a show options for the initial faces of the first body.

In Fig. 6.6.10 b-6.6.13 b. faces with added intersection edges are shown (intersection edges are highlighted). In Fig. 6.6.10 in - 6.6.13 in show the faces that resulted from the operation.

Rice. 6.6.10. Original face (a), face c. by adding intersection edges (b), the result of operation (b)

Rice. 6.6.11. The original face (a), the face with the addition of intersection edges (b), the result of the operation (c)

Rice. 6.6.12. The original face (a), the face with the addition of intersection edges (b), the result of the operation (c)

Rice. 6.6.13. The original face (a), the face with the addition of intersection edges (b), the result of the operation (c)

In Fig. 6.6.10, a face with two cycles was cut to produce one face with one cycle. In Fig. 6.6.11 a face with two cycles gave two faces. In the example shown in Fig. 6.6.12, it was necessary to use the old outer and inner loops. In Fig. 6.6.13 two faces were obtained from one face, and for one of them it was necessary to use the old outer loop.

The described reconstruction of cycles is performed for each intersecting face of the first body.

We will deal with the intersecting faces of the second body in the same way as we did with the faces of the first body, but with one small difference. The intersection edges must enter the rebuilt cycles of the faces of the second body with a positive flag (they entered the rebuilt cycles of the faces of the first body with a negative flag). This is the difference between rebuilding the cycles of the faces of the second body. All other actions on the faces of the first and second merged bodies are the same.

We have rearranged the intersecting edges of the merged bodies. We will include all of them in the shell of the resulting body. To obtain the resulting body, all that remains is to add to these faces in the body shell the faces that did not intersect in the operation, which are topologically related to the intersecting faces. To do this, we will take sequentially the edges included in the shell of the new body and include adjacent faces of the edges into the shell (if they are not there). Continuing these steps for the edges of all added faces, we obtain the shell of the resulting body.

Crossing bodies

Briefly, the essence of the Boolean operation of intersection of bodies can be described as follows: you need to find the lines of intersection of the bodies, remove that part of the first body that did not get inside the second, and that part of the second body that did not get inside the first, and build a new body from the rest.

This operation has much in common with the operation of combining bodies. Let's return to Fig. 6.6.6. It shows intersecting faces: one face of the first body and two faces of the second body. The faces cut each other, so that only parts of these faces will be included in the resulting shell.

The intersection of bodies will include part of the face of the first body, lying inside the second body, and part of the face of the second body, lying inside the first body (Fig. 6.6.14) (the union of bodies includes part of the face of the first body, lying outside the second body, and part of the face of the second body lying outside the first body).

Rice. 6.6.14. Source faces

Rice. 6.6.15. Rebuilt body intersection faces

This is the main difference between the operations of union and intersection of bodies.

We will divide the operation into three stages. The first and second stages of the operation of intersecting bodies completely coincide with the corresponding stages of the operation of combining bodies.

The third stage of the operation of intersection of bodies is performed similarly to the third stage of the operation of combining bodies, but has one difference in the flag with which intersection edges enter the cycles. The intersection edges are included in the rebuilt cycles of the faces of the first body with a positive flag, and in the rebuilt cycles of the faces of the second body - with a negative flag (in the union of bodies, the flags of the intersection edges in the cycles have the opposite meaning). All other actions on the faces of both bodies are the same in both operations.

Body difference

Briefly, the essence of the Boolean operation of subtracting bodies can be described as follows: you need to find the intersection lines of the bodies, remove that part of the first body that fell inside the second, and that part of the second body that did not fall inside the first, and construct a new body from the rest.

The Boolean operation of subtracting bodies is reduced to the Boolean operation of intersecting the body being reduced and the body being subtracted turned inside out. We will obtain a body turned inside out from the original body by reorienting the directions of the normals of the faces and the directions of the cycles of the faces. Reorientation of the direction of the face normal is performed by changing the sign of coincidence of the surface normal and the normal of its face. Reorientation of the direction of the face cycle is carried out by rebuilding the list of edges (changing to reverse order sequence of edges in the list) and replacing edge flags in lists with opposite ones. For an inverted body, the internal volume is the part of space located outside its shell. Therefore, at the intersection of a reduced body and a subtrahend body turned inside out, the resulting shell will contain that part of the volume of the reduced body that lies outside the subtrahend body.

Intersecting ribs.

The most labor-intensive and requiring a certain precision in the process of performing Boolean operations is the construction of intersection edges. The intersection edges must not have parts protruding beyond the boundaries of the face; they must necessarily join either with each other or with the old edges of the faces. If the surface intersection operation is performed correctly, these conditions are met. Intersection edges must not intersect each other beyond their extreme points.

In most cases, new edges do not intersect each other, but in some special cases this is possible. In Fig. 6.6.16 shows two cylindrical bodies of the same diameter, the axes of which intersect - a cross of cylinders. With a Boolean union of these bodies, a situation is possible when only two closed intersection edges are constructed. Such edges have two intersection points: A and B, at least one of which will not coincide with the vertices of the edges, but will lie somewhere on the edge. The intersection points of the ribs lie at the points of contact of the cylinders. These edges must be cut at points A and B, and the orientation of their parts must be specified, since when passing the point of contact of the surfaces in this case, the vector product of the normals to them, along which the new edges are oriented, changes its direction to the opposite. The intersection of new edges can be detected by the intersection of curves on the surfaces that make up the intersection line.

Rice. 6.6.16. At points A and B, the normals of the faces coincide

Matching edges.

The described algorithm for performing Boolean operations works correctly if the intersection edges do not coincide with the edges of the original bodies. Otherwise, it needs clarification. Let's look at examples.

In Boolean operations, a case is possible when any face of one body intersects another body along its edge. It is also possible that when constructing the edges of the intersection of the faces of one body with the faces of another body, we get two new edges that coincide in space with each other and with the edge of one of the bodies. All edges are different, since different faces join them. In Fig. 6.6.17 shows two bodies, when performing a Boolean operation on which, the intersection edges will coincide with the edges of the smaller body. Following the general algorithm, in this case we will get eight intersection edges, half of which should be omitted (or should not be constructed).

Rule for intersection edges.

If there are intersection edges that coincide with the edges of the faces of the original bodies, and in some other cases, we will perform the following check. Let us construct two vectors in the plane of each of the two intersecting faces, orthogonal to the intersection edge. In Fig. 6.6.18 these are vectors for a face with a normal and vectors for a face with a normal. Vectors rotate to the left of the intersection edge in the corresponding planes, and vectors rotate to the right of the intersection edge in the corresponding planes.

Rice. 6.6.17. Coincidence of intersection edges with edges of a smaller body

Rice. 6.6.18. Intersection of faces

Rice. 6.6.19. Intersecting faces along an edge

If the face does not extend beyond the intersection edge (the intersection edge partially or completely coincides with the edge of the body), then the corresponding vector is set equal to zero (Fig. 6.6.19). Using vectors and normals we can determine whether a given intersection edge will be used in the operation or should be omitted. Let us pay attention to the following circumstance.

In the operation of uniting bodies, we can rebuild the face of the first body if it has a continuation to the right of the intersection edge outside the second body, and we can rebuild the face of the second body if it has a continuation to the left of the intersection edge outside the first body.

Thus, in the Boolean operation of uniting bodies, the conditions for the intersection edge must be met:

Otherwise, the intersection edge in question should not be constructed in the Boolean operation of uniting bodies (if it is constructed, it should be omitted).

In the Boolean operation of intersection of bodies, we can rebuild the face of the first body if it has a continuation to the left of the intersection edge inside the second body, and we can rebuild the face of the second body if it has a continuation to the right of the intersection edge inside the first body. Thus, in the Boolean operation of intersection of bodies, the conditions for the intersection edge must be met:

Otherwise, the intersection edge in question in the Boolean operation of intersection of bodies should not be constructed (if it is constructed, it should be omitted).

As already mentioned, the intersection edges have a priority right over the old edges of the body to be included in the rebuilt cycle.

That point belongs to the internal space of the body. Otherwise, no.

Overlapping edges.

In Boolean operations, one can quite often encounter cases of partial coincidence of some faces of two original bodies. In Fig. Figure 6.6.20 shows two bodies, some of whose faces partially overlap each other.

Rice. 6.6.20. Coinciding faces of bodies

Rice. 6.6.21. Merging bodies

In this case, not all edges of the intersection of faces will be included in the Boolean result; some edges should be omitted (or not built). The result of combining bodies is shown in Fig. 6.6.21.

A similar situation arises when performing a Boolean operation on two coaxial cylinders of the same radius and in many other cases. Faces can overlap completely, partially, or just along one line. The normals of partially overlapping faces must be in the same direction at common points. Overlapping faces are those that can be transferred to one common surface. There may be more than two such faces. If the body operands have overlapping faces, all edges of the intersection of these faces must be checked to see if they are present in the Boolean result. In the operation of merging bodies, we only need those edges of intersection of overlapping faces whose adjacent faces have a continuation outside one of the bodies. In the operation of intersecting bodies, we only need those edges of intersection of overlapping faces whose adjacent faces extend into one of the bodies.

Cycles of overlapping faces of bodies must be rebuilt using a slightly different algorithm than for other faces. First of all, all edges of these faces must be brought to one common support (to the surface of one of the overlapping faces). In the operation of merging bodies, old edges of overlapping faces of the first body that lie inside the second body, and old edges of overlapping faces of the second body that lie inside the first body, will not be included in the resulting body. In the operation of cutting bodies, the old edges of the overlapping faces of the first body, lying outside the second body, and the old edges of the overlapping faces of the second body, lying outside the first body, will also not be included in the resulting body.

Let's start constructing a certain cycle of overlapping faces with an edge that should definitely be included in the result. To continue the cycle, among the intersection edges and among the old remaining edges of the face, we find all the edges that connect to a given edge at its corresponding vertex. Among the found edges, we choose the one that lies to the right of the others (it turns to the right at a larger angle compared to the other found edges, if you look along the cycle from the outside of the face). We put the selected edge in the cycle list. The difference in the algorithm is that as we continue the loop, we select the rightmost (rather than the leftmost) edge.

Bodies with several shells.

If any of the operand bodies has voids and, accordingly, is described by several shells, then the internal (external) shells untouched by the operation must be checked to see if the Boolean result is included in the shell. In general, the resulting body can also have several shells.

Body construction tree.

Boolean operations on bodies show the need to use topological concepts to construct bodies.

The bodies considered in the previous paragraphs will be called simple, in contrast to the bodies obtained as a result of operations, which we will call complex. Data structure simple bodies contains a minimum of information from which all faces of the body can be constructed. In the data structure of the body obtained as a result of a Boolean operation, we put the data structures of the original bodies and the type of the Boolean operation. Body shells can always be constructed using this information. Thus, the data structure of a body obtained as a result of repeated execution of Boolean operations will contain a construction tree. The resulting body is at the root of the tree, and its branches begin at simple bodies.

An example of a tree is shown in Fig. 6.6.22. The nodes of the tree contain bodies. The tree has several tiers. Operations between bodies are indicated by appropriate signs. Operations are performed between bodies of the same tier.

Rice. 6.6.22. Body construction tree

The body data structure in the form of a construction tree can be used for all bodies - both for bodies obtained as a result of some operation, and for simple bodies.

Operations > Boolean

A Boolean operation is designed to create a new body based on two or more existing bodies. As a result of the operation, a new body is created, which is a combination of the original bodies.

Basic concepts. Operation options

Types of Boolean Operation

There are three types of Boolean operations:

● Addition . The result of the operation is a body that combines all the parts of the bodies involved in the operation.

● Subtraction . The result of the operation is a body obtained by subtracting one body from another.

● Intersection . The result of the operation is a body obtained by the intersection of the bodies involved in the operation and consisting of common parts of these bodies.

Operands of a Boolean operation

The bodies involved in a Boolean operation are called " Operands " Boolean operation. They are divided into first and second operands. The bodies on which transformations are performed are called "First operands" Boolean operation. The bodies with which the transformation is performed are called "Second operands". Depending on which operand the bodies were chosen as, we get different results Boolean operation.


A Boolean operation can also be performed between a set of bodies, some of which can be selected as the first operands, and other bodies as the second. In the process of performing such an operation, all first operands are combined into one body and all second operands into another body. The selected Boolean operation is then performed between these bodies. The result is one multicomponent body.

Boolean operations results

Both solid and sheet bodies can be selected as operands. The ability to select different combinations of operands and set parameters allows you to generate different results of Boolean operations.

It should be noted that in some situations, when combining certain types of operands in Boolean operations, it is impossible to obtain a result.

Below we will consider the main combinations of operands and the results of the operation.

As a result of Boolean operations, in some cases, both a solid and a sheet body can be formed. The user can select the type of the resulting body using the "Result of the operation".

This option is advisory in nature and allows you to select, other things being equal, one or another type of the resulting body. If it is impossible to form the selected body type as a result of the operation, then the value of this parameter will be ignored.

Interpretation of a sheet body

A sheet body used as an operand in a Boolean operation can be defined in a command as either a sheet body itself or a half-space. Depending on the interpretation and which operand the body is chosen as, different results will be obtained.

If the operand - a sheet body was defined as a half-space, then the normal vectors to the surface of the sheet body will be displayed in the scene. The direction of these vectors indicates which half-space is selected and will affect the outcome of the operation.

Operation "Addition"

Results of the Boolean operation "Addition" when combined various types operands:

Solid + Solid

If the first and second operands are solids, then as a result of the operation one body will be formed, combining all parts of the bodies involved in the operation.

Sheet body + Solid body

As a result of the operation, a sheet body will be formed, which represents the “punching” of the sheet body by a part of the solid body. Depending on the selected half-space, a “punching” of either the lower or upper part is formed.

It should be noted that the sheet body must completely intersect the solid body.

Solid + Sheet body

If a rigid body was selected as the first operand and a sheet body was selected as the second, then the default result of the Add operation is to create a rigid body. The faces of the sheet body will form additional volume for the solid body.

The sheet body in this case must be defined in the command as a half-space.

It should be noted that to form this kind of Boolean operation, it is necessary that the sheet body, when added to a solid body, closes the volume. Otherwise, it is impossible to obtain the result of the operation.

When selecting a sheet body, you should pay attention to the direction of the normal vectors. With a certain direction of the normals, the resultant body may be incorrect. In this case, you need to select a different half-space in the "Interpretation of the operand".

Leaf body + Leaf body

As a result of the addition of two sheet bodies, a sheet body is obtained. To successfully create an operation, it is necessary that the faces of the sheet bodies either have a common edge or coincide in a certain area. This feature is similar to the "Stitch" operation. The difference is that the Boolean operation " Addition "does not remove gaps between bodies, but" Stitching " is trying to create a new continuous surface.

Operation "Subtraction"

Results of the Boolean operation "Subtraction" when combining different types of operands:

Solid - Solid

The result of performing the Boolean operation “Subtraction” of one solid body from another will be a body that rearranges the first operand, from which the volume of the second operand is removed.

When creating a Boolean operation " Subtraction "A situation where the resulting body will have areas with walls of zero thickness is not allowed. In this case, the topology of the model is violated.

Sheet body - Solid body

When subtracting a rigid body from a sheet body, a hole will be created in the sheet body in the shape of the second operand - the solid body.

As a result of subtracting a sheet body from a solid, a part of the solid body remains, cut off by the sheet body. In this case, the sheet body must be defined as a half-space. Depending on the selected half-space, either the top or bottom part solid body. This type of Boolean operation is analogous to the "Cut" operation.

Operation Crossing

Results of the Boolean operation "Intersection" when combining different types of operands:

Solid - Solid

The result of the intersection of solid bodies is a body that represents common part all operands.

Sheet body (half space) - Sheet body (half space)

If the sheet bodies coincide in a certain area, then as a result of performing the Boolean operation "Intersection" their common part remains.

Sheet body - Solid body

If a sheet body was selected as the first operand, and a solid one as the second, then as a result of performing the Boolean operation "Intersection" a sheet body will be formed, which is the common part of the two operands.

Rigid Body - Sheet Body (Half Space)

As a result of performing the Boolean operation "Intersection" of a sheet body, interpreted as a half-space, and a solid body, a part of the solid body will remain, cut off by the sheet body. The result of this operation is similar to the result of the Boolean operation “Subtract” a sheet body (half-space) from a solid body. The difference is that as a result of performing the “Intersection” operation, another part of the solid body remains. In this case, the order in which the operands are selected does not affect the result.

Boolean operations between sheet bodies (half-spaces)

One way to use Boolean operations between sheet bodies is to create corners. To do this, the sheet bodies in the team must intersect and be defined as half-spaces. Depending on the direction of the normals to the surfaces of the sheet bodies and the type of Boolean operation used, different resulting sheet bodies are obtained. In this case, the directions of the normals on the resulting body are preserved.

In the case where one sheet body does not completely intersect another, the Boolean operation will not work. To correct the situation, the parameters of the Boolean operation provide the ability to extend the edges of the first or second operand to the nearest edge or boundary of the body. In this case, the line of intersection of these two bodies will be extended tangentially to the selected edge or boundary of one of the operands.

Global and local Boolean operations

If sheet or rigid bodies are selected as operands, then these types of Boolean operations will be called " Global ". When creating such a Boolean operation, the system itself determines the faces of the bodies participating in the operation and their intersections. If the Boolean operation involves geometrically complex bodies or uses enough large number operands, then searching for all intersections can greatly slow down the execution of the command.

In addition to the "Global" Boolean operation in T-FLEX there is the concept of " Local "Boolean operation. Unlike the "Global" Boolean operation, where only bodies are selected as operands, in the "Local" Boolean operation, in addition to bodies, the faces of the operands are selected. You can select the faces of the operands in the operation parameters on the "Faces" tab. In some cases, use The “Local” Boolean operation provides a significant gain in model regeneration time compared to the “Global” Boolean operation, because as a result of the operation, intersections of only the specified faces will be searched. For example, if you need to make a hole in a fairly complex body and it is known that. If the hole intersects a small number of faces, it makes sense to specify these faces in the operation parameters.

It should be noted that you need to carefully select the faces for the "Local" Boolean operation. In the case of incorrectly selected faces, an incorrect body may be formed.

Selecting individual operand faces in " Local "Boolean operation with parameter enabled"" allows you to form such bodies as shown in the figure below. In this case, the intersection lines of the faces of the operands will first be determined, and then closed loops will be formed along these intersection lines and the boundaries of the faces of the first operands to form a Boolean operation.

In some cases it may be convenient to use the option "Use adjacent faces" for the first or second operands. It is enough to select one face of the operand so that the system itself defines the neighboring faces in such a way that the lines of intersection of the faces of the operands form closed cycles. In this case, when changing the number of faces, the component closed loop, if the operands are modified, the result of the Boolean operation will remain correct.

Selective Boolean Operations

As a result of the intersection of the operand faces, common edges are formed. These edges divide the bodies of the operands into parts. Parts of operands can be internal (common parts of operands) and external. When creating a Boolean operation, it is possible to specify the external parts of the operands that will be left in the resulting body or, conversely, excluded from it.

Part of the operand is defined by topological elements: vertices, edges or faces. To select a part of the operand, just specify in the operation parameters on the " tab Operand parts " one of these elements. The figure below shows the possibility of using a selective Boolean operation "Addition", during which only the selected parts of the second operand remain in the resulting body.

In some situations, the selected topological element does not explicitly define the desired part. For example, as shown in the picture below, the selected edge belongs to several outer parts of the operand. In order to unambiguously determine the required part, you need to build a 3D node on this face and use the option " Point selection " select this 3D node. There is no need to select a face.

In cases where the operands have matching areas, the command provides the ability to additionally determine the topological correspondence of the areas of these operands. Based on this information, the team will choose required algorithm forming a Boolean operation.

This feature allows you to:

1. Speed ​​up the process of recalculating a Boolean operation by specifying a specific type of contact.

2. In some cases, without specifying a match, it is impossible to obtain the result of a Boolean operation. For example, when there is contact between spline and analytical surfaces (Boolean operation between the cylinder and the face of the spiral in the picture below).

The command provides four types of matches:

Complete match– the boundaries of topological elements coincide with the specified accuracy.

● Turn on – the boundaries of the second element lie within the boundaries of the first element.

Partial match– the boundaries of one element partially coincide with the boundaries of another element.

● Projection – coincidence of fingerprints of the boundaries of topological elements.

The table below provides a description of the match types for different operand topologies:

The match can be exact or approximate. Exact matching assumes that the operands have only the described contacts and there are no other matches or intersections. If you establish an approximate match, then in addition to the specified contacts, the system will look for other intersections of operands. This method takes longer to complete than the exact method, but in some cases it is the only way to obtain the result of a Boolean operation.

The figure below shows the assignment of a correspondence in the Boolean operation "Addition" between a hemisphere and a cone that have matching bases. If the match is set to coincide with the faces of the base and selected exact method, then in this case it will be impossible to obtain the result of a Boolean operation, because when the operands intersect, there is one more common edge that is not described in the correspondences. In this case, the only possible approximate method will be the implementation of which this intersection will be found.

Smoothing New Edges

Another feature of Boolean operations is smoothing new edges. By new edges we mean edges resulting from the intersection of operand faces. When the geometry of the operands changes, or the number of new edges decreases or increases, the system will automatically track this and generate smoothing. In the command, you can select the smoothing type: rounding or chamfer and set the smoothing radius.

Missing one of the operands

When creating a Boolean operation, you can set the parameter "It is possible that one of the original operations is missing". This technique is often used in parametric models, when for a certain design of the model it is necessary to exclude one of the elements. As shown in the figure below, the nut can have two designs: with and without a groove. In order to implement these designs in one model, you can suppress the second the operand will save all subsequent operations created on the basis of a Boolean operation (in the example, this is saving a cosmetic thread on the edge of a Boolean operation).

If this option is disabled, a Boolean operation creation error will be thrown when suppressing an operand.

Creating a Boolean Operation

To work in a team, the automenu and the properties window are used together. They work synchronously and complement each other. The state of the automenu depends on the stage of specifying the operation, on the purpose and type of selected objects.

To create an operation you need to do the following:

1. Select Boolean operands.

2. Select the type of Boolean operation.

3. Select parts of the operands to form a selective Boolean operation (optional).

4. Set element correspondence (optional).

5. Set additional parameters (if necessary).

6. Set anti-aliasing parameters (optional).

7. Confirm the creation of the operation.

Basic parameters of the operation

Operand selection

Selecting Operands for a Global Boolean Operation

To select the operands of a global Boolean operation, use the following option:

<1> Select Boolean Operands

In this case, the following options become available in the automenu:

Select first body

Select second body

When one of these options is activated, the input focus moves to the corresponding window for selecting the first or second operands in the properties window. And vice versa, by switching between windows for selecting operands in the properties window, the corresponding option is activated in the automenu. You can select bodies as the first or second operands directly in the 3D scene or in the 3D model tree window. The bodies of the first operands are highlighted in the scene green, the bodies of the second operands are yellow. The operand selected in the properties window is highlighted in blue in the scene.

To remove any operand from the list, you need to select it in the " Properties" click the [Delete] button.

To deselect all operands, use the option:

Deselect all operands

After creating a Boolean operation, the bodies of the operands will be removed from the scene and only the resulting body will remain. For each operand can include the parameter "Leave in the scene". In this case, after creating the operation, the body of the operand with this parameter enabled will be left in the scene.

If a sheet body is selected as an operand, then the interpretation of this body must be specified. There are three possible interpretations of a sheet body: directly as a sheet body, or as an upper or lower half-space. Depending on how it is determined by the system, different results of the Boolean operation will be generated. You can define sheet bodies by selecting the appropriate values ​​in the drop-down lists of operand interpretation parameters.

Selecting Operands for a Local Boolean Operation

To switch to the face selection mode to create a local Boolean operation, you can use the automenu option:

<3> Select local faces

Faces" in the Properties window.

In this case, the following options become available in the automenu:

Select local faces of first operand

Select local faces of second operand

After selecting the operands, you can use the specified automenu options or move the input focus to the tab windows " Edges ", select faces of bodies in the scene to create a local Boolean operation. When creating a Boolean operation, you can not select operands, but immediately switch to the face selection mode. In this case, bodies whose faces are selected will be automatically added as operands to the corresponding tab in the operation parameters Marking the faces of the first and second operands is similar to selecting the body operands. To delete a face, you need to select it in the list on the tab ". Edges " and press the [ button Delete ]. In some cases it is necessary to enable the "Trim along the edges of the first operands" to generate the correct result of the operation.

To deselect all local faces, use the option:

Deselect Local Faces

When creating a local Boolean operation, faces adjacent to the selected face can be used. To do this, select the appropriate value in the drop-down list of the parameter "Use adjacent faces".

Selecting a Boolean Operation Type

The type of operation is selected either using the parameter " Operation type "in the Properties window ", or using the following automenu options:

<+>Addition

<->Subtraction

<*>Intersection

When executing a Boolean operation command for the first time after starting the program, the type of Boolean operation is automatically set in the automenu " Addition ". When you call the Boolean operation creation command again, the pressed state will be the button corresponding to the type selected the last time you used the Boolean operation.

Selecting parts of operands

To create a selective Boolean operation, use the following option:

<2> Select parts of operands

You can also switch to the " tab to activate this mode.

Select element defining part of operand

Select point defining part of operand

Using these options, you can select elements that define parts of the operands. The names of the selected elements will be added to the list on the " tab Operand parts" in the Properties window ". On the same tab, you can select an action for the selected parts of the operands: leave them in the resulting body or exclude them. This action is set for all selected parts of the operands.

To deselect parts of the operands, use the option:

Deselect elements that define parts of operands

To specify the correspondence of elements, use the option:

<4> Setting Element Matches

You can also switch to the " tab to activate this mode.". In this case, the following options become available in the automenu:

Select first element

Select second element

Deselect all items

Using these options, elements to match are selected in pairs. The names of the selected elements are displayed on the " tab Matches in the Properties window ". For all pairs of elements, an exact or approximate method can be set. The matching type is selected from the parameter list " Type " on this tab.

It should be noted that the set of matching types in this list may vary depending on the combination of topological elements in the pair (see table in paragraph "Setting Element Matching").

The accuracy of the match can be set on this tab.

Previewing the results of Boolean operations

To preview the result of a Boolean operation, as well as the changes made by a Boolean operation, you must use the view automenu option or a similar button in the properties window:

Preview the result of the operation

Preview the changes made by the operation

Additional Operation Options

Continuation of operand edges

If the command uses sheet bodies defined as half-spaces as operands, then in this case, in order to form the result of a Boolean operation, it may be necessary to continue the edges of the intersection of the operands. To do this, you need to select the type of object to which to extend the edges of the first or second operand. This can be done using the appropriate additional parameters.

Selecting the type of the resulting body

If, as a result of creating a Boolean operation, both a solid and a sheet body can be formed, then desired type can be selected using the option "Result of the operation" in the additional parameters of the operation. When set to " Default " the command will create the priority type of the resulting body.

As noted earlier, this option is advisory in nature. If it is impossible to form the selected type of resulting body, the value of this parameter will be ignored.

Copying by pattern

If a 3D array is used as one of the operands, then by turning on the parameter "Copying by pattern", you can significantly reduce the execution time of a Boolean operation.

Possibility of missing one of the operands

If you enable the parameter "The absence of one of the original operations is allowed", then in the future it will be possible to suppress one of the operands and at the same time preserve the result of the Boolean operation.

Smoothing New Edges

To enable the smoothing mode for new edges obtained by intersecting the faces of the first and second operands, you need to enable the parameter "Smooth new edges". After this, a group of parameters becomes available that allows you to select the type of smoothing (" Fillet, Chamfer ") and the amount of smoothing (parameter " Radius ").

New edge material

One of three values ​​can be selected:

● “ Material of 1st operand" In this case, the new faces will be assigned a base material, or a coating material, if one is specified, in accordance with these parameters of the first operand. If there are several first operands and they have different materials, then the new faces will retain the material of the operand that participated in the formation of these faces.

● “ Material of 2nd operand" With this value, the material of the faces of the second operand, which participated in the formation of new faces, will be transferred to these new faces. This can be the base material, the covering material, if one is specified, and even the material of the material assignment operation. For example, as a result of the Boolean operation “Subtraction” between the first operand with the material steel and the second operand with the material black plastic, the material black plastic will be superimposed on the created faces of the resulting body. If there are several second operands and they have different materials, then the new faces will retain the material of the operand that participated in the formation of these faces.

● “ Base material of 1st operand" The effect of this parameter is similar to the first parameter (“Material of 1st operand"), unless a coating material is specified, the coating material is not applied to new faces. For example, if you make a hole in a part with the base material “Steel” and the coating “Copper” using a Boolean operation, then the inside will look like steel in accordance with the base material.

Features of working with Boolean operations

Displaying a Boolean operation in the 3D Model window

After you create a Boolean operation, it is placed in the Boolean folder in the " 3D model ". To the left of each Boolean operation, an icon is displayed indicating the type of operation (Addition, Subtraction, Intersection). Boolean operations are displayed in a special way in the 3D model tree. When expanding the structure of the Body, the Boolean operation is shown as an icon to the left of the second operand. The figure on the right shows "Boolean_2": the intersection of the first operand "Rotate_1" with the second operand "Push_2".

When you click on the icon to the left of the second operand in the model tree, the context menu for the Boolean operation is called up. Also, the context menu for a Boolean can be called from the context menu for the second operand in the model tree.


Creating a Boolean operation in the 3D model tree

You can create a Boolean operation in the 3D model tree without explicitly calling the create command.

Using the Drag&Drop method , you can select one body in the 3D model tree and hold the left mouse button and drag it to another body. In this case, the Boolean operation "Addition" will be automatically created. If you keep pressingSubtraction ". If instead hold down a Boolean operation " will be created Intersection ". The body being dragged will be the second operand, and the body being dragged onto will be the first operand.

Automatic creation of Boolean operations when creating other operations

When creating many T-FLEX CAD operations, automatic creation of a Boolean operation is possible. The body created is always the second operand of the Boolean operation. Any of the already existing bodies of the 3D model is selected as the first operand.

To create a Boolean operation you need:

1. Enable the Boolean operation creation mode using the automenu option:

A Boolean operation is created when the icon is pressed.

2. Select the type of operation to be created using the automenu option containing a drop-down list:

Intellectual

Operating principle of intelligent mode:

If the created body and the selected body (explicitly or implicitly) have an intersection of volumes - a type of Boolean operation: subtraction .

If the body being created lies entirely inside the selected body, the type of Boolean operation is: subtraction .

If the body being created touches the selected body, the type of Boolean operation is: addition

If the conditions specified in paragraphs 1, 2, 3 are not met, or the selected body lies inside the one being created, or an error occurred when determining the type of penetration of bodies -Boolean type is not defined, Boolean operation will not be created.

3. Select the first operand of a Boolean operation (in some cases an optional action) using the automenu option:

If there is only one body in the scene, it is selected automatically. The new body created in the operation is the second operand of the Boolean operation.

After confirming the creation of the operation, the body is first created, and then the Boolean operation of the specified type is executed.


It should be noted that the preview when creating such operations displays the result of the automatic Boolean only when the operation is created. When editing, the preliminary result is not displayed. If an automatically generated Boolean operation has no result, only the generated operation will be visible in the preview.

Removing a Boolean Operation

If the Boolean operation is on upper level tree, then when it is deleted, the bodies of the operands of this Boolean operation will remain in the model tree. If a Boolean operation has descendants, then when it is deleted, the dialog "Removing items".

If in this dialog you select the option "Exclude selected elements from model...", then the dialog "Selecting an operation to reassign children", in which it is proposed to select one of the operands of the Boolean operation, to which all descendants of the Boolean operation will be transferred.

The figure below shows the structure of Body_1. First, the Boolean operation “Subtraction” of the operation “Circular Array_1” was created from the operation “Rotation_1”, and then “Thread_1” was applied to the face of the resulting body of the Boolean operation. If you now delete the operation “Boolean_1” with an attempt to exclude an element from the model tree and in the “Select an operation for reassigning descendants” dialog select the operation “Rotation_1”, then the operation “Thread _1” will become a descendant of the operation “Rotation_1.

When you delete one of the operands and exclude an element from the model tree, the Boolean operation itself will be deleted.

Boolean operations with 3D fragments

The use of 3D fragments as operands is a unique feature of T-FLEX CAD. Thanks to this, the possibilities for creating parametric 3D models and assemblies are significantly expanded. When inserting a 3D fragment into an assembly, it is possible to automatically create a Boolean operation with assembly bodies. More details about the possibilities of using a 3D fragment as an operand can be found in the description of the "3D Fragment" command in the "section"Creating a Boolean operation based on a 3D fragment" and in the description of the ST command: Document parameters in the section " Bookmark 3D ".

When you create 3D fragments with an automatic Boolean operation specified, the preview displays not only the inserted fragment, but also the result of that Boolean operation.


Threading using a Boolean operation

If a cosmetic thread is applied to the face of one of the operands and this face is in contact with the faces of another operand, then in this case it is possible to automatically create a cosmetic thread on the face of the resulting body. For example, as shown in the figure below, the body with cosmetic threads on the edge is subtracted from the body body. In this case, a cosmetic thread is automatically created on the created face of the resulting body.

It should be noted that the thread on the edge of the second operand must be " Internal ", so that on the resulting body the thread in the hole is also created as " Internal ".

In the operation parameters dialog called by the option, you can set general operation parameters.

To edit the created operation, use the 3EB command.

Purpose of the work: Learning the basic techniques for multiplying objects using the “array” function; studying the technology of creating objects using Boolean operations.

Boolean operations

Boolean operations (often called logical) came to 3D graphics from mathematics, more precisely, from Boolean algebra (named after its creator, George Boole) and are based on the concepts of union, intersection and exclusion. There are three main Boolean operations in 3D Studio Max, the results of which are shown in Figure 1:
  1. Union (connection of objects into one).
  2. Intersection (the Boolean object includes only the common parts of the original objects).
  3. Elimination (cutting).
Figure 1. Results of using Boolean operations.
Association. The resulting object, obtained by combining two objects, contains all the points of the two original operand objects, except for duplicates of the common points.

Intersection. The object resulting from the intersection operation contains only those points that are common to the two original objects.

Subtraction. The object that results from this logical operation contains only the points of the first object, excluding those points that are common to the two objects. The operation of logical subtraction of one object from another is non-commutative. In other words, the difference A - B- this is not the same as the difference B - A.

Using Boolean Operations

Boolean operations in 3D Studio Max can only be performed on two objects. These objects must intersect, i.e. contain common points. Boolean operations allow you to create composite objects by performing the operations of combining, subtracting, and intersecting parts of two objects. Boolean operations can be accessed as follows (Figure 2).
Figure 1. Accessing Boolean operations.

First, you need to select the object that will participate in the operation first, i.e. will be an object A in one of the projection windows. Then you need to click on the tab Create(New) command bar and button Geometry(Geometry). From the drop-down list below this button, select a mode Compound Objects(Composite objects). In the branch Object Type(Object type) click on the button Boolean(Boolean operations). A scroll will appear in the command bar with operations that can be performed on objects. Boolean operations are mentioned in combination with another term - operand. An operand is a variable assigned to the selected objects during the execution of an operation. The operand is much like the variables used in algebra to write equations. For example, variables A And IN can be used to represent two objects on which a Boolean operation will be applied.

  • Union(Union). This function merges two objects into one and removes overlapping or overlapping areas.
  • Intersection(Intersection). This function creates an object that contains only the overlapping areas of both objects.
  • Substraction(Subtraction [A-B]) and Substraction(Subtraction [B-A]). This operation removes one of the objects and any overlapping areas of the objects. For this type of operation choice A-B results in the subtraction of object B from object A, and B-A results in the subtraction of object A from B.
  • (Added in older versions of the program) Cut(Cut). This function splits operand A with operand B. It works similar to the modifier Slice(Section), which allows you to cut the frame. Please note that there are four cutting options: Refine(Clarification), Split(Split), Remove Inside(Delete inside) Remove Outside(Removal from outside).
  • Operation Refine will add new vertices and edges to operand A at the places where it intersects with operand B. Operation Split will cut the object into two pieces. Operations Remove Inside And Remove Outside will remove from operand A all edges that are, respectively, inside and outside operand B.
Creating Boolean Objects

Objects of type Boolean(Boolean) are created by applying Boolean algebra operations to the shells of two three-dimensional solids. The shells of the original bodies participating in the Boolean operation are the operands ( operands), must necessarily intersect. Of the two objects involved in a Boolean operation, one must be allocated before the operation begins (operand A), and the other (operand B) is specified during the operation. After selecting one of the objects, you need to select the switch for the operation you want to perform. Once these items are selected, you should select the radio button for one of the copy types:

  • Move(Move) – in this case, the object itself participates in the logical operation. It will disappear after the operation is completed.
  • Sora(Copy) – a copy of the second object is involved in the operation. The object itself remains unchanged.
  • Reference(Link) – a link to the second object takes part in the operation.
  • Instance(Instance) – an instance of the second object takes part in the operation.
Then you need to click on the button Pick Operand IN(Select operand B) and, as soon as it is selected, in the projection window you need to select the second object, in relation to which you want to perform a Boolean operation. When starting to create Boolean objects, be aware that they are sometimes unstable and can produce undesirable results in certain situations. Therefore, before using Boolean operations, we recommend that you create a backup copy of your current project so that if objects are damaged, they can be restored. In the process of working with Boolean functions, it is discovered that sometimes Boolean objects behave extremely unstable when several Boolean operations are applied to the same objects. One of possible methods A solution to this problem is to convert the object into an editable wireframe before performing each Boolean operation. This may reduce the likelihood of unwanted results.

It's time to get acquainted with logical operations and a new data type - Boolean.

The simplest logical operation is the Equals operation. It finds out whether two values ​​are equal or not.

This operation is defined for values ​​of any type: for numbers, for strings, for dates, and so on. The only important thing is that both values ​​you are comparing are of the same type. For example, two numbers or two lines.

The logical operation Equals is denoted by the “=” sign. In the vast majority of cases, logical operations are used in If and Loop statements. But these instructions are not yet familiar to you.

Therefore, you will become familiar with the Equals operation using the assignment statement. In it, this operation will look a little strange, so for greater importance you will enclose it in brackets (Fig. 3.79).

Rice. 3.79. Blank for the operation “Equal”

Now inside the parentheses write the Equal operation. For example, 5 = 5.

Then write another assignment statement, but so that the Equals operation involves different numbers. For example, 5 and 2.

Launch 1C:Enterprise in debug mode and see what the variables in these instructions are equal to (Fig. 3.80).

Rice. 3.80. The meaning of "True" and the meaning of "False"

You will see that where the two are compared identical numbers, the result is True. And where different numbers are compared, the result is False. In addition, both of these values ​​are of type Boolean (emphasis on the letter “y”).

There are quite a lot of logical operations in the built-in language, as in life. They are all intuitive, and there is no particular need to practice using them. The only thing that can cause difficulty is what symbols they are denoted by. But Table 3.1 will help you with this.

Table 3.1. Comparison Operations

All the operations listed in this table are called comparison operations. Because they compare two values. Moreover, the Equal and Not Equal operations can be applied to values ​​of any type. The main thing is that the types are the same on one side and on the other side of the operation.



But the remaining four operations (greater than/less than) can only be applied to two numbers, two strings or two dates.

In this section, you will not perform examples with comparison operators. But once you become familiar with the If statement, you will have the opportunity to practice writing different comparison operators.

Boolean operations

And now you can get acquainted with the most interesting logical operations. In addition to comparison operations, there is also a group of logical operations called Boolean operations.

While comparison operations could be performed (mostly) on numbers, strings, and dates, Boolean operations are performed only on values ​​of type Boolean. That is, with the values ​​True and False.

For now, it’s hard for you to imagine why this might be needed. But now, with a few examples, you will immediately understand everything.

For these examples, you will need to write Boolean values ​​directly in the program text, that is, use literals. So, Boolean type literals look very simple. The value True is denoted True, and the value False is denoted False.

For example, if you want to create a variable that describes the weather outside your window, you could write it like this (Figure 3.81).

Rice. 3.81. Literal value "True"

And if in another variable you want to clarify whether it is raining outside or not, you can write like this (Fig. 3.82). Try it and see what the variables equal.

Rice. 3.82. Literal value "False"

Notice that the platform colors the words True and False in red. Because these are special reserved words. And this means that if you suddenly want to, you cannot create a variable with that name.

To become familiar with the first Boolean operation, create two variables: I Can Swim and There Is A Sea Near. Give them the values ​​that actually exist. And in the book, for example, I will assign them the value True (Fig. 3.83).



Rice. 3.83. Variables “I Can Swim” and “There is a Sea Nearby”

Now you need to use a logical operation to find out whether you will swim in the sea or not.

First try saying it in normal words. It will probably turn out something like “if I can swim and if there is a sea nearby, then I will swim in the sea.”

Now look (Fig. 3.84) how the same phrase looks in the built-in language.

Rice. 3.84. Operation "I"

To say the same thing in the built-in language, the AND operation is used. You can check how it works for yourself in this example by changing the values ​​of the variables.

You will only swim in the sea if it is nearby and you know how to swim. If there is no sea nearby, then there is simply nowhere to swim. And if you don’t know how to swim, then you won’t succeed either. This is very dangerous and you could drown. Well, if there is no sea, and you don’t know how to swim, then you won’t be able to swim in the sea.

Now solve another problem. Create two variables IHaveABoat and IHaveARaft. You can give them any values. And in the book, for example, I will assign them the value True (Fig. 3.85).

Rice. 3.85. Variables “I Have a Boat” and “I Have a Raft”

Now you need to use a logical operation to find out whether you can swim across the lake or not.

First try saying it in normal words. It will probably turn out something like “if I have a raft or a boat, then I can swim across the lake.”

Now look (Fig. 3.86) how the same phrase looks in the built-in language.

Rice. 3.86. OR operation

To say the same thing in an embedded language, the OR operator is used. You can check for yourself how it works in this example by changing the values ​​of the variables.

If you have a boat, can you cross the lake? Yes.

But if you don’t have a boat, but a raft, then can you? Yes, you can.

What if you have both a boat and a raft? Certainly! Even twice! Once on a boat and the other on a raft (just kidding)!

In what case will you not be able to swim across the lake? Right. When you have neither a boat nor a raft.

Now make your example more complex and recognize that multiple Boolean operators can be used in a single expression.

Create three variables: I Can Swim, There Is A Sea Nearby, and There Is A Pool Nearby. Give them the values ​​that actually exist. And in the book I will again not complicate things and assign them the value True (Fig. 3.87).

Rice. 3.87. Variables “I Can Swim”, “Nearby Is The Sea” and “Nearby Is A Swimming Pool”

And the question that you will solve will be almost the same. What will the variable IWillSwim be equal to?

If you answer with words, you will say: “I will swim if I know how to swim and there is a sea or a pool nearby.” Try writing this in the built-in language (Figure 3.88).

Rice. 3.88. Variable “I Will Swim”

At first glance, everything seems to be fine. But we need to check.

For example, you don't know how to swim. In this case, it doesn’t matter whether there is a pool nearby or not: you should not swim. But what does the program tell you? Try it (Fig. 3.89).

Rice. 3.89. “I Will Swim = True”

The program tells you what you will be swimming. This turns out to be some kind of “dangerous” programming. With such programming it won't take long to drown!

What's the matter? Maybe you wrote the wrong operations? No, they are correct.

You just didn't take into account that if several Boolean operations occur in one expression, they have a specific execution order. Just like it was with the arithmetic operations +, -, * and /.

The AND operation is performed first, and then the OR operation is performed. And if several identical operations occur in a row, then they are performed in the sequence in which they were written.

Therefore, in the example, the expression was calculated in this way (Fig. 3.90).

Rice. 3.90. Expression evaluation order

First, the AND operation was performed, which returned False. And then the OR operation, the result of which was Truth.

In fact, two things are important to you in this expression. What can you swim and what to eat, where to swim. But whether it’s the sea or the pool is not so important.

Therefore, the correct solution would be NearThereIsSea OR NearThereIsPool in brackets (Fig. 3.91). Give it a try.

Rice. 3.91. “I Will Swim = False”

Then the platform will first evaluate the expression in parentheses. That is, he finds out whether there is somewhere to swim, or nowhere to swim. And then he will take an interest in your swimming ability (Fig. 3.92).

Rice. 3.92. Expression evaluation order

To solidify this example, change the condition slightly. Create three variables: I Can Swim, There Is A Sea Nearby, and There Is A Bath Nearby. Give them the values ​​that were in the last example: False, True and True (Fig. 3.93).

Rice. 3.93. Variables “I Can Swim”, “Nearby Is The Sea” and “Nearby Is A Bath”

And you will need to calculate a variable called I Will Swim. Be careful: the variable name has changed for a reason.

Try writing the expression in the built-in language and then compare it with the one in Figure 3.94.

Rice. 3.94. “I Will Swim = Truth”

Launch 1C:Enterprise in debug mode and see what the result is if you change the values ​​of the variables.

Why weren’t parentheses needed in this case, even though the example looks very similar to the previous one? The parentheses were not needed because the “natural” order of logical operations in this expression suits you quite well (Fig. 3.95).

Rice. 3.95. Expression evaluation order

Indeed, the ability to swim is only important when you are about to enter the sea. If you want to take a bath, you don't need to know how to swim.

Therefore, it is absolutely correct that the AND operation is first performed and it is found out whether you can swim in the sea. And then the presence of a bathtub is checked, the use of which does not require the ability to swim.

In conclusion, we need to say about one more Boolean operation - the NOT operation. It's very simple. It returns the Boolean value opposite of the one present.

To see how it works, you can use the example shown in Figure 3.96.

Rice. 3.96. Operation "NOT"

Usually there are no difficulties with using this operation. The only thing you may need is the order in which the Boolean operations are performed. It looks like this in full:

  • First, what is in parentheses is executed;
  • then the NOT operation;
  • then operation AND;
  • then the OR operation.

Instruction "If"

Finally, it's time to get acquainted with another instruction that is used in the built-in language.

If you used only the assignment statement, your program would look like a straight line from point A to point B. From start to finish (Fig. 3.97).

Because assignment statements are executed one after another in the order in which they are written.

But in reality, most programs look different. There is a lot of time between the start of a program and its completion. different paths, along which the program can be executed (Fig. 3.98).

Rice. 3.98. Many paths from point A to point B

There is a lot for this various reasons. For example, it depends on what data is already in the program. If all the necessary data is available, then execution will follow one path. If some data is missing, then take a different path.

It also depends on what you want to get as a result. If from your electronic diary you want to find out whether there will be a math lesson tomorrow or not, then this will be one way, a simple one. But if you want to get a lesson schedule for the whole week, indicating classrooms, teachers and what is assigned, then this will be a different path, a difficult one. Because the program will need to work around a lot different places and collect for you all the information you request.

It is precisely in order to direct the execution of the program along one or another path that the If instruction exists. It looks very simple (Fig. 3.99).

Rice. 3.99. Instruction "If"

It allows you to select several instructions that will not always be executed, but only when the result of calculating a logical expression is True.

The words If, Then and EndIf are mandatory in this instruction. A logical expression is written between the words If and Then. And EndIf indicates where instructions that depend on a condition end.

To see how this works, make a small example. Create a variable and record your age in it. And then create another variable, I'mGoingToKindergarten, and set it to True. But create this variable only if you are not yet of school age. To avoid confusion, we will assume that school age starts at age 7.

When you make your example, compare it with the one in Figure 3.100.

Rice. 3.100. Example

Set a breakpoint on the line If..., run 1C:Enterprise in debugging mode and look at the value of the MyAge expression< 7 (Shift + F9) (рис. 3.101).

Rice. 3.101. The meaning of the expression “My Age”< 7»

You will see that it is equal to False. And that's right. Your age is more than 7 years.

Since the expression is false, then the platform must skip all the statements that are written inside the If statement. Check it out using step-by-step execution (F11). Take one step (Fig. 3.102).

Rice. 3.102. One execution step

Indeed, the platform will jump to the EndIf line. And if you step again, it will stop at the End of Procedure line. In this case, the value of the variable YaIduVKindergarten will be Undefined, because this instruction was not executed and such a variable was not even created.

Now see how the platform behaves when the expression is true. To do this, you will not change the program text. You will take advantage of the ability to change variable values ​​while debugging.

To do this, you will need to restart debugging first. To do this, execute the command Debug – Restart (Fig. 3.103).

Rice. 3.103. Restart debugging

After debugging restarts, execution will stop again at the line If... Open local variables (if you have this window closed).

Double-click the cell with the value 25 (Fig. 3.104).

Rice. 3.104. Changing the value of a variable

It will go into edit mode. Type 6 and press Enter.

From now on, the value of the MyAge variable will be equal to 6. And you can continue debugging in the same way as before.

Look up the meaning of the expression MyAge< 7. Теперь оно будет равно Истина (рис. 3.105).

Rice. 3.105. The meaning of the expression “My Age”< 7»

Take one step. Execution will go “inside” the If instruction (Fig. 3.106).

Rice. 3.106. One execution step

Now if you take a couple more steps you will reach the end of the procedure. And the value of the variable I am Going to Kindergarten will be equal to True.

So far you have considered the most simple form instructions If. In fact, it may be more complex. Look.

In your example, the "special" actions are only performed if you are under 7 years old. But imagine that you have to make a decision between two options. If under 7 years old, you go to kindergarten. In all other cases, you go to school. How can I write this in the built-in language?

It turns out to be very simple. To do this, use the keyword Else (Fig. 3.107).

Rice. 3.107. Keyword "Otherwise"

Modify the example so that as a result of its work you create two variables: I'm Going to Kindergarten and I'm Going to School. And so that they take the correct values ​​(True or False) depending on the age specified in the MyAge variable.

Compare your result with what is shown in Fig. 3.108.

Rice. 3.108. Modified example

Launch 1C:Enterprise in debug mode and check step by step that the example works correctly for different meanings age. Change the age while debugging.

Very often in the instructions If not one, but several conditions are analyzed. For example, one fine morning you woke up and remembered that you need to go to study. But you don’t remember where exactly: to kindergarten, school or college.

But you know the rules. Until the age of 7 you need to go to kindergarten. After kindergarten need to go to school. They finish school at the age of 18. And at the age of 19 they go to college.

To write this algorithm in the built-in language, you will need one more keyword - OtherwiseIf (Fig. 3.109).

Rice. 3.109. Keyword "ElseIf"

In your example, it will need to be written instead of the keyword Else. And then write the condition under which you need to go to school.

And at the end of the example, you will again add the word Otherwise and indicate that in all other cases you are going to college. Try making an example yourself.

To check your result, compare it with Figure 3.110.

Rice. 3.110. Example “I'm going to college”

In debug mode, go through different branches of the If instruction and see how it works.

You will see that the expressions specified in the If statement are evaluated and parsed one at a time. In the order in which they are written. As soon as a true expression is encountered, the corresponding branch of the If statement is executed. After this, execution moves to EndIf. That is, instructions located in those branches where the expression was false, or in those branches that the expression check did not reach, are simply not executed.

This is a feature of the If statement that needs to be remembered and taken into account. If you open local variables, you will see that after running the example, the YIduVIInstitute variable may not be defined. For example, if your age is 15 (Fig. 3.111).

Rice. 3.111. The variable "YaIduVInstitute" is not defined

And if the age is 20, then the variables YaIduToKindergarten and YaIduVSchool will not be defined (Fig. 3.112).

Rice. 3.112. The variables “I’m Going to Kindergarten” and “I’m Going to School” are not defined

But in a “live” program you will probably create such variables not just like that, but in order to use them in the future. And if any of these variables are missing, your program will not be able to work.

What is the way out of this situation? It's tedious and meticulous in every branch of the instructions. If you prescribe the creation of all the variables that you might need? No.

There is a much simpler and more convenient solution. Right before the If statement you create all the variables you will need. And you assign them some standard value - the “default” value. For example, Lie.

Rice. 3.113. Another example option

Do this example in your configuration and see how it works.

For any age, all variables will exist. And they will have the correct values ​​(Fig. 3.114).

Rice. 3.114. All variables are defined

Beautiful program

I've said before that your configuration should be beautiful. He said that variable names should be convenient and understandable. He said that expressions should be written clearly and “readably.” Now is a good opportunity to talk about what the text of your program should look like.

You are probably already accustomed to the fact that the platform itself colors the words in your program. And it's convenient. Also, maybe you noticed that the platform itself indents when you write an If statement.

If you haven't noticed this, then do a little experiment. In the module write If a = 2 Then. And press the Enter key (Fig. 3.115).

Rice. 3.115. Syntax indentation

You will see that on the new line the cursor will not appear under the letter E, but with a slight shift to the right. This shift is called syntactic indentation. It helps you read program text better and easier. Because “subordinate” instructions located inside one branch are highlighted visually (Fig. 3.116).

Rice. 3.116. There is a syntax indentation

Look what a mess it would be if there were no syntactic indentation (Fig. 3.117).

Rice. 3.117. No syntax indentation

Therefore, syntactic indentation is an important, mandatory part of the program. That's why the platform does it automatically when you type instructions sequentially.

But you don't always work this way. Even when running your simple examples, you see that you have to change what has already been written. Insert new lines. Copy from one place to another. In these cases, the platform cannot automatically indent the syntax. As a result, you may well end up with text like this (Fig. 3.118).

Rice. 3.118. Text with broken formatting

What to do with him? Move each line manually to make it look “beautiful”? It's boring, long and uninteresting.

Therefore, the platform has a command that can do this automatically. But now you don't see her. The Text panel in which this command is located is not shown with standard configurator settings. But you can always turn it on so that the formatting command is at your fingertips.

To do this, right-click on the empty space on the right in the top command bar (Fig. 3.119).

Rice. 3.119. Setting up configurator panels

In the menu that appears, click on the Text line. A new command panel will appear at the bottom of the window (Fig. 3.120).

Rice. 3.120. Text Command Bar and Format Command

This panel contains the Format command, which is what you need.

This command is very easy to use. First, you select the text you want to format. To do this, for example, click on the gray bar in the first line of text (Fig. 3.121).

Rice. 3.121. Start highlighting text

Then, without releasing the mouse button, move it until last line, which you need (Fig. 3.122).

Rice. 3.122. The text that needs to be formatted is highlighted

And click the Format button. The text immediately becomes beautiful and formatted (Fig. 3.123).

Rice. 3.123. Rich text

In addition to syntax indentation, there are other ways to make text more understandable. For example, one of good ways is the addition of empty lines to the program text. They allow you to divide the text into several separate semantic blocks.

If we take the example of the If instruction, then such semantic blocks suggest themselves. Each branch of this instruction is a separate semantic block. Therefore, if you add a blank line before the beginning of the branch, this will only improve the readability of your program (Figure 3.124).

Rice. 3.124. Using empty lines

Another good and very commonly used technique is creating comments. A comment is an explanation of the program, which is located directly in the text of the program (Fig. 3.125).

Rice. 3.125. Comment