A method, device and electronic equipment for drawing a three-dimensional geometric figure
By drawing and saving the information of each geometric face of a 3D geometric figure separately, the problem of the inability to achieve more demonstration functions in the existing technology is solved, and a richer display effect of 3D geometric figures is achieved.
Patent Information
- Application Number
- CN202111221262.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-20
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2041-10-20
AI Technical Summary
Existing methods for drawing 3D geometric figures cannot achieve more demonstration functions, especially in teaching scenarios, as they cannot show the unfolding process or the changes before and after rotation of 3D geometric figures.
When drawing 3D geometric figures, each geometric surface is drawn separately and the drawing information is saved so that each geometric surface can be processed later to achieve more demonstration functions.
By drawing and saving the information of each geometric surface separately, it is possible to more effectively help users understand the solid structure of three-dimensional geometric figures and provide more demonstration functions.
Smart Images

Figure CN114067072B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of graphics drawing technology, and in particular relates to a method, apparatus and electronic device for drawing three-dimensional geometric graphics. Background Technology
[0002] To better present the three-dimensional effect of things, it's necessary to combine the object's three-dimensional geometric shape with the display in some scenarios. For example, in a teaching setting, to help students understand a cube, a cube can be drawn on the blackboard. Currently, some drawing software has 3D drawing functions; you can select the shape to draw and then drag the mouse in the drawing area to create a 3D geometric shape. However, the 3D geometric shape drawn in this way is a single unit, which can only achieve a simple display effect and cannot realize more demonstration functions. Summary of the Invention
[0003] To address the aforementioned technical problems, embodiments of this application provide a method, apparatus, and electronic device for drawing three-dimensional geometric figures, which can achieve more demonstration functions.
[0004] In a first aspect, embodiments of this application provide a method for drawing three-dimensional geometric figures, wherein the three-dimensional geometric figures to be drawn include multiple geometric surfaces, and the method includes:
[0005] In a three-dimensional coordinate system, the three-dimensional coordinates of the feature points of the first geometric surface are determined based on the parameter information of the target center and the three-dimensional geometric figure to be drawn. The first geometric surface is any one of multiple geometric surfaces, and the parameter information includes at least one side length of the smallest cuboid that can accommodate the three-dimensional geometric figure to be drawn.
[0006] Based on the three-dimensional coordinates of the feature points of the first geometric surface, draw the first geometric surface and draw its outline.
[0007] Preferably, drawing the first geometric surface based on the three-dimensional coordinates of the feature points of the first geometric surface includes: determining the forward surface and / or the backward surface in the first geometric surface based on the three-dimensional coordinates of the feature points of the first geometric surface, wherein the forward surface is the surface displayed when viewing the three-dimensional geometric figure from the first direction, and the backward surface is the surface hidden when viewing the three-dimensional geometric figure from the first direction; and drawing the first geometric surface based on the forward surface and / or the backward surface in the first geometric surface.
[0008] Preferably, drawing a profile for the first geometric surface includes: drawing a first profile for the forward face of the first geometric surface, and / or drawing a second profile for the backward face of the first geometric surface.
[0009] Preferably, when the first contour of the front face and the second contour of the back face have an overlapping portion, the overlapping portion is deleted from the second contour of the back face.
[0010] Preferably, determining the forward and backward surfaces in the first geometric surface based on the three-dimensional coordinates of the feature points of the first geometric surface includes:
[0011] Three feature points are identified from the feature points of the first geometric surface, and these three feature points constitute a sub-surface of the first geometric surface. Two three-dimensional vectors are generated based on the three-dimensional coordinates of the three feature points. Based on the two three-dimensional vectors, it is determined whether the sub-surface of the first geometric surface formed by the three feature points is a forward surface or a backward surface.
[0012] Preferably, determining whether a sub-surface of the first geometric surface formed by three feature points is a forward surface or a backward surface based on two three-dimensional vectors includes: performing a cross product operation on the two three-dimensional vectors; and determining whether a sub-surface of the first geometric surface formed by the three feature points is a forward surface or a backward surface based on the result of the cross product operation.
[0013] Preferably, drawing the first geometric surface includes: when the first geometric surface includes a forward surface and a backward surface, filling the backward surface and the forward surface in sequence to complete the drawing of the first geometric surface.
[0014] Secondly, embodiments of this application provide a device for drawing three-dimensional geometric figures. The three-dimensional geometric figures to be drawn include multiple geometric surfaces, including:
[0015] The determination module is used to determine the three-dimensional coordinates of the feature points of the first geometric surface in a three-dimensional coordinate system based on the parameter information of the target center and the three-dimensional geometric figure to be drawn. The first geometric surface is any one of multiple geometric surfaces, and the parameter information includes at least one side length of the smallest cuboid that can accommodate the three-dimensional geometric figure to be drawn.
[0016] The processing module is used to draw the first geometric surface based on the three-dimensional coordinates of the feature points of the first geometric surface, and to draw the outline of the first geometric surface.
[0017] Thirdly, embodiments of this application also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method for drawing three-dimensional geometric figures as described in the first aspect.
[0018] Fourthly, embodiments of this application also provide a computer-readable storage medium storing computer instructions that, when executed on a computer, cause the computer to perform the method for drawing three-dimensional geometric figures as described in the first aspect.
[0019] Fifthly, embodiments of this application also provide a computer program product, which includes a computer program that, when run on a computer, implements the method for drawing three-dimensional geometric figures as described in the first aspect.
[0020] This application provides a method for drawing three-dimensional geometric figures, comprising: determining the three-dimensional coordinates of feature points of a first geometric surface in a three-dimensional coordinate system based on parameter information of the target center and the three-dimensional geometric figure to be drawn; drawing the first geometric surface based on the three-dimensional coordinates of the feature points of the first geometric surface, and drawing the outline of the first geometric surface. The first geometric surface is any one of multiple geometric surfaces of the three-dimensional geometric figure. After drawing the first geometric surface, other geometric surfaces are drawn in the same way, thereby realizing the drawing of the three-dimensional geometric figure. Since each geometric surface is drawn separately, the drawing information of the first geometric surface is saved during drawing. After the three-dimensional geometric figure is drawn, each geometric surface of the three-dimensional geometric figure can be processed separately according to the drawing information of each geometric surface of the three-dimensional geometric figure, realizing more demonstration functions and more effectively helping users understand the three-dimensional structure of the three-dimensional geometric figure. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 This is a flowchart illustrating a method for drawing three-dimensional geometric figures provided in an embodiment of this application;
[0023] Figure 2 This is a flowchart illustrating another method for drawing three-dimensional geometric figures provided in an embodiment of this application;
[0024] Figure 3 This is a schematic diagram of drawing a cuboid provided in an embodiment of this application;
[0025] Figure 4 This is a schematic diagram of drawing a cylinder provided in an embodiment of this application;
[0026] Figure 5 This is a schematic diagram of drawing a cone provided in an embodiment of this application;
[0027] Figure 6 This is a schematic diagram of the structure of a three-dimensional geometric drawing device provided in an embodiment of this application;
[0028] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0029] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0030] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of embodiments of this application, unless otherwise stated, "multiple" means two or more, and "at least one" or "one or more" means one, two, or more.
[0031] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0032] While numerous powerful and widely used graphics libraries exist for drawing 2D and 3D vector graphics, they are not always suitable for drawing relatively simple 3D geometric shapes (such as cuboids, cylinders, and cones). Professional graphics libraries are typically large, requiring a significant time investment to learn their usage and reach a certain level of proficiency before drawing. This high learning curve makes them inaccessible to non-professional drafters. Furthermore, professional graphics libraries are computationally intensive, demanding high-performance hardware. Finally, they often limit drawing to specific platforms, failing to meet the requirements for drawing on specific devices or windows.
[0033] Combining graphics libraries with drawing software through interfaces can solve some problems. However, graphics libraries mainly emphasize drawing, and drawing software cannot obtain information about the drawn graphics. As a result, the drawn 3D geometric figures can only achieve simple display effects and cannot realize more demonstration functions.
[0034] For example, in a teaching setting, a smart blackboard is installed in the classroom. The smart blackboard can be equipped with drawing software to draw a cuboid. At this time, only the cuboid can be displayed, but the unfolding process of the cuboid cannot be demonstrated, or the effects of clicking on a face or edge, or the changes in the cuboid during rotation, can be shown.
[0035] Therefore, this application provides a method for drawing three-dimensional geometric figures. When drawing three-dimensional geometric figures, each geometric surface of the three-dimensional geometric figure is drawn separately, and the drawing information of each geometric surface is saved. After the three-dimensional geometric figure is drawn, each geometric surface of the three-dimensional geometric figure can be processed according to the drawing information to realize more demonstration functions and more effectively help users understand the three-dimensional structure of the three-dimensional geometric figure.
[0036] The method for drawing three-dimensional geometric figures provided in this application can be applied to electronic devices such as smartphones, tablets, laptops, ultra-mobile personal computers (UMPCs), netbooks, and personal digital assistants (PDAs). This application does not impose any limitations on the specific type of electronic device.
[0037] The present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0038] Figure 1 This is a flowchart illustrating a method for drawing three-dimensional geometric figures, as provided in an embodiment of this application. Figure 1 As shown, the method includes:
[0039] S101: In a three-dimensional coordinate system, based on the parameter information of the target center and the three-dimensional geometric figure to be drawn, determine the three-dimensional coordinates of the feature points of the first geometric surface. The first geometric surface is any one of multiple geometric surfaces, and the parameter information includes at least one side length of the smallest cuboid that can accommodate the three-dimensional geometric figure to be drawn.
[0040] Generally, multiple feature points form edges, multiple edges form faces, and multiple faces form three-dimensional geometric figures. Therefore, the three-dimensional geometric figure to be drawn includes multiple geometric faces (planar or curved surfaces), which are the surfaces of the three-dimensional geometric figure to be drawn. For example, a cuboid includes 6 geometric faces. A cylinder includes 3 geometric faces: the top face, the bottom face, and the lateral face. A cone includes 2 geometric faces: the bottom face and the lateral face. The first geometric face can be any one of the multiple geometric faces; for example, for a cylinder, the first geometric face can be the lateral face.
[0041] The parameter information of the 3D geometric figure to be drawn is used to determine its shape and size. The parameter information includes at least one side length of the smallest cuboid capable of accommodating the 3D geometric figure. The smallest cuboid is the circumscribed cuboid of the 3D geometric figure, and its side length determines the size of the 3D geometric figure. For example, the parameter information of a cuboid is its length, width, and height; the parameter information of a cylinder is the base and lateral edge lengths of its circumscribed regular square prism, the diameters of the corresponding base and top circles, and the height of the cylinder.
[0042] When drawing three-dimensional geometric figures, the first step is to determine the three-dimensional coordinate system. In this embodiment, a left-handed coordinate system is used as the three-dimensional coordinate system. The positive x-axis points to the right horizontally from the electronic device, the positive y-axis points downward vertically from the electronic device, and the positive z-axis points outward from the plane perpendicular to the electronic device. The human eye (or camera) can observe the three-dimensional geometric figures perpendicular to the electronic device, with the line of sight extending from the outside of the electronic device inward (i.e., the z-axis of the left-handed coordinate system is reversed).
[0043] In a 3D coordinate system, a point is designated as the target center, which is the center point of the 3D geometry to be drawn. For example, the origin of the 3D coordinate system to be drawn can be set as the target center.
[0044] Then, input the parameter information of the 3D geometric figure. Based on the parameter information and the target center, determine the 3D coordinates (x, y, z) of multiple feature points constituting the 3D geometric figure. For example, inputting the length, width, and height of a cuboid will yield the 3D coordinates of its eight vertices. Inputting the parameter information of a cylinder will yield the 3D coordinates of points on its base and top circles. Inputting the parameter information of a cone will yield the 3D coordinates of points on its base circle and vertices. Each feature point is then divided into regions, and further, the 3D coordinates of the feature points forming each geometric surface are determined.
[0045] S102: Draw the first geometric surface based on the three-dimensional coordinates of the feature points of the first geometric surface, and draw the outline of the first geometric surface.
[0046] The components of a three-dimensional geometric figure include faces and contours. In this embodiment, the information of the first geometric face includes: the region corresponding to the first geometric face, and whether the first geometric face is a forward face or a backward face. The three-dimensional geometric figure is observed by a human eye or a virtual camera from a first direction and a specific distance. The first direction can be the reverse of the z-axis of the three-dimensional coordinate system. The forward face is the displayed face (that can be observed), and the backward face is the hidden face (that cannot be observed).
[0047] The contour (also called the edge) of the first geometric surface is formed by edges connecting feature points. Contour information includes: which edge is the contour, and whether the contour is a forward face or a backward face. The contour of a forward face is not occluded by the faces of the 3D geometry and can be observed, while the contour of a backward face is occluded by the faces of the 3D geometry and cannot be observed.
[0048] When drawing 3D geometric figures, the information of the first geometric surface and its contour are obtained based on the 3D coordinates of its feature points, and then the first geometric surface is drawn. Other geometric surfaces are drawn using the same method. Contours are then drawn for the first and other geometric surfaces sequentially. Drawing information can be cached or stored during the drawing process. After drawing is complete, the 3D geometric figures can be transformed in various ways based on the cached or stored drawing information.
[0049] Specifically, when determining the drawing information of the first geometric surface, it can be divided into a small number of sub-surfaces, such as consecutive small triangles or rectangles. The drawing information of the first geometric surface is determined on a unit based on these sub-surfaces. Figure 2 The diagram shown is a flowchart of another method for drawing three-dimensional geometric figures provided in an embodiment of this application. The method includes:
[0050] S201: In a three-dimensional coordinate system, based on the parameter information of the target center and the three-dimensional geometric figure to be drawn, determine the three-dimensional coordinates of the feature points of the first geometric surface. The first geometric surface is any one of multiple geometric surfaces.
[0051] S202: Determine three feature points from the feature points of the first geometric surface, and the three feature points constitute a sub-surface of the first geometric surface.
[0052] S203: Generate two three-dimensional vectors based on the three-dimensional coordinates of the three feature points.
[0053] S204: Based on two three-dimensional vectors, determine whether the sub-surface of the first geometric surface formed by three feature points is the forward surface or the backward surface.
[0054] S205: Draw the first geometric surface based on the forward and / or backward surfaces in the first geometric surface.
[0055] Three feature points pt0, pt1, and pt2 are selected from multiple feature points on the first geometric surface in a specific order. For example, when viewing a surface from the front, three 3D coordinate points are selected in a counter-clockwise direction. When a surface is the front view, points on other surfaces need to be mapped onto the front view first.
[0056] A sub-surface is represented by a sequence of three-dimensional coordinate points [pt0, pt1, pt2]. This yields two three-dimensional vectors, a0 and a1, where a0 is represented as (pt1 - pt0) and a1 as (pt2 - pt1). The cross product of a0 and a1 results in a three-dimensional vector (x', y', z'). If the value of z' is greater than 0, the sub-surface represented by this three-dimensional coordinate point sequence is considered a forward surface; otherwise, it is considered a backward surface. The contours on the forward surface are statistically analyzed as the forward surface contours, and the contours on the backward surface are statistically analyzed as the backward surface contours.
[0057] Based on the vector cross product operation, it can be determined whether each sub-face of the first geometric surface is a forward face or a backward face. The sub-faces of the first geometric surface may all be forward faces or all be backward faces. For example, if one side of a cube is a forward face, all its sub-faces are forward faces, and the sub-faces of the face opposite that side are all backward faces; that is, the face opposite that side is a backward face. The sub-faces of the first geometric surface may also include both forward and backward faces. For example, if the first geometric surface is the side of a cylinder, when viewing the side from any direction, some of the sub-faces are forward faces, and some are backward faces.
[0058] In this embodiment of the application, after determining the forward surface and / or backward surface in the first geometric surface, the backward surface is filled first and then the forward surface is filled during drawing, thereby achieving the effect of depth testing (i.e., the occluded backward surface is not visible, and the forward surface is visible). Then, a first contour is drawn for the forward surface and a second contour is drawn for the backward surface to obtain a three-dimensional geometric figure.
[0059] When the first contour corresponding to the forward surface in the first geometric plane overlaps with the second contour corresponding to the backward surface, or when the first contour corresponding to the forward surface in the first geometric plane overlaps with the second contour corresponding to the backward surface in other geometric planes, the overlapping part is deleted from the contour information corresponding to the backward surface to avoid drawing the contour repeatedly. The contour line corresponding to the forward surface can be drawn with a solid line, and the contour line corresponding to the backward surface can be drawn with a dashed line.
[0060] When filling surfaces or drawing outlines, the z-coordinate in the 3D coordinate system is ignored, and the 3D coordinate system is used as a 2D coordinate system.
[0061] The method provided in this application embodiment can draw simple 3D geometric figures with good visual effects without learning complex professional graphics libraries, without the need for depth testing, and with high drawing efficiency. It saves surface and contour information during drawing for use in implementing more demonstration functions, making it very suitable for drawing and editing relatively small 2D and 3D geometric figures.
[0062] After drawing a 3D geometric figure based on the drawing information, you can perform operations such as rotation, translation, scaling, and disassembly on the 3D geometric figure. You can also set the display format of each face and each edge of the 3D geometric figure, such as color and line style, so as to achieve different demonstration effects.
[0063] When performing operations such as rotation, translation, scaling, and disassembly on a three-dimensional geometric figure, the three-dimensional coordinates of the feature points of the three-dimensional geometric figure will change. In this embodiment, a three-dimensional coordinate mapping matrix is used to determine the three-dimensional coordinates of the feature points after different operations.
[0064] The 3D coordinate mapping matrix is a 4×4 matrix (4 rows, 4 columns) containing rotation angles around the x, y, and z axes, scaling factors in the x, y, and z directions, and offsets in the x, y, and z directions. Expanding the 3D coordinates (x0, y0, z0) to (x0, y0, z0, 1) and multiplying it with the 3D coordinate mapping matrix yields the mapping result (x0', y0', z0', 1). This mapping result represents the new 3D coordinates of (x0', y0', z0') after rotation, scaling, and translation according to the transformation information contained in the 3D coordinate mapping matrix. The rendering information for the 3D geometry is then determined based on these new 3D coordinates.
[0065] The method provided in this application, through three-dimensional coordinate mapping and the sign of the z-value of the cross product calculation result, can determine the coordinates of feature points of a three-dimensional geometric figure in real time, and determine surface and contour information in real time. It eliminates the need for complex calculations, improves computational efficiency, and facilitates demonstrations using three-dimensional geometric figures. Furthermore, it conveniently provides a drawing interface for drawing software, allowing the three-dimensional geometric figures to be drawn on different drawing devices.
[0066] The following explanation uses cuboids, cylinders, and cylindrical shapes as examples.
[0067] 1. Methods for collecting and drawing the outline and face information of a cuboid
[0068] like Figure 3 As shown, the eight vertices of the cuboid are (x0, y0, z0), (x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4), (x5, y5, z5), (x6, y6, z6), and (x7, y7, z7). Based on the aforementioned three-dimensional coordinate system and the method for selecting feature points, we analyze surface01{(x0, y0, z0),(x1, y1, z1),(x2, y2, z2),(x3, y3, z3)} and surface02{(x4, y4, z4),(x5, y5, z5),(x6, y6, z6),(x7, y7, z7)}.
[0069] On surface01, extract the first three points (x0, y0, z0), (x1, y1, z1), and (x2, y2, z2) to obtain two vectors v0 and v1, represented as (x1-x0, y1-y0, z1-z0) and (x2-x1, y2-y1, z2-z1) respectively. Perform a cross product operation on v0 and v1. Since the cross product of vectors satisfies the right-hand rule, the result vector points outward from the display device, in the same direction as the positive z-axis (not necessarily perpendicular to the display device outward), and opposite to the direction of human eye (or camera) observation. It is the surface that can be observed by human eye (camera). Therefore, surface01 is a forward surface, and its contour is a forward surface contour.
[0070] Analyzing surface02, extracting the first three points (x4, y4, z4), (x5, y5, z5), and (x6, y6, z6), we can obtain two vectors v2 and v3, represented as (x5-x4, y5-y4, z6-z4) and (x6-x5, y6-y5, z6-z5) respectively. Performing a cross product operation on v2 and v3, we can see that it is a backward surface, and its contour is the contour of a backward surface.
[0071] Using the same method to determine the information of each face of the cuboid, when drawing each face of the cuboid, first fill all the back faces, and then fill all the front faces to achieve the effect of depth testing, that is, the occluded back faces cannot be observed by the human eye, while the front faces can be observed by the human eye.
[0072] Some contours may be classified as both forward and backward contours, such as the contour composed of points (x5, y5, z5) and (x6, y6, z6). After all contour information is statistically analyzed, all backward contours are checked. If a backward contour is also a forward contour, it is removed from the backward contour set.
[0073] After all faces are drawn and filled, draw all outlines. Use solid lines to draw the front face outlines and dashed lines to draw the back face outlines to distinguish the front and back of the 3D geometry, which helps users understand the 3D geometry.
[0074] 2. Methods for collecting and drawing the contour and surface information of a cylinder
[0075] like Figure 4As shown, sampling is performed on the top circular surface of the cylinder. When the sampling density reaches a certain level, the polygon formed by connecting the sampling points can approximate the circle. Three sampling points, p0, p1, and p2, are selected, where p0, p1, and c0 form a triangle triangle0, with c0 being the center of the top circular surface. According to the forward surface determination method, the cross product of vectors (p1-p0) and (c0-p1) is performed, revealing triangle0 as the forward surface, and the line connecting p0 and p1 is the outline of the forward surface.
[0076] By performing a cross product on vectors (p2-p1) and (c0-p2), we can see that the triangle formed by points p1, p2, and c0, triangle1, is also a forward face, and the line connecting p1 and p2 is the contour of the forward face. Using this method, we can statistically determine that all sampling points on the top circle and the triangle formed by c0 are forward faces, and the lines connecting all adjacent sampling points are the contours of the forward face.
[0077] Sampling is performed on the bottom and top circular surfaces of the cylinder, where c1 is the center of the bottom circular surface. The forward and backward surfaces on the bottom circular surface of the cylinder, as well as the contours of the forward and backward surfaces, are determined according to the aforementioned method.
[0078] The lateral surface of a cylinder can be approximated by a series of rectangular surfaces, such as... Figure 4 As shown, sampling points p0, p1, and p2 are selected on the top circle, and sampling points p3, p4, and p5 are selected on the bottom circle. The lines connecting p0 and p3, p1 and p4, and p2 and p5 are all parallel to the line connecting c0 and c1.
[0079] Sampling points p0, p1, p3, and p4 form a rectangular surface rectangle01, and sampling points p1, p2, p4, and p5 form a rectangular surface rectangle02. Following the aforementioned method, analyzing rectangular surfaces rectangle01:{p3,p4,p1,p0} and rectangle02:{p4,p5,p2,p1}, we can conclude that rectangle01 is a backward surface with a corresponding backward surface contour, and rectangle02 is a forward surface with a corresponding forward surface contour.
[0080] When analyzing the rectangular faces corresponding to all sampling points, it is also necessary to calculate which four sampling points are the closest approximate side profile of the cylinder, i.e., the leftmost and rightmost profiles of the cylinder as observed by the human eye or camera. The calculation method is as follows: if a rectangular face is a forward face, record its direction value as 1; if a rectangular face is a backward face, record its direction value as -1; when the direction values of a rectangular face and its preceding rectangular face are different, the line connecting the two points shared by the rectangular face and its preceding rectangular face is recorded as the closest approximate side profile. For example, Figure 4If rectangle01 is the back face and rectangle02 is the front face, then the line connecting the common points p1 and p4 of these two rectangles is the closest approximate side profile. Using the same method, another closest approximate side profile can be obtained, and thus the side profile of the rectangle can be drawn using the calculated closest approximate side profile.
[0081] Based on the above analysis, we can obtain the drawing information for the cylinder, including: the set of sub-triangles of the top circle and all front and back face contours; the set of sub-triangles of the bottom circle and all front and back face contours; the set of sub-rectangles of the side face and all front and back face contours; and the cylinder's most approximate side face contour. Using this drawing information, draw the cylinder in the following order:
[0082] ① Fill all the back faces, then fill all the front faces (this can achieve the effect of depth testing);
[0083] ② Draw the front and back outlines of the top and bottom circles;
[0084] ③ Draw the front outline of the side surface to avoid drawing the common back outline of the side and bottom circles twice, which would result in the back outline not being a dashed line.
[0085] ④ Draw the two closest side profile lines.
[0086] 3. Methods for collecting and drawing the contour and surface information of a cone.
[0087] The methods for collecting and drawing the contour and surface information of a cone are similar to those for a cylinder. For example... Figure 5 As shown, the center of the base circle of the cone is c3, and the vertex is c4. Sampling is performed on the base circle, and each pair of adjacent points is connected to the center of the base circle to form a triangular face, which is then analyzed. For example, if the sampling points are p6, p7, and p8, the triangular faces {p7, p6, c3} and {p8, p7, c3} are analyzed. Similarly, each pair of adjacent points is connected to the vertex to form a triangular face, which is then analyzed. For example, the triangular faces {p7, p6, c4} and {p8, p7, c4} are analyzed.
[0088] The set of sub-triangles of the base circle and all the front and back face contours, and the set of sub-triangles of the side face and all the front and back face contours are determined according to the aforementioned method; the two most approximate side face contours of the cone are obtained using a method similar to that used for the cylinder.
[0089] To draw a cone, fill the back face, then fill the front face, and finally draw all the contour lines and the closest approximate side contour line to obtain the desired shape. Figure 5 The cone shown.
[0090] The embodiments of a method for drawing three-dimensional geometric figures provided by the present invention have been described in detail above. The present invention also provides a three-dimensional geometric figure drawing device, electronic device, and computer-readable storage medium corresponding to the method. Since the embodiments of the device, electronic device, and computer-readable storage medium correspond to the embodiments of the method, please refer to the description of the embodiments of the method for the embodiments of the device, electronic device, and computer-readable storage medium, and they will not be repeated here.
[0091] Figure 6 The three-dimensional geometric drawing device 600 provided in the embodiments of this application includes a determining module 601 and a processing module 602.
[0092] The determination module 601 is used to determine the three-dimensional coordinates of the feature points of the first geometric surface in a three-dimensional coordinate system based on the parameter information of the target center and the three-dimensional geometric figure to be drawn. The first geometric surface is any one of multiple geometric surfaces, and the parameter information includes at least one side length of the smallest cuboid that can accommodate the three-dimensional geometric figure to be drawn.
[0093] The processing module 602 is used to draw the first geometric surface based on the three-dimensional coordinates of the feature points of the first geometric surface, and to draw the outline of the first geometric surface.
[0094] Preferably, the processing module 602 is further configured to determine the forward surface and / or backward surface in the first geometric surface based on the three-dimensional coordinates of the feature points of the first geometric surface, wherein the forward surface is the surface displayed when the three-dimensional geometric figure is viewed from the first direction, and the backward surface is the surface hidden when the three-dimensional geometric figure is viewed from the first direction.
[0095] Preferably, the processing module 602 is further configured to draw a first profile for the forward face in the first geometric plane, and / or to draw a second profile for the backward face in the first geometric plane.
[0096] Preferably, the processing module 602 is further configured to delete the overlapping portion in the second contour of the rearward surface when the first contour of the current surface and the second contour of the rearward surface overlap.
[0097] Preferably, the processing module 602 is further configured to determine three feature points from the feature points of the first geometric surface, the three feature points constituting a sub-surface of the first geometric surface; generate two three-dimensional vectors based on the three-dimensional coordinates of the three feature points; and determine whether the sub-surface of the first geometric surface formed by the three feature points is a forward surface or a backward surface based on the two three-dimensional vectors.
[0098] Preferably, the processing module 602 is further configured to perform a cross product operation on the two three-dimensional vectors, and determine whether the sub-surface of the first geometric surface formed by the three feature points is a forward surface or a backward surface based on the result of the cross product operation.
[0099] Preferably, the processing module 602 is further configured to fill the backward surface and the forward surface in sequence when the first geometric surface includes a forward surface and a backward surface, thereby completing the drawing of the first geometric surface.
[0100] It should be understood that the device 600 in this application embodiment can be implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD can be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof. It can also be implemented using software. Figure 1 The method for drawing the three-dimensional geometric figures shown is implemented using software. Figure 1 When drawing the three-dimensional geometric figures shown, the device 600 and its various modules can also be software modules.
[0101] Figure 7 This is a schematic diagram of the structure of an electronic device 700 provided in an embodiment of this application. Figure 7 As shown, the device 700 includes a processor 701, a memory 702, a communication interface 703, and a bus 704. The processor 701, memory 702, and communication interface 703 communicate via the bus 704, or via other means such as wireless transmission. The memory 702 stores instructions, and the processor 701 executes the instructions stored in the memory 702. The memory 702 stores program code 7021, and the processor 701 can call and execute the program code 7021 stored in the memory 702. Figure 1 The method for drawing the three-dimensional geometric figures shown.
[0102] It should be understood that in the embodiments of this application, processor 701 may be a CPU, or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. General-purpose processors may be microprocessors or any conventional processors, etc.
[0103] The memory 702 may include read-only memory and random access memory, and provides instructions and data to the processor 701. The memory 702 may also include non-volatile random access memory. The memory 702 may be volatile memory or non-volatile memory, or may include both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory may be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).
[0104] In addition to the data bus, the 704 bus may also include a power bus, a control bus, and a status signal bus. However, for clarity, in... Figure 7 The general designated all buses as Bus 704.
[0105] The above embodiments can be implemented, in whole or in part, by software, hardware, firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded or executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more sets of available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium. A semiconductor medium can be a solid-state drive (SSD).
[0106] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A method for drawing a three-dimensional geometric figure, wherein the three-dimensional geometric figure to be drawn includes multiple geometric surfaces, characterized in that, The method includes: In a three-dimensional coordinate system, based on the parameter information of the target center and the three-dimensional geometric figure to be drawn, the three-dimensional coordinates of the feature points of the first geometric surface are determined. The first geometric surface is any one of the plurality of geometric surfaces. The parameter information includes at least one side length of the smallest cuboid capable of accommodating the three-dimensional geometric figure to be drawn. The parameter information of the three-dimensional geometric figure to be drawn is used to determine the shape and size of the three-dimensional geometric figure to be drawn. The target center is the center point of the three-dimensional geometric figure to be drawn. Based on the three-dimensional coordinates of the feature points of the first geometric surface, draw the first geometric surface and draw its outline; After drawing the first geometric surface, draw the other geometric surfaces in the same way to achieve the drawing of the three-dimensional geometric figure; The step of drawing the first geometric surface based on the three-dimensional coordinates of the feature points of the first geometric surface includes: splitting the first geometric surface into sub-surfaces, and determining the drawing information of the first geometric surface in units of the split sub-surfaces; the step of splitting the first geometric surface into sub-surfaces and determining the drawing information of the first geometric surface in units of the split sub-surfaces includes: determining three feature points from the feature points of the first geometric surface, the three feature points constituting the sub-surfaces of the first geometric surface; generating two three-dimensional vectors based on the three-dimensional coordinates of the three feature points; and performing a cross product operation on the two three-dimensional vectors to obtain a three-dimensional vector (x). ' y ' , z ' If the obtained z ' If the value is greater than 0, the sub-face of the first geometric surface formed by the three feature points is determined to be the forward face; otherwise, it is the backward face. During drawing, the backward face is filled first, then the forward face is filled. After all faces are drawn and filled, a first contour is drawn for the forward face and a second contour is drawn for the backward face to obtain a three-dimensional geometric figure. The forward face is the face that is displayed when the three-dimensional geometric figure is viewed from the first direction, and the backward face is the face that is hidden when the three-dimensional geometric figure is viewed from the first direction. While drawing, the surface information and outline information are saved. After drawing the 3D geometric figure, the color and line style of each face and each edge of the 3D geometric figure can be set by rotating, translating, scaling and disassembling the 3D geometric figure to achieve different demonstration effects. The 3D coordinates of feature points after different operations are determined using a 4×4 coordinate mapping matrix. This matrix includes rotation angles around the x, y, and z axes, scaling factors in the x, y, and z directions, and offsets in the x, y, and z directions. The 3D coordinates (x0, y0, z0) are expanded to (x0, y0, z0, 1) and multiplied by the 3D coordinate mapping matrix to obtain the mapping result (x0, y0, z0, 1). ' y0 ' z0 ' ,1), the mapping result is the coordinate (x0) ' y0 ' z0 ' The new three-dimensional coordinates are rotated, scaled, and translated according to the transformation information contained in the three-dimensional coordinate mapping matrix; the drawing information of the three-dimensional geometry is determined based on the new three-dimensional coordinates, so as to determine the coordinates of the feature points of the three-dimensional geometry in real time, and to determine the surface information and contour information in real time.
2. The method according to claim 1, characterized in that, The method further includes: When the first contour and the second contour have overlapping portions, the overlapping portions are deleted from the second contour.
3. A device for drawing three-dimensional geometric figures, wherein the three-dimensional geometric figure to be drawn includes multiple geometric surfaces, characterized in that, The device includes: The determining module is used to determine the three-dimensional coordinates of feature points of a first geometric surface in a three-dimensional coordinate system based on parameter information of the target center and the three-dimensional geometric figure to be drawn. The first geometric surface is any one of the plurality of geometric surfaces. The parameter information includes at least one side length of the smallest cuboid capable of accommodating the three-dimensional geometric figure to be drawn. The parameter information of the three-dimensional geometric figure to be drawn is used to determine the shape and size of the three-dimensional geometric figure to be drawn. The target center is the center point of the three-dimensional geometric figure to be drawn. The processing module is used to draw the first geometric surface based on the three-dimensional coordinates of the feature points of the first geometric surface, and to draw the outline of the first geometric surface. After drawing the first geometric surface, draw the other geometric surfaces in the same way to achieve the drawing of the three-dimensional geometric figure; The step of drawing the first geometric surface based on the three-dimensional coordinates of the feature points of the first geometric surface includes: splitting the first geometric surface into sub-surfaces, and determining the drawing information of the first geometric surface in units of the split sub-surfaces; the step of splitting the first geometric surface into sub-surfaces and determining the drawing information of the first geometric surface in units of the split sub-surfaces includes: determining three feature points from the feature points of the first geometric surface, the three feature points constituting the sub-surfaces of the first geometric surface; generating two three-dimensional vectors based on the three-dimensional coordinates of the three feature points; and performing a cross product operation on the two three-dimensional vectors to obtain a three-dimensional vector (x). ' y ' , z ' If the obtained z ' If the value is greater than 0, the sub-face of the first geometric surface formed by the three feature points is determined to be the forward face; otherwise, it is the backward face. During drawing, the backward face is filled first, then the forward face is filled. After all faces are drawn and filled, a first contour is drawn for the forward face and a second contour is drawn for the backward face to obtain a three-dimensional geometric figure. The forward face is the face that is displayed when the three-dimensional geometric figure is viewed from the first direction, and the backward face is the face that is hidden when the three-dimensional geometric figure is viewed from the first direction. While drawing, the surface information and outline information are saved. After drawing the 3D geometric figure, the color and line style of each face and each edge of the 3D geometric figure can be set by rotating, translating, scaling and disassembling the 3D geometric figure to achieve different demonstration effects. The 3D coordinates of feature points after different operations are determined using a 3D coordinate mapping matrix. This 4×4 matrix includes rotation angles around the x, y, and z axes, scaling factors in the x, y, and z directions, and offsets in the x, y, and z directions. The 3D coordinates (x0, y0, z0) are expanded to (x0, y0, z0, 1) and multiplied by the 3D coordinate mapping matrix to obtain the mapping result (x0, y0, z0, 1). ' y0 ' z0 ' ,1), the mapping result is the coordinate (x0) ' y0 ' z0 ' The new three-dimensional coordinates are rotated, scaled, and translated according to the transformation information contained in the three-dimensional coordinate mapping matrix; the drawing information of the three-dimensional geometry is determined based on the new three-dimensional coordinates, so as to determine the coordinates of the feature points of the three-dimensional geometry in real time, and to determine the surface information and contour information in real time.
4. An electronic device, characterized in that, include: A memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the method as described in any one of claims 1 to 2.
5. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed on an electronic device, cause the electronic device to perform the method as described in any one of claims 1 to 2.
Citation Information
Patent Citations
Three-dimensional graph rendering method, apparatus and equipment and storage medium
CN107248192A