A method and system for automatic alignment of three-dimensional engine geometric bodies based on three-dimensional vectors
By calculating the distance between the alignment points of the three-dimensional geometry in the world coordinate system and automatically updating the position of the alignment geometry, it solves the time-consuming, laborious and error-prone problems of traditional manual alignment, and achieves efficient and accurate alignment of the three-dimensional model.
Patent Information
- Application Number
- CN202410726504.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-06
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-06-06
Smart Images

Figure CN118298142B
Abstract
Description
Technical Field
[0001] The present invention relates to the intersection of computer graphics and three-dimensional modeling technology, and in particular to a three-dimensional engine geometric body automatic alignment method and system based on three-dimensional vectors. Background Art
[0002] In the practice of 3D modeling and rendering, precise alignment between geometric bodies is a key link in shaping high-quality models, ensuring the accuracy of physical simulation, and improving the convenience of subsequent operations. However, traditional alignment methods mainly rely on manual adjustments, which are not only time-consuming and labor-intensive, but also prone to alignment errors due to human factors. Although some 3D software on the market have built-in basic alignment tools, such as axis alignment and surface fitting, the functional limitations of such tools are exposed when it comes to the alignment of complex and irregular geometric bodies, or when it involves specific alignment rules such as point-to-point, line-to-line, and face-to-face. Therefore, the industry urgently needs a more intelligent and efficient solution for automatic alignment of geometric bodies to meet the increasingly complex 3D design needs. Summary of the invention
[0003] In order to realize the high automation and precision of the geometric body alignment process, the present invention provides a three-dimensional engine geometric body automatic alignment method and system based on three-dimensional vectors.
[0004] In a first aspect, the present invention provides a method for automatic alignment of three-dimensional engine geometric bodies based on three-dimensional vectors, which adopts the following technical solution:
[0005] A method for automatic alignment of 3D engine geometry based on 3D vectors, comprising the following steps:
[0006] Step S1, respectively obtaining the world coordinate systems of the reference geometry and the alignment geometry;
[0007] Step S2, respectively obtaining the world coordinate three-dimensional vectors of the points to be aligned in the reference geometric body and the alignment geometric body;
[0008] Step S3, calculating the distance between the reference geometric body and the point to be aligned in the aligned geometric body according to the world coordinate three-dimensional vector;
[0009] Step S4, updating the world coordinates of the aligned geometric body according to the distance to complete the alignment.
[0010] By adopting the above technical solution, the position of the aligned geometry is updated by calculating the distance between the alignment points in the world coordinate system, without the need for manual alignment adjustment. In addition, the accuracy of the alignment result is ensured by calculating the three-dimensional vector of the world coordinate system, making the geometry alignment process highly automated and precise.
[0011] Optionally, the specific steps of step S1 include:
[0012] Get the initial world coordinate systems of the reference geometry and the alignment geometry respectively;
[0013] Determine whether the initial world coordinate systems of the reference geometry and the aligned geometry are consistent with the transformed coordinate systems;
[0014] When it is determined that they are consistent, the initial world coordinate system of the reference geometry and / or the alignment geometry is converted to the reference world coordinate system;
[0015] When it is judged to be inconsistent, the initial world coordinate system is the reference world coordinate system.
[0016] By adopting the above technical solution, there are two world coordinate systems, the left-hand system and the right-hand system. The coordinate systems are unified through conversion to avoid the situation where the graphics do not meet the user's expectations after alignment due to different coordinate systems.
[0017] Optionally, the step of converting the initial world coordinate system of the reference geometry and / or the alignment geometry into the reference world coordinate system comprises:
[0018] Determine the flip axis and flip direction to set the flip matrix;
[0019] Multiply the initial world coordinate system coordinate by the flip matrix to obtain the reference world coordinate system coordinate;
[0020] The reference geometry and / or alignment geometry are transformed into the reference world coordinate system.
[0021] Optionally, the step of converting the initial world coordinate system of the reference geometry and / or the alignment geometry into the reference world coordinate system comprises:
[0022] Keep the Z axis unchanged, flip the X axis, and set the flip matrix FlipMatrix
[0023] ;
[0024] A(x,y,z)*FlipMatrix=A1(-x,y,z);
[0025] Where A is the initial world coordinate system coordinate of the reference geometry or alignment geometry, and A1 is the reference world coordinate system coordinate of the reference geometry or alignment geometry after transformation.
[0026] Optionally, the conversion coordinate system includes a right-hand coordinate system, the reference world coordinate system includes a left-hand coordinate system, and the three-dimensional engine world coordinate zero point is taken as the coordinate system zero point.
[0027] By adopting the above technical solution, since the left-handed system is more consistent with the understanding of space in daily life, the left-handed system is used as the reference world coordinate system for coordinate system unification and subsequent alignment.
[0028] Optionally, the specific steps of step 2 include:
[0029] Get the coordinates of the point on the reference geometry that needs to be aligned, and convert the coordinates of the point from local coordinates to a three-dimensional vector of world coordinates;
[0030] Get the coordinates of the point that needs to be aligned to the geometry, and convert the coordinates of the point from local coordinates to a world coordinate 3D vector.
[0031] By adopting the above technical solution, the coordinate system is converted so that the points to be aligned are in the world coordinate system, and then the distance is calculated, so as to avoid the graphics not meeting the user's expectations after alignment due to different coordinate systems.
[0032] Optionally, the step of converting the point to be aligned from the local coordinates to the world coordinate three-dimensional vector includes:
[0033] Use the alignment point as a child of the reference geometry or alignment geometry and obtain the local coordinates of the child object;
[0034] Convert the alignment point from the child object's local coordinates to the parent object's local coordinates;
[0035] Convert the parent object's local coordinates to world coordinates.
[0036] By adopting the above technical solution, the points to be aligned are converted to the parent object coordinate system through the conversion of the coordinate system, and then converted to the world coordinate system, and then the distance is calculated, so as to avoid the graphics not meeting the user's expectations after alignment due to different coordinate systems, which is more convenient for calculation.
[0037] Optionally, the distance calculation method in step 3 is:
[0038] X = α-β;
[0039] Where α is the world coordinate 3D vector of the reference geometry alignment point, and β is the world coordinate 3D vector of the alignment geometry alignment point;
[0040] The method to update the world coordinates of the aligned geometry in step 4 is:
[0041] B1=B+X;
[0042] Among them, B1 is the world coordinate after the alignment geometry is updated, and B is the world coordinate before the alignment geometry is updated.
[0043] By adopting the above technical solution, the distance between the reference geometry and the alignment point of the alignment geometry is calculated, and then the world coordinates of the alignment geometry are calculated based on this distance, so that the world coordinates of the alignment geometry coincide with the reference geometry to obtain the alignment effect.
[0044] In a second aspect, a three-dimensional engine geometric automatic alignment system based on three-dimensional vectors includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the computer program.
[0045] In summary, the present invention has the following beneficial technical effects:
[0046] 1. In the world coordinate system, the position of the aligned geometry is updated by calculating the distance between the alignment points, which automates the alignment process, reduces human errors, improves the accuracy of the alignment process, and improves the quality of 3D model construction and editing;
[0047] 2. The left-handed coordinate system is used to maintain the overall uniformity of the coordinate system, avoid the problem that the graphics do not meet user expectations after alignment due to different coordinate systems, and is more convenient for calculation. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 The present invention is a flowchart of a method for automatically aligning three-dimensional engine geometric bodies based on three-dimensional vectors according to an embodiment of the present invention.
[0049] Figure 2 It is a detailed step diagram of a method for automatic alignment of three-dimensional engine geometric bodies based on three-dimensional vectors according to an embodiment of the present invention. DETAILED DESCRIPTION
[0050] The following is combined with Figure 1-2 The present invention is described in further detail.
[0051] The present invention provides a method and system for automatic alignment of 3D engine geometry based on 3D vectors, aiming to significantly improve the efficiency and accuracy of alignment operations during 3D model construction and editing, and is widely applicable to diversified scenarios such as various professional 3D design software, 3D engines, and virtual reality (VR) / augmented reality (AR) application development.
[0052] Example 1
[0053] Reference Figure 1 and Figure 2 , a 3D engine geometric body automatic alignment method based on 3D vectors in this embodiment includes the following steps:
[0054] Step S1, respectively obtaining the world coordinate systems of the reference geometry and the alignment geometry;
[0055] The world coordinate system is a coordinate system used to locate objects in fields such as 3D graphics, computer-aided design (CAD), computer game development, and virtual reality (VR). The world coordinate system provides a global reference frame that allows all objects in the scene to be assigned a uniform position. At the same time, the origin of the world coordinate system is usually located at the center of the scene or a specific reference point. The positions of all other points are defined relative to this origin. The world coordinate system can be a right-handed coordinate system or a left-handed coordinate system, depending on the direction of the Z axis. In a right-handed coordinate system, if the four fingers are bent counterclockwise from the X axis to the Y axis, the direction in which the thumb points is the positive direction of the Z axis. The left-handed coordinate system is the opposite.
[0056] The specific steps of step S1 include:
[0057] Get the initial world coordinate systems of the reference geometry and the alignment geometry respectively;
[0058] Determine whether the initial world coordinate systems of the reference geometry and the alignment geometry are consistent with the transformed coordinate system respectively; since the world coordinate system is divided into left-handed coordinate system and right-handed coordinate system, there is a possibility that the reference geometry and the alignment geometry are not in the same world coordinate system, so it is necessary to unify the coordinate system so that subsequent alignment operations can meet user needs.
[0059] When it is determined that they are consistent, the initial world coordinate system of the reference geometry and / or the alignment geometry is converted to the reference world coordinate system;
[0060] When it is judged to be inconsistent, the initial world coordinate system is the reference world coordinate system.
[0061] The reference world coordinate system here can be either a right-handed coordinate system or a left-handed coordinate system. The reference world coordinate system is a standard for geometric coordinate systems. As long as the coordinate system can be kept unified, the conversion coordinate system and the reference world coordinate system are different coordinate systems. That is, if the reference coordinate system is a right-handed coordinate system, the conversion coordinate system is a left-handed coordinate system, and if the reference coordinate system is a left-handed coordinate system, the conversion coordinate system is a right-handed coordinate system. The conversion coordinate system serves as the basis for judging whether the coordinate system needs to be converted.
[0062] In this embodiment, taking into account the understanding of space in daily life and the needs in actual operation, the conversion coordinate system includes a right-hand coordinate system, the reference world coordinate system includes a left-hand coordinate system, and the three-dimensional engine world coordinate zero point is taken as the coordinate system zero point.
[0063] The steps to transform the initial world coordinate system of the reference geometry and / or alignment geometry into the reference world coordinate system include:
[0064] Determine the flip axis and flip direction to set the flip matrix; in this embodiment, keep the Z axis unchanged, flip the X axis, and set the flip matrix FlipMatrix.
[0065] ;
[0066] The initial world coordinate system coordinates are multiplied by the flip matrix to obtain the reference world coordinate system coordinates; in this embodiment, A (x, y, z) * FlipMatrix = A1 (-x, y, z); other flip axes and flip directions can also be used as long as the reference geometry and the alignment geometry maintain the same coordinate system;
[0067] Where A is the initial world coordinate system coordinate of the reference geometry or alignment geometry, and A1 is the reference world coordinate system coordinate of the reference geometry or alignment geometry after transformation.
[0068] At this time, the reference geometry and / or the aligned geometry is converted into the reference world coordinate system, completing the unification of the geometry world coordinate system, so that the geometry can perform subsequent alignment operations based on the world coordinate system, avoiding the possibility of deviation after the alignment operation is completed.
[0069] Step S2, respectively obtaining the world coordinate three-dimensional vectors of the points to be aligned in the reference geometry and the alignment geometry; the specific steps include:
[0070] Get the coordinates of the point on the reference geometry that needs to be aligned, and convert the coordinates of the point from local coordinates to a three-dimensional vector of world coordinates;
[0071] Get the coordinates of the point that needs to be aligned to the geometry, and convert the coordinates of the point from local coordinates to a world coordinate 3D vector.
[0072] The local coordinate system is also called the object coordinate system or the model coordinate system. It is a coordinate system associated with a specific object or model. It defines the positions of points inside the object. The positions of these points are relative to the local origin of the object. The origin of the local coordinate system is usually located at a specific part of the object, such as the geometric center, the center of mass, or a vertex. In modeling and animation, the local coordinate system provides a convenient way to allow designers to work without relying on the global scene layout. In this embodiment, when obtaining the coordinates of the points that need to be aligned with the geometric body, the local coordinates are obtained. Therefore, in order to locate the object in the world coordinate system, the points in the local coordinate system need to be converted to the world coordinate system through a series of transformations.
[0073] The steps to convert the points to be aligned from local coordinates to world coordinates are:
[0074] Use the alignment point as a child object of the reference geometry or the alignment geometry and obtain the local coordinate P1 of the child object;
[0075] Convert the alignment point from the child object local coordinates to the parent object local coordinates; in this embodiment, the child object coordinate to parent object coordinate conversion matrix is taken as M1, and the parent object local coordinates of the alignment point are: P2=P1*M1;
[0076] The local coordinates of the parent object are converted to world coordinates. In this embodiment, the conversion matrix from the parent object coordinates to the world coordinate system is taken as M2. At this time, the world coordinates of the alignment point are: P3=P2*M2=P1*M1*M2.
[0077] When the parent object itself is also the child object of another object, repeat the above formula to convert until it is converted to the world coordinate system.
[0078] The concept of child objects and parent objects is a powerful tool in 3D modeling and animation, which allows creators to work in a modular and hierarchical manner. The parent object is the object in the hierarchy that controls the position, rotation and scaling of the child object, and the child object is the object relative to the position of the parent object. Their transformation is relative to the local coordinate system of the parent object. In this embodiment, in order to facilitate the construction of the geometric body and the flexible transformation of the local part of the geometric body, and because the alignment points are usually selected from the key points of the geometric body in actual applications, the alignment points in this embodiment can be regarded as child objects of the geometric body, so the obtained coordinates are the local coordinates of the child object. In order to unify them into the world coordinate system for operation, they need to be converted to the parent object coordinate system first, and then converted to the world coordinate system.
[0079] Step S3, calculating the distance between the reference geometric body and the point to be aligned in the aligned geometric body according to the world coordinate three-dimensional vector; the calculation method is:
[0080] X=α-β=(x1,y1,z1)-(x2-y2-z2)=(x1-x2,y1-y2,z1-z2);
[0081] Where α (x1, y1, z1) is the world coordinate 3D vector of the reference geometry alignment point, and β (x2-y2-z2) is the world coordinate 3D vector of the alignment geometry alignment point;
[0082] Step S4, updating the world coordinates of the aligned geometric body according to the distance to complete the alignment. The method for updating the world coordinates of the aligned geometric body is:
[0083] B1=B+X=(x3,y3,z3)+(x1-x2,y1-y2,z1-z2)=(x1-x2+x3,y1-y2+y3,z1-z2+z3);
[0084] Among them, B1 (x3, y3, z3) is the world coordinate after the aligned geometry is updated, and B (x1-x2, y1-y2, z1-z2) is the world coordinate before the aligned geometry is updated.
[0085] Reference Figure 2 The implementation principle of this embodiment is: obtain the world coordinates of geometric body A (reference geometric body) and determine whether geometric body A is a right-handed geometric body (determine the coordinate system). When it is determined that geometric body A is a right-handed geometric body, the coordinates of geometric body A are converted to the left-handed system (reference world coordinate system). After geometric body A is converted to the left-handed system or when it is determined that geometric body A is not a right-handed geometric body, obtain the coordinates of a point in geometric body A that needs to be aligned, where a vertex of geometric body A is taken. The coordinates of the point are converted from the local coordinate system to the world coordinate three-dimensional vector α (x, y, z), and the above method is used to obtain the world coordinate three-dimensional vector α (x, y, z). In this embodiment, x=x1, y=y1, z=z1 are obtained.
[0086] Get the world coordinates of geometry B (aligned geometry) and determine whether geometry B is a right-handed geometry. When it is determined that geometry B is a right-handed geometry, convert the coordinates of geometry B to the left-handed system. After geometry B is converted to the left-handed system or when it is determined that geometry B is not a right-handed geometry, obtain the coordinates of a point in geometry B that needs to be aligned, where a vertex of geometry B is taken. Convert the coordinates of the point from the local coordinate system to the world coordinate three-dimensional vector β (x, y, z), obtained from the above method in this embodiment, where x=x2, y=y2, z=z2.
[0087] Calculate the distance X=α-β=(x1-x2,y1-y2,z1-z2) between the world coordinate three-dimensional vectors α and β of the points to be aligned, and update the coordinates of the geometric body B to B1(x,y,z) through the above method. It can be concluded from the above method that in this embodiment, the geometric body B1=B+X=(x3,y3,z3)+(x1-x2,y1-y2,z1-z2)=(x1-x2+x3,y1-y2+y3,z1-z2+z3), so correspondingly in the geometric body B1, x=x1-x2+x3,y=y1-y2+y3,z=z1-z2+z3.
[0088] In summary, when geometric alignment is required, all geometric bodies are converted to the world coordinate system, and the position of the aligned geometric body is updated by calculating the distance between the alignment point of the geometric body to be aligned and the alignment point of the geometric body used as a reference. No manual alignment adjustment is required, which avoids the errors caused by manual adjustment, ensures the accuracy of the alignment results, and makes the geometric alignment process highly automated and precise.
[0089] Example 2
[0090] The difference between this embodiment and Embodiment 1 is that this embodiment provides a three-dimensional engine geometry automatic alignment system based on three-dimensional vectors, including a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the above-mentioned method when executing the computer program.
[0091] The above are all preferred embodiments of the present invention, and are not intended to limit the protection scope of the present invention. Therefore, any equivalent changes made based on the structure, shape, and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for automatic alignment of three-dimensional engine geometric bodies based on three-dimensional vectors, characterized in that: The following steps are involved: Step S1, respectively obtaining the world coordinate systems of the reference geometry and the alignment geometry; wherein, respectively obtaining the initial world coordinate systems of the reference geometry and the alignment geometry; respectively determining whether the initial world coordinate systems of the reference geometry and the alignment geometry are consistent with the conversion coordinate system; when determined to be consistent, converting the initial world coordinate system of the reference geometry and / or the alignment geometry into the reference world coordinate system, determining the flip axis and the flip direction to set the flip matrix, multiplying the initial world coordinate system coordinates by the flip matrix to obtain the reference world coordinate system coordinates, and converting the reference geometry and / or the alignment geometry into the reference world coordinate system; when determined to be inconsistent, the initial world coordinate system is the reference world coordinate system; Step S2, respectively obtaining the world coordinate three-dimensional vectors of the points to be aligned in the reference geometry and the alignment geometry; wherein the coordinates of the points to be aligned in the reference geometry are obtained, and the coordinates of the points are converted from local coordinates to world coordinate three-dimensional vectors; the coordinates of the points to be aligned in the alignment geometry are obtained, and the coordinates of the points are converted from local coordinates to world coordinate three-dimensional vectors; The step of converting the point to be aligned from the local coordinates to the world coordinate three-dimensional vector comprises: taking the alignment point as a child object of the reference geometry or the alignment geometry and obtaining the local coordinates of the child object; converting the alignment point from the local coordinates of the child object to the local coordinates of the parent object; converting the local coordinates of the parent object to the world coordinates; Step S3, calculating the distance between the reference geometric body and the point to be aligned in the aligned geometric body according to the world coordinate three-dimensional vector; Step S4, updating the world coordinates of the aligned geometric body according to the distance to complete the alignment.
2. The method according to claim 1, characterized in that The steps to transform the initial world coordinate system of the reference geometry and / or alignment geometry into the reference world coordinate system include: Keep the Z axis unchanged, flip the X axis, and set the flip matrix FlipMatrix A(x,y,z)*FlipMatrix=A1(-x,y,z); Where A is the initial world coordinate system coordinate of the reference geometry or alignment geometry, and A1 is the reference world coordinate system coordinate of the reference geometry or alignment geometry after transformation.
3. The method according to claim 2, characterized in that The conversion coordinate system includes a right-hand coordinate system, the reference world coordinate system includes a left-hand coordinate system, and the three-dimensional engine world coordinate zero point is taken as the coordinate system zero point.
4. The method according to claim 3, characterized in that The distance in step 3 is calculated as: X=α-β; Where α is the world coordinate 3D vector of the reference geometry alignment point, and β is the world coordinate 3D vector of the alignment geometry alignment point; The method to update the world coordinates of the aligned geometry in step 4 is: B1=B+X; Among them, B1 is the world coordinate after the alignment geometry is updated, and B is the world coordinate before the alignment geometry is updated.
5. A 3D engine geometric body automatic alignment system based on 3D vectors, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.
