A method and device for drawing a spherical rectangle
By calculating the spatial coordinates of rectangular vertices on the spatial sphere and dividing them into small triangles, the problem of spherical rectangles being drawn as trapezoids in traditional methods is solved, achieving more accurate graphic drawing and higher usage efficiency.
Patent Information
- Application Number
- CN202211177823.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-27
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2042-09-27
AI Technical Summary
When drawing rectangles on a spatial spherical surface, the figure calculated by the traditional method is actually a trapezoid of the spherical surface, and it is difficult to find a balance between ensuring the aesthetics of the graphics and the execution efficiency.
By using two points on the sphere as the diagonal vertices of the rectangle, the spatial coordinates of the other two vertices are calculated, and the diagonal dividing into two large triangles, and the preset triangle slices into several small triangles using the preset triangle slicing area, and finally map the small triangle from the plane to the sphere to draw.
It realizes accurate drawing of rectangles on the sphere of three-dimensional space, ignoring the limitation of the north and south polar rotation angle of the sphere, and can accurately control the accuracy of the sphere grid. Compared with traditional methods, the graphics are more accurate and the use efficiency is lower.
Smart Images

Figure CN115482357B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of graphics drawing, and in particular to a method and device for drawing a spherical rectangle. Background Art
[0002] The drawing of spatial spheres is of great significance in the field of computer graphics. The Chinese patent document "Method for Generating Spherical Grid Model" (CN102096947A) discloses a technical solution for drawing spatial spheres, which constructs a sphere based on a cube and optimizes the uniformity of the grid. The Chinese patent document "Method, Device and Storage Medium for Drawing Spherical Maps" (CN112802143A) discloses a technical solution for drawing spherical maps, which uses earth map tiles to draw spherical maps. In practical applications, it is necessary to draw a rectangle on the spatial sphere, such as selecting a map area that needs to be enlarged. In traditional spatial spherical rectangle drawing, the elevation and azimuth of the rectangle line vertices are usually used to determine the positions of the other two vertices of the rectangle. The figure calculated in this way is actually a spherical trapezoid when the signs of the elevation angles are the same. The larger the absolute value of the elevation angle, the shorter the horizontal side length. After the vertices of the rectangle are determined, the triangle is usually divided by connecting the midlines of the three sides to generate four congruent triangles. Although this method splits the triangles evenly and beautifully, one split will form four times the number of triangles as the original, and it is not easy to find an exact balance between graphic beauty and execution efficiency. Summary of the invention
[0003] In view of this, the present application proposes a method for solving the problem of drawing rectangular marks on the earth's surface in global situation visualization software.
[0004] According to one aspect of the present application, a method for drawing a spherical rectangle is provided, wherein four vertices of the spherical rectangle are vertex P1, vertex P2, vertex P3 and vertex P4 in a clockwise direction, and the method comprises:
[0005] Take two points on the sphere as the vertex P1 and the vertex P3;
[0006] The spatial coordinates of the vertex P2 and the vertex P4 are calculated using the vertex P1 and the vertex P3, wherein the spatial coordinates take the center of the sphere as the origin;
[0007] Divide the plane rectangle formed by vertex P1, vertex P2, vertex P3 and vertex P4 into two large triangles along the diagonal line;
[0008] Using a preset triangle cutting area, the large triangle is cut into a plurality of small triangles;
[0009] Mapping the small triangle from the plane to the sphere;
[0010] The small triangle is drawn, thereby achieving drawing of a spherical rectangle.
[0011] Preferably, calculating the spatial coordinates of the vertex P2 and the vertex P4 using the vertex P1 and the vertex P3 comprises:
[0012] Calculate the midpoint P of the line segment formed by the vertex P1 and the vertex P3 C ;
[0013] Calculate the center line vector V of the rectangle perpendicular to the line segment formed by the vertex P1 and the vertex P2 C ;
[0014] Calculate the midpoint P C The vector V on the plane to the vertex P1 P ;
[0015] Using the rectangle center line vector V C The intersection point P of the line segment formed by the vertex P1 and the vertex P2 12C ;
[0016] According to the vertex P1 and the intersection point P 12C Calculate the coordinates of the vertex P2;
[0017] The coordinates of the vertex P4 are calculated according to the coordinates of the vertex P1, the vertex P2 and the vertex P3.
[0018] Preferably, the center line vector V of the rectangle perpendicular to the line segment formed by the vertex P1 and the vertex P2 is calculated. C include:
[0019] Determine the sphere center and midpoint P C The vector formed is perpendicular to the vector formed by vertex P1 and vertex P2 Parallel auxiliary vectors ,
[0020] ;in, , is the vector P C Components in the x and y axis directions;
[0021] The center of the sphere and the midpoint P C The vectors and auxiliary vectors Cross product to get the rectangle center line vector V C .
[0022] Preferably, the method further comprises:
[0023] The rectangle center line vector V C Normalization:
[0024] ;in, , , is the rectangle center line vector V C The components in the x, y, and z directions respectively.
[0025] Preferably, the midpoint P is calculated C The vector V on the plane to the vertex P1 P include:
[0026] According to the vector formed by the center of the sphere and the vertex P1 and the center line vector V of the rectangle C The difference between the two vectors V P .
[0027] The present application provides a spherical rectangle drawing device, wherein the four vertices of the spherical rectangle are vertex P1, vertex P2, vertex P3 and vertex P4 in a clockwise direction, and the device comprises:
[0028] A vertex setting module, used for taking two points on the spherical surface as the vertex P1 and the vertex P3;
[0029] A calculation module, used to calculate the spherical coordinates of the vertex P2 and the vertex P4 using the vertex P1 and the vertex P3;
[0030] A cutting module is used to cut the plane rectangle formed by the vertex P1, the vertex P2, the vertex P3 and the vertex P4 into two large triangles along the diagonal line; and cut the large triangle into a plurality of small triangles using a preset maximum cutting area of the triangle;
[0031] A mapping module, used for mapping the small triangle from a plane to a spherical surface;
[0032] The drawing module is used to draw the small triangle, thereby achieving the drawing of the spherical rectangle.
[0033] Preferably, the calculation module is further used to calculate the midpoint P of the line segment formed by the vertex P1 and the vertex P3. C ; Calculate the rectangular center line vector V perpendicular to the line segment formed by the vertex P1 and the vertex P2 C ; Calculate the midpoint P C The vector V on the plane to the vertex P1 P ; Use the rectangle center line vector V C The intersection point P of the line segment formed by the vertex P1 and the vertex P2 12C ; According to the vertex P1 and the intersection point P 12C The coordinates of the vertex P2 are calculated; and the coordinates of the vertex P4 are calculated according to the coordinates of the vertex P1, the vertex P2 and the vertex P3.
[0034] Preferably, the calculation module is also used to determine the relationship between the center of the sphere and the midpoint P C The vector formed is perpendicular to the vector formed by vertex P1 and vertex P2 Parallel auxiliary vectors ,
[0035] ;in, , is the vector P C Components in the x and y axis directions;
[0036] The center of the sphere and the midpoint P C The vectors and auxiliary vectors Cross product to get the rectangle center line vector V C .
[0037] Preferably, the device further comprises:
[0038] Normalization module, used to transform the rectangle center line vector V C Normalization:
[0039] ;in, , , is the rectangle center line vector V C The components in the x, y, and z directions respectively.
[0040] Preferably, the calculation module is further used to calculate the vector formed by the center of the sphere and the vertex P1 and the rectangular center line vector V C The difference between the two vectors V P .
[0041] According to the technical solution of this application, a spherical rectangle can be drawn on a three-dimensional sphere using any two points as the diagonal vertices of the spherical rectangle, as well as the sphere radius and triangle segmentation accuracy (minimum triangle area upper limit). Ignoring the restrictions of the rotation angles of the north and south poles of the sphere, ignoring the different situations of vertex input order ( The accuracy of the sphere mesh can be precisely controlled, which is more accurate than the traditional method and has lower efficiency and cost.
[0042] Other features and advantages of the present application will be described in detail in the subsequent detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The accompanying drawings constituting a part of the present application are used to provide a further understanding of the present application, and the schematic implementation modes and descriptions of the present application are used to explain the present application. In the accompanying drawings:
[0044] Figure 1 It is a schematic diagram of a rectangle P1P2P3P4 drawn in a spatial coordinate system;
[0045] Figure 2 is the auxiliary vector in the space coordinate system Schematic diagram;
[0046] Figure 3 It is a schematic diagram of dividing the rectangle P1P2P3P4 into right triangles along the diagonal line;
[0047] Figure 4 This is a schematic diagram of triangle segmentation with 6 recursive segmentations;
[0048] Figure 5 Schematic diagram of mapping the vertices of the cut triangle to the spherical surface;
[0049] Figure 6 and Figure 7 An example of a drawn spherical rectangle provided for this application. DETAILED DESCRIPTION
[0050] It should be noted that, in the absence of conflict, the embodiments of the present application and the features in each embodiment may be combined with each other.
[0051] The present application will be described in detail below with reference to the accompanying drawings and in combination with implementation modes.
[0052] When drawing a rectangle, it is necessary to determine the coordinates of the four vertices of the rectangle. In order to achieve the drawing of a spherical rectangle, the present application provides the following technical solution.
[0053] Assume that the four vertices of the spherical rectangle to be drawn are , , and , use any point on the known space sphere as a vertex of the rectangle to be drawn , another known arbitrary point is known as the other vertex of the rectangle to be drawn First, calculate the spatial coordinates of the other two vertices through the two known diagonal vertices; then divide the rectangle into two large triangles through the diagonal line, and then split each triangle to an appropriate degree and map all the triangle vertices from the plane where the rectangle is located to the sphere, and then draw and render to form a spherical rectangle.
[0054] The spherical rectangle drawing method provided by this application includes:
[0055] Step 1: Based on the known vertices and Calculate the other two vertices and The present application abstracts the plane in the three-dimensional space where the four vertices of the rectangle are located into a two-dimensional plane, and uses the two-dimensional idea to solve the three-dimensional problem. The specific process is as follows:
[0056] Step 11: Find the intersection of the diagonals of the four vertices of the rectangle ;
[0057] From the properties of the rectangle, it is easy to get:
[0058] ;
[0059] Step 12, use Find the spatial coordinates of the rectangle on the plane perpendicular to The center line vector of the rectangle and to The projection vector of the vector on the plane where the rectangle lies ;
[0060] First find a vector Vertical and Parallel auxiliary vectors , Can be based on It turns out that:
[0061]
[0062] The position in space is Figure 1 shown.
[0063] Will and Perform the cross product to get :
[0064]
[0065] Then Normalize:
[0066]
[0067] to The projection vector of the vector on the plane where the rectangle lies In fact, to The amount of direction:
[0068] .
[0069] Step 13, Utilize and You can calculate exist The intersection of (i.e. in a rectangular plane The midpoint of the side) coordinates;
[0070] Will and The dot product can get the cosine value of the angle between the two vectors, and then the signed cosine value scalar can be used to calculate exist The intersection of (i.e. in a rectangular plane The midpoint of the side) coordinates are calculated as follows:
[0071] .
[0072] Step 14, pass and Available vertices The spatial coordinates of
[0073] according to and Easy to get:
[0074]
[0075] Step 15, through the triangle The barycentric coordinate space can be obtained The spatial coordinates of Figure 2 shown.
[0076] Since the two triangles divided by the diagonal of a rectangle are congruent, In the barycentric coordinate space The coordinates of the center of gravity are ( , =1), then the 3D coordinate conversion formula can be used to calculate The spatial coordinates are:
[0077] .
[0078] Step 2: Divide the rectangle into two large triangles using the diagonal line, split each triangle appropriately and map all the triangle vertices from the plane where the rectangle is located to the sphere, and then draw and render to form a spherical rectangle. Specifically, the three-dimensional space coordinates of the four vertices of the rectangle have been calculated through step 1, and the diagonal lines are used to divide the rectangle into two large triangles. Cut the rectangle into triangles and triangle Two large triangles, using the maximum area of a small triangle as input To divide the large triangle into several small triangles; then map the vertices of each small triangle from the plane to the spherical space coordinates, and draw all the small triangles to form the final spherical rectangle. The specific steps include:
[0079] Step 21: Use the maximum area of a small triangle as input To divide the large triangle into several small triangles, first calculate the area of the large triangle , using Heron's formula we can get:
[0080] ;
[0081]
[0082] Where p is the semi-perimeter of the triangle;
[0083] A, B, and C are the three-dimensional coordinates of the three vertices of the triangle.
[0084] Step 22: According to the adopted segmentation method, a triangle is segmented into two small triangles of equal area at one time. To ensure that the area of the small triangle after the last segmentation is smaller than the input area, , the large triangle needs to be recursively divided n times, and finally divided into small triangles, n can be calculated based on the maximum area of the small triangles and the area of the large triangle The calculations show that:
[0085]
[0086] The method of triangle segmentation is to first find the midpoint of the longest side of the triangle; connect the vertex of the largest inner angle and the midpoint of the longest side to form two small triangles with the same area, and complete one segmentation. In this way, the number of triangles obtained after segmentation is relatively accurate, and the vertices in the plane are evenly distributed. After n recursions, we will get Small triangles. Figure 3 shown.
[0087] like Figure 4 As shown, after recursively splitting 6 times in this way, we will get That is 64 small triangles:
[0088] Step 23, after obtaining the segmented small triangles, it is necessary to map the vertices of each small triangle from the plane to the sphere:
[0089]
[0090] in is the three-dimensional coordinate of the vertex; R is the radius of the sphere.
[0091] by Taking a point as an example, the way to map it to a sphere Figure 5 shown.
[0092] Step 24, by traversing and executing the above mapping, the final spherical rectangular grid can be obtained for drawing.
[0093] The present application also provides a spherical rectangle drawing device, wherein the four vertices of the spherical rectangle are vertex P1, vertex P2, vertex P3 and vertex P4 in a clockwise direction, and the device comprises:
[0094] A vertex setting module, used for taking two points on the spherical surface as the vertex P1 and the vertex P3;
[0095] A calculation module, used to calculate the spherical coordinates of the vertex P2 and the vertex P4 using the vertex P1 and the vertex P3;
[0096] A cutting module is used to cut the plane rectangle formed by the vertex P1, the vertex P2, the vertex P3 and the vertex P4 into two large triangles along the diagonal line; and cut the large triangle into a plurality of small triangles using a preset maximum cutting area of the triangle;
[0097] A mapping module, used for mapping the small triangle from a plane to a spherical surface;
[0098] The drawing module is used to draw the small triangle, thereby achieving the drawing of the spherical rectangle.
[0099] The above description is only a preferred implementation mode of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A method for drawing a rectangle on the surface of the earth, wherein the four vertices of the rectangle on the surface of the earth are vertex P1, vertex P2, vertex P3 and vertex P4 in a clockwise direction, characterized in that: The method includes: Take two points on the earth's surface as the vertex P1 and the vertex P3; The spatial coordinates of the vertex P2 and the vertex P4 are calculated using the vertex P1 and the vertex P3, wherein the spatial coordinates take the center of the earth's surface as the origin; Divide the plane rectangle formed by vertex P1, vertex P2, vertex P3 and vertex P4 into two large triangles along the diagonal line; Using a preset triangle cutting area, the large triangle is cut into a plurality of small triangles; Mapping the small triangles from the plane to the surface of the earth, and rendering them; The small triangle is drawn, thereby achieving drawing of a rectangle on the surface of the earth.
2. The method according to claim 1, characterized in that Calculating the spatial coordinates of the vertex P2 and the vertex P4 using the vertex P1 and the vertex P3 includes: Calculate the midpoint P of the line segment formed by the vertex P1 and the vertex P3 C ; Calculate the center line vector V of the rectangle perpendicular to the line segment formed by the vertex P1 and the vertex P2 C ; Calculate the midpoint P C The vector V on the plane to the vertex P1 P ; Using the rectangle center line vector V C The intersection point P of the line segment formed by the vertex P1 and the vertex P2 12C ; According to the vertex P1 and the intersection point P 12C Calculate the coordinates of the vertex P2; The coordinates of the vertex P4 are calculated according to the coordinates of the vertex P1, the vertex P2 and the vertex P3.
3. The method according to claim 2, characterized in that Calculate the center line vector V of the rectangle perpendicular to the line segment formed by the vertex P1 and the vertex P2 C include: Determine the vector P C Auxiliary vector V perpendicular and parallel to vector P1P2 temp , in, is the vector P C Components in the x and y axis directions; The vector P C With the auxiliary vector V temp Cross product to get the rectangle center line vector V C .
4. The method according to claim 3, characterized in that The method further includes: The rectangle center line vector V C Normalization: in is the rectangle center line vector V C The components in the x, y, and z directions respectively.
5. The method according to claim 4, characterized in that Calculate the midpoint P C The vector V on the plane to the vertex P1 P include: According to the vector formed by the center of the earth's surface and the vertex P1 and the rectangle center line vector V C The difference between the two vectors V P .
6. A device for drawing a rectangle on the earth's surface, wherein the four vertices of the rectangle on the earth's surface are vertex P1, vertex P2, vertex P3 and vertex P4 in a clockwise direction, characterized in that: The device includes: A vertex setting module, used for taking two points on the earth's surface as the vertex P1 and the vertex P3; A calculation module, used to calculate the earth surface coordinates of the vertex P2 and the vertex P4 using the vertex P1 and the vertex P3; A cutting module is used to cut the plane rectangle formed by the vertex P1, the vertex P2, the vertex P3 and the vertex P4 into two large triangles along the diagonal line; and cut the large triangle into a plurality of small triangles using a preset maximum cutting area of the triangle; A mapping module, used for mapping the small triangles from the plane to the surface of the earth, and performing drawing and rendering; The drawing module is used to draw the small triangle, so as to realize drawing of a rectangle on the surface of the earth.
7. The device according to claim 6, characterized in that The calculation module is also used to calculate the midpoint P of the line segment formed by the vertex P1 and the vertex P3. C ; Calculate the rectangular center line vector V perpendicular to the line segment formed by the vertex P1 and the vertex P2 C ; Calculate the midpoint P C The vector V on the plane to the vertex P1 P ; Use the rectangle center line vector V C The intersection point P of the line segment formed by the vertex P1 and the vertex P2 12C ; According to the vertex P1 and the intersection point P 12C The coordinates of the vertex P2 are calculated; and the coordinates of the vertex P4 are calculated according to the coordinates of the vertex P1, the vertex P2 and the vertex P3.
8. The device according to claim 7, characterized in that The calculation module is also used to determine the vector P C Auxiliary vector V perpendicular and parallel to vector P1P2 temp , in, is the vector P C Components in the x and y axis directions; The center of the Earth's surface and the midpoint P C The vector and auxiliary vector V temp Cross product to get the rectangle center line vector V C .
9. The device according to claim 8, characterized in that The device also includes: Normalization module, used to transform the rectangle center line vector V C Normalization: in is the rectangle center line vector V C The components in the x, y, and z directions respectively.
10. The device according to claim 9, characterized in that The calculation module is also used to calculate the vector formed by the center of the earth's surface and the vertex P1 and the rectangle center line vector V C The difference between the two vectors V P .
Citation Information
Patent Citations
Generation method for spherical network model
CN102096947A
Spherical map drawing method and device and storage medium
CN112802143A
Method and device for displaying sky sphere in game scene
CN106355635A
Graphic drawing method, device and equipment
CN107230239A