High-precision coordinate calculation method based on Matlab
By using Matlab's high-precision coordinate calculation method, all point pair combinations are generated. Precise geometric intersection calculation and cluster analysis are used, combined with weighted averaging, to solve the problem of coordinate calculation error accumulation and achieve high-precision and fast coordinate calculation results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HEFEI UNIV OF TECH
- Filing Date
- 2026-01-23
- Publication Date
- 2026-05-08
AI Technical Summary
Existing coordinate calculation methods suffer from severe error accumulation when dealing with combinations of multiple points and vectors, failing to meet high-precision requirements, especially in complex geometric relationships and noisy environments where calculation results are inaccurate.
A high-precision coordinate calculation method based on Matlab is adopted. All point pairs are generated by combining the generating function, the intersection is calculated using the accurate geometric intersection calculation function, the region in the intersection set is identified by the clustering algorithm, and the final coordinates are calculated by weighted average. The results are optimized by combining prior knowledge and weights.
It achieves high-precision, fast, and flexible coordinate calculation, and is suitable for fields such as precision measurement and high-precision map drawing. It reduces calculation errors and improves the representativeness and reliability of calculation results.
Smart Images

Figure CN121997592A_ABST
Abstract
Description
Technical Field
[0001] This invention mainly relates to the fields of coordinate calculation technology and data processing technology, specifically a high-precision coordinate calculation method based on Matlab. Background Technology
[0002] In existing coordinate calculation methods, when dealing with combinations of multiple points and vectors, errors can accumulate as each calculation step introduces some error. For example, in calculating multiple intersection points and midpoints, each numerical calculation may produce a slight deviation due to the precision limitations of the computer's floating-point operations. These deviations, after multiple calculations, can lead to a larger error in the final coordinate result.
[0003] Some existing technologies employ mathematical models with insufficient precision in coordinate calculations. For example, when dealing with complex geometric relationships, simplified approximation algorithms may be used. While these algorithms can yield coordinate results to some extent, they fail to meet the accuracy requirements of applications demanding high precision (such as precision measurement and high-precision map creation). Existing methods may also fail to accurately find intersection points when processing large amounts of data, or produce inaccurate results in the presence of noise.
[0004] Therefore, it is necessary to provide a high-precision coordinate calculation method to improve the accuracy of coordinate estimation. Summary of the Invention
[0005] The technical solution of this invention addresses the problem that existing technical solutions are too simplistic and provides a solution that is significantly different from existing technologies. It mainly provides a high-precision coordinate calculation method based on Matlab to solve the problem of insufficient accuracy of existing coordinate calculation methods mentioned in the background.
[0006] The technical solution adopted by the present invention to solve the above-mentioned technical problems is as follows:
[0007] A high-precision coordinate calculation method based on Matlab includes the following steps:
[0008] S1. Generate all combinations of points and vectors: Use the combinatorial generation function to generate all combinations of two points from a given set of points, where the combinatorial generation function is based on a mathematical combinatorial algorithm to determine all possible combinations of point pairs;
[0009] S2. Initialize the result vector: Create a cell array to store the coordinates of subsequent intersection points and related parameters;
[0010] S3. Calculate the intersection of all combinations: For each generated point combination, extract the corresponding points and vectors, calculate the intersection coordinates and related parameters using a precise geometric intersection calculation function, and store them in the result vector;
[0011] S4. Assign the results to the workspace: By looping through the result vector, use the workspace assignment function to assign the intersection coordinates and related parameters to the Matlab workspace according to a specific naming rule for subsequent processing;
[0012] S5. Calculate all midpoints: Based on the intersection coordinates assigned to the work area, calculate the midpoint coordinates of all intersection pairs using the midpoint calculation function and store them in the midpoint coordinate matrix;
[0013] S6. Find the region with the most concentrated intersection points: Calculate the distance between all points in the midpoint coordinate matrix, cluster the points using a clustering algorithm, determine the cluster center, and select the points that are closer to the cluster center based on the statistical characteristics of the distance between points within the cluster as the points in the region with the most concentrated intersection points.
[0014] S7. Calculate the weighted average of the remaining intersection points: Based on the points in the selected intersection point concentration area, combined with the given prior knowledge and weights, calculate the final high-precision coordinates using the weighted average calculation function;
[0015] S8. Distribute the final result to the work area: Distribute the final calculated weighted average result to the work area.
[0016] In step S1, the combination generation function is the nchoosek function, which generates all combinations of any two different elements selected from 1 to a given number of points, and stores them in the combinations variable.
[0017] In step S2, creating the cell array specifically involves initializing two result vectors, t_vals and E_vals.
[0018] In step S3, the geometric intersection calculation function is the calculate_intersection function.
[0019] In step S4, the work area assignment function is the assignin function.
[0020] In step S5, the midpoint calculation function obtains the midpoint coordinates by adding the coordinates of each pair of intersection points into vectors and dividing by 2.
[0021] In step S6, the clustering algorithm is the kmeans clustering algorithm. This algorithm clusters the points in the midpoint coordinate matrix into a preset number of clusters and determines the cluster centers. The method for selecting points is to set a threshold based on the median distance between points within a cluster and select points whose distance from the cluster center is less than or equal to the threshold.
[0022] In step S7, the weighted average calculation function obtains the final coordinates by weighting the average value of the points in the selected intersection set region with the given prior knowledge according to a preset weight.
[0023] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0024] (1) This invention comprehensively considers all possible point pair combinations through a combination of generating functions to ensure the completeness of the calculation results; it uses precise geometric algorithms to calculate the intersection coordinates, reducing the cumulative numerical error; and it identifies regions with concentrated intersection points through midpoint calculation and cluster analysis, improving the representativeness of the calculation results; furthermore, it utilizes a weighted average method, combining prior knowledge and weights, to optimize the intersection coordinates, thereby achieving high-precision calculation. Therefore, the coordinate calculation method provided by this invention comprehensively utilizes mathematical combination, geometric analysis, statistical analysis, and weighted averaging, ensuring the comprehensiveness, accuracy, and reliability of the calculation results. It is applicable to many fields with high coordinate accuracy requirements, such as coordinate processing and analysis tasks in precision measurement, high-precision map drawing, and computer graphics.
[0025] (2) The present invention is highly efficient: by utilizing the efficient computing power and matrix operation function of MATLAB, it can quickly process a large amount of coordinate data, thereby improving the efficiency of coordinate calculation and saving computing time and resources.
[0026] (3) This invention is flexible: it can be customized and expanded according to different application needs. It can be combined with other data sources and algorithms to achieve more complex coordinate calculation tasks. At the same time, MATLAB provides rich visualization tools, which can easily display and analyze the coordinate results.
[0027] (4) This invention is easy to use: MATLAB has a user-friendly interface and abundant documentation, making this algorithm easy to use and promote. High-precision coordinate calculations can be achieved without professional programming knowledge and skills.
[0028] The present invention will be explained in detail below with reference to the accompanying drawings and specific embodiments. Attached Figure Description
[0029] Figure 1 This is a flowchart of the present invention;
[0030] Figure 2 The image shows the MATLAB code for this invention. Detailed Implementation
[0031] To facilitate understanding of the present invention, a more comprehensive description of the present invention will be given below with reference to the accompanying drawings, which illustrate several embodiments of the present invention. However, the present invention can be implemented in different forms and is not limited to the embodiments described in the text. Rather, these embodiments are provided to make the disclosure of the present invention more thorough and complete.
[0032] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly associated with those skilled in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to limit the invention. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.
[0033] Please refer to the attached document carefully. Figure 1 and attached Figure 2 A high-precision coordinate calculation method based on Matlab is presented below, along with its code implementation and explanation:
[0034] (a) Generate all combinations of points and vectors
[0035] 1. Code snippet
[0036] combinations = nchoosek(1:num_points, 2);
[0037] 2. Explanation
[0038] Here, the `nchoosek` function is used to generate all combinations of any two distinct elements selected from 1 to `num_points`. For example, if `num_points` is 5, then all possible combinations of two points will be generated, such as [1, 2], [1, 3], [1, 4], [1, 5], [2, 3], etc. These combinations are stored in the `combinations` variable and will be used for subsequent intersection calculations.
[0039] Advantages: This method avoids calculation errors caused by missing certain point pairs, thereby improving the comprehensiveness and accuracy of the results.
[0040] (ii) Initialize the result vector
[0041] 1. Code snippet
[0042] t_vals = cell(num_combinations, 1);
[0043] E_vals = cell(2 *num_combinations, 1);
[0044] 2. Explanation
[0045] The `cell` function creates two cell arrays, `t_vals` and `E_vals`. `t_vals` stores one coordinate value of the intersection point, and `E_vals` stores the other coordinate value of the intersection point and related vector information. Their sizes are initialized to the corresponding number of combinations for later storage of calculation results.
[0046] Advantages: Using cell arrays to store intersection coordinates and related parameters provides a structured storage method for subsequent data processing. Cell arrays can accommodate different types of data, allowing the result vector to flexibly store various calculation results.
[0047] (iii) Calculate the intersection of all combinations
[0048] 1. Code snippet
[0049] for i = 1:num_combinations
[0050] idx1 = combinations(i, 1);
[0051] idx2 = combinations(i, 2);
[0052] P1 = P(:, idx1);
[0053] P2 = P(:, idx2);
[0054] R1 = R(:, idx1);
[0055] R2 = R(:, idx2);
[0056] [E1, E2, t1, t2] = calculate_intersection(P1, R1, P2, R2);
[0057] t_vals{2*i - 1} = t1;
[0058] t_vals{2*i} = t2;
[0059] E_vals{2*i - 1} = E1;
[0060] E_vals{2*i} = E2;
[0061] end
[0062] 2. Explanation
[0063] For each pair of combinations (idx1 and idx2), extract the corresponding points and vectors (P1, P2, R1, R2) from matrices P and R.
[0064] The function `calculate_intersection` is called to calculate the intersection point of the two vectors, obtaining the intersection point coordinates E1 and E2 and the parameters t1 and t2.
[0065] The calculated intersection parameters and coordinates are stored in t_vals and E_vals respectively. For example, for the i-th pair of combinations, t1 is stored in t_vals{2*i - 1}, t2 is stored in t_vals{2*i}, E1 is stored in E_vals{2*i - 1}, and E2 is stored in E_vals{2*i}.
[0066] Advantages: For each pair of points, using an accurate geometric intersection calculation function ensures that the intersection coordinates are calculated based on analytical geometry principles, rather than numerical approximations. This minimizes calculation errors and improves the accuracy of the intersection coordinates.
[0067] (iv) Assigning results to work areas
[0068] 1. Code snippet
[0069] function assign_to_workspace(t_vals, E_vals)
[0070] for i = 1:length(t_vals)
[0071] assignin('base', ['t', num2str(i)], t_vals{i});
[0072] assignin('base', ['E', num2str(i)], E_vals{i});
[0073] end
[0074] end
[0075] 2. Explanation
[0076] The core function is to distribute the intersection-related results obtained in the previous calculation (stored in t_vals and E_vals) to the Matlab basic workspace according to a unified rule so that subsequent steps can call them directly.
[0077] Traversal logic: Loop through all elements of t_vals (since t_vals and E_vals store one-to-one intersection parameters and coordinates, and have the same length, the length of t_vals is used as the traversal basis).
[0078] Assignment rules: Use the assignin function to assign each element to the base work area ('base' specifies the work area type). The naming rule is "parameter identifier + index" - the i-th element in t_vals is named t + number i (e.g., t1, t2), corresponding to the parameter value of the intersection point; the i-th element in E_vals is named E + number i (e.g., E1, E2), corresponding to the coordinate value of the intersection point;
[0079] Core objective: By using structured naming and unified allocation logic, intersection parameters and coordinates can be directly accessed in the workspace, avoiding manual data processing in subsequent steps, reducing operational errors, and providing a clear data retrieval foundation for subsequent steps such as midpoint calculation and cluster analysis.
[0080] (v) Calculate all midpoints
[0081] 1. Code snippet
[0082] function mid_points = calculate_mid_points(E_vals)
[0083] num_pairs = length(E_vals) / 2;
[0084] mid_points = zeros(3, num_pairs);
[0085] for i = 1:num_pairs
[0086] E1 = E_vals{2*i - 1};
[0087] E2 = E_vals{2*i};
[0088] mid_points(:, i) = (E1 + E2) / 2;
[0089] end
[0090] end
[0091] 2. Explanation
[0092] First, calculate the number of element pairs num_pairs in E_vals.
[0093] Create a zero matrix mid_points of size (3, num_pairs) to store the coordinates of the midpoint.
[0094] For each pair of elements (E1 and E2) in E_vals, calculate their midpoint coordinates and store them in the mid_points matrix. For example, the midpoint coordinates of the i-th pair are calculated as (E1 + E2) / 2 and stored in mid_points(:, i).
[0095] Advantages: Calculating the midpoint coordinates of intersection pairs helps identify the spatial distribution pattern of the intersection points. The midpoint coordinates can serve as a proxy for the intersection point distribution, providing basic data for subsequent cluster analysis.
[0096] (vi) Find the area with the most concentrated intersection points
[0097] 1. Code snippet
[0098] function [cluster_center, filtered_points] = find_cluster_center(points)
[0099] num_points = size(points, 2);
[0100] distances = zeros(num_points);
[0101] for i = 1:num_points
[0102] for j = i + 1:num_points
[0103] distances(i, j) = norm(points(:, i) - points(:, j));
[0104] distances(j, i) = distances(i, j);
[0105] end
[0106] end
[0107] num_clusters = 1;
[0108] [idx, C] = kmeans(points', num_clusters);
[0109] cluster_center = C';
[0110] cluster_distances = distances(:, idx == 1);
[0111] median_distance = median(cluster_distances(:));
[0112] threshold = 1.5 * median_distance;
[0113] filtered_points = points(:, vecnorm(points - cluster_center) <=threshold);
[0114] end
[0115] 2. Explanation
[0116] First, calculate the distance matrix `distances` between all points. For each pair of points i and j, use the `norm` function to calculate their Euclidean distance and store it in the `distances` matrix.
[0117] Using the k-means clustering algorithm, the point set `points` is clustered into `num_clusters` (here, set to 1) clusters. The cluster centers `C` and the cluster index `idx` of each point are then obtained.
[0118] Calculate the distances between points belonging to the first cluster (cluster_distances) and find the median (median_distance).
[0119] Set a threshold based on the median (here, it is 1.5 times the median).
[0120] Points that are less than or equal to a threshold from the cluster center are selected as filtered_points. These points are the points in the region where the intersection points are most concentrated.
[0121] Advantages: By calculating the distance between the midpoint coordinates and applying a clustering algorithm, densely distributed regions of intersection points can be identified. The cluster center represents a high-density region of intersection points, and points closer to the cluster center can be selected as representatives of the intersection point set, giving them higher weight when calculating the final coordinates.
[0122] (vii) Calculate the weighted average of the remaining intersection points
[0123] 1. Code snippet
[0124] function average_point = weighted_average(filtered_points, zxzb,weight)
[0125] filtered_avg = mean(filtered_points, 2);
[0126] average_point = (filtered_avg * (1 - weight))+(zxzb * weight);
[0127] average_point = average_point(:);
[0128] end
[0129] 2. Explanation
[0130] First, calculate the average value of filtered_points, filtered_avg (average by column).
[0131] Calculate the weighted average point (average_point) based on the given weights (weight) and prior knowledge (zxzb). The formula for calculating the weighted average is (filtered_avg * (1 - weight)) + (zxzb * weight).
[0132] Finally, the results are converted into column vector form.
[0133] Advantages: The weighted average calculation combines prior knowledge and weights, more accurately reflecting the true location of the intersection points. By assigning different weights to different intersection points, the influence of each intersection point on the final result can be balanced, thereby improving the overall accuracy of the coordinate calculation. This method considers the spatial distribution and importance of the intersection points, making the final calculation results more reliable.
[0134] (viii) Assign the final results to the work area
[0135] 1. Code snippet
[0136] function average_point = weighted_average(filtered_points, szxbo,weight)
[0137] % Calculate the average value of the selected intersection points
[0138] filtered_avg = mean(filtered_points, 2);
[0139] % Considering spot identification (szxbo), combined with weighted average
[0140] average_point = (filtered_avg .* (1 - weight)) + (szxbo .*weight);
[0141] % Guaranteed to return a vector
[0142] average_point = average_point(:); % Convert the result to a column vector end
[0143] 2. Explanation
[0144] The core function is to combine the "filtered intersection points" with the "spot identification results szxbo" and calculate the final target point (such as the center of the spot) by weighted average.
[0145] Input instructions:
[0146] filtered_points: The set of intersection points after clustering (outliers have been removed);
[0147] szxbo: Reference point obtained from light spot identification (as a weighting term);
[0148] weight: weighting coefficient (controls the contribution ratio of filtered_avg and szxbo);
[0149] Calculation logic:
[0150] First, calculate the average value of filtered_points column by column (mean(filtered_points, 2)) to obtain the average position of the filtered intersection points, filtered_avg.
[0151] The filtered_avg and szxbo are merged according to a weighted rule: average_point = mean of filtered intersection points × (1 - weight) + reference point of light spot × weight;
[0152] Finally, the result is converted into a column vector using (:) to unify the output format;
[0153] Core objective:
[0154] By weighted fusion of the "calculated mean of intersection points" and the "light spot identification reference point", a more reliable target point location is obtained, taking into account both calculation accuracy and actual light spot characteristics; at the same time, the unified format facilitates subsequent workspace calls.
[0155] Example: (I) Hypothetical Data
[0156] 1. Point coordinate matrix P
[0157] Suppose P is a 3×5 matrix representing the coordinates of 5 three-dimensional points. For example:
[0158] P = [1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7];
[0161] 2. Vector matrix R
[0162] Suppose R is a 3×5 matrix representing 5 three-dimensional vectors. For example:
[0163] R = [0.1 0.2 0.3 0.4 0.5; 0.2 0.3 0.4 0.5 0.6; 0.3 0.4 0.5 0.6 0.7];
[0166] (II) Operation Process
[0167] 1. Generate combinations
[0168] The combination of points is generated using `combinations = nchoosek(1:5, 2);`, resulting in a combination matrix (e.g., [1, 2; 1, 3; 1, 4; 1, 5; 2, 3; 2, 4; 2, 5; 3, 4; 3, 5; 4, 5], a total of 10 pairs of points). This matrix will be used as the index for subsequent traversal calculations of intersection points.
[0169] 2. Initialize the result vector
[0170] First, determine the number of combinations: `num_combinations = size(combinations, 1)` (here, `num_combinations = 10`). Then, initialize two result vectors using a cell array to store the intersection parameters and coordinates respectively.
[0171] MATLAB
[0172] % Initialize the cell array to store the intersection parameters (each combination corresponds to 2 parameters, for a total of 10×2=20 elements)
[0173] t_vals = cell(num_combinations, 1);
[0174] % Initialize the cell array to store the coordinates of the intersection points (each combination corresponds to 2 coordinates, for a total of 10×2=20 elements)
[0175] E_vals = cell(2 * num_combinations, 1);
[0176] Among them, t_vals is used to store the parameters t1 and t2 in the intersection calculation process (output by the calculate_intersection function), and E_vals is used to store the corresponding intersection coordinates E1 and E2. The structure of the cell array can flexibly adapt to the calculation results of different dimensions and avoid data storage type conflicts.
[0177] 3. Allocation Results
[0178] The results in t_vals and E_vals are assigned to the workspace using the assign_to_workspace function, resulting in variables such as 't1' and 'E1'.
[0179] 4. Calculate the midpoint
[0180] The midpoints are calculated using the `calculate_mid_points` function, resulting in the `mid_points` matrix, which stores the coordinates of the midpoints of all intersection pairs.
[0181] 5. Cluster analysis
[0182] Using all midpoints as input, the find_cluster_center function performs cluster analysis to find the region with the most concentrated intersections and the cluster center.
[0183] 6. Weighted average
[0184] Finally, the weighted_average function is used to calculate the weighted average coordinates based on the selected points and prior knowledge, resulting in the final high-precision coordinates.
[0185] The present invention has been described by way of example in conjunction with the accompanying drawings. Obviously, the specific implementation of the present invention is not limited to the above-described manner. Any non-substantial improvement made by adopting the inventive concept and technical solution of the present invention, or the direct application of the inventive concept and technical solution of the present invention to other occasions without modification, shall be within the protection scope of the present invention.
Claims
1. A high-precision coordinate calculation method based on Matlab, characterized in that: Includes the following steps: S1. Generate all combinations of points and vectors: Use the combinatorial generation function to generate all combinations of two points from a given set of points, where the combinatorial generation function is based on a mathematical combinatorial algorithm to determine all possible combinations of point pairs; S2. Initialize the result vector: Create a cell array to store the coordinates of subsequent intersection points and related parameters; S3. Calculate the intersection of all combinations: For each generated point combination, extract the corresponding points and vectors, calculate the intersection coordinates and related parameters using a precise geometric intersection calculation function, and store them in the result vector; S4. Assign the results to the workspace: By looping through the result vector, use the workspace assignment function to assign the intersection coordinates and related parameters to the Matlab workspace according to a specific naming rule for subsequent processing; S5. Calculate all midpoints: Based on the intersection coordinates assigned to the work area, calculate the midpoint coordinates of all intersection pairs using the midpoint calculation function and store them in the midpoint coordinate matrix; S6. Find the region with the most concentrated intersection points: Calculate the distance between all points in the midpoint coordinate matrix, cluster the points using a clustering algorithm, determine the cluster center, and select the points that are closer to the cluster center based on the statistical characteristics of the distance between points within the cluster as the points in the region with the most concentrated intersection points. S7. Calculate the weighted average of the remaining intersection points: Based on the points in the selected intersection point concentration area, combined with the given prior knowledge and weights, the final high-precision coordinates are calculated using the weighted average calculation function.
2. The high-precision coordinate calculation method based on Matlab according to claim 1, characterized in that: In step S1, the combination generation function is the nchoosek function, which generates all combinations of any two different elements selected from 1 to a given number of points, and stores them in the combinations variable.
3. The high-precision coordinate calculation method based on Matlab according to claim 1, characterized in that: In step S2, creating the cell array specifically involves initializing two result vectors, t_vals and E_vals.
4. The high-precision coordinate calculation method based on Matlab according to claim 1, characterized in that: In step S3, the geometric intersection calculation function is the calculate_intersection function.
5. The high-precision coordinate calculation method based on Matlab according to claim 1, characterized in that: In step S4, the work area assignment function is the assignin function.
6. The high-precision coordinate calculation method based on Matlab according to claim 1, characterized in that: In step S5, the midpoint calculation function obtains the midpoint coordinates by adding the coordinates of each pair of intersection points into vectors and dividing by 2.
7. The high-precision coordinate calculation method based on Matlab according to claim 1, characterized in that: In step S6, the clustering algorithm is the kmeans clustering algorithm. This algorithm clusters the points in the midpoint coordinate matrix into a preset number of clusters and determines the cluster centers. The method for selecting points is to set a threshold based on the median distance between points within a cluster and select points whose distance from the cluster center is less than or equal to the threshold.
8. The high-precision coordinate calculation method based on Matlab according to claim 1, characterized in that: In step S7, the weighted average calculation function obtains the final coordinates by weighting the average value of the points in the selected intersection set region with the given prior knowledge according to a preset weight.
9. A high-precision coordinate calculation method based on Matlab according to any one of claims 1-8, characterized in that: It also includes S8, which assigns the final result to the work area: assigns the final calculated weighted average result to the work area.