Pagina principale
Una pagina a caso
Ultime modifiche
Pagine speciali
Portale comunità
Preferenze
Informazioni su Masticationpedia
Avvertenze
Masticationpedia
Ricerca
Menu utente
discussioni
contributi
entra
Modifica di
Asse Trasversale Cerniera
(sezione)
Attenzione:
non hai effettuato l'accesso. Se effettuerai delle modifiche il tuo indirizzo IP sarà visibile pubblicamente. Se
accedi
o
crei un'utenza
, le tue modifiche saranno attribuite al tuo nome utente, insieme ad altri benefici.
Controllo anti-spam.
NON
riempirlo!
===Mathematical Formalism: Fitting Error=== To illustrate the concept of error due to noise in determining the points of the curve, the preliminary mathematical steps are as follows (refer to Figure 7, represented in Geogebra). The script starts by defining the original circle center with the coordinates: <math>O_{HA} = \begin{pmatrix} 11.55 \ 61.14\end{pmatrix}</math> This center represents the central point around which a circle will be constructed. The radius of the circle is set to <math>r = 26.38</math> mm. This value represents the distance from the center to the points on the edge of the circle. Using the center and radius, 10 points are uniformly distributed along the circumference of the circle. The angles <math>\theta</math> used to position the points are distributed from <math>0</math> to <math>2\pi</math>. For each angle, the coordinates of the points are calculated using the parametric equations of the circle: <math>x = x_c + r \cdot \cos(\theta)</math> <math>y = y_c + r \cdot \sin(\theta)</math> A function called add_noise_to_points is used to add noise to the generated points. The noise is generated from a normal (or Gaussian) distribution with a mean of zero and a standard deviation of <math>0.1</math> units. This step simulates the measurement errors that may occur in practice. The points disturbed by noise are stored in the noisy_points variable. The function residuals is defined to calculate the residuals, that is, the difference between the distance of each noisy point from the estimated center and the estimated radius. This function is essential for optimization since the circle fitting aims to minimize these residuals: <math>R_i = \sqrt{(x_i - x_c)^2 + (y_i - y_c)^2} - r</math> where <math>R_i</math> is the residual for the <math>i</math>-th point. An initial estimate of the noisy circle's center is made by calculating the mean of the noisy points' coordinates: <math>x_m = \frac{1}{n} \sum_{i=1}^{n} x_i</math>, <math>y_m = \frac{1}{n} \sum_{i=1}^{n} y_i</math> This average is used as a starting point for the fitting. '''Initial Radius''' The initial radius is estimated as the mean distance between each noisy point and the estimated center: <math>r_m = \frac{1}{n} \sum_{i=1}^{n} \sqrt{(x_i - x_m)^2 + (y_i - y_m)^2}</math> This approximated value is used as the initial radius for the optimization. '''Circle Fitting with Levenberg-Marquardt Method''' *Fitting Optimization: The least_squares function from the SciPy library is used to perform the circle fitting. This method minimizes the residuals calculated earlier, aiming to find the optimal values for the center coordinates <math>(x_c, y_c)</math> and the radius <math>r</math>. The optimization results are returned as the calculated center <math>(x_c, y_c)</math> and the radius <math>r</math>. '''Error Calculation''' *Error between Centers: The distance between the calculated center and the original center is computed. This distance represents the localization error, indicating how far the calculated center deviates from the true center due to noise: <math>\text{error} = \sqrt{(x_c - x_{\text{original}})^2 + (y_c - y_{\text{original}})^2}</math> The error is then converted into millimeters if the original units were in centimeters, for greater interpretative precision. ===='''Script Python: Errore di fitting'''==== <syntaxhighlight lang="python"> import numpy as np from scipy.optimize import least_squares import matplotlib.pyplot as plt # Original data provided original_center = np.array([11.56, 61.21]) radius = 26.38 angles = np.linspace(0, 2 * np.pi, 10) points = np.array([ original_center + radius * np.array([np.cos(angle), np.sin(angle)]) for angle in angles ]) # Function to add noise to the points def add_noise_to_points(points, noise_level): noisy_points = points + np.random.normal(0, noise_level, points.shape) return noisy_points # Add noise to the points noise_level = 0.1 # Reduced noise level noisy_points = add_noise_to_points(points, noise_level) # Residual function for non-linear fitting def residuals(c, points): xc, yc, r = c Ri = np.sqrt((points[:, 0] - xc)**2 + (points[:, 1] - yc)**2) return Ri - r # Calculate the center and radius using noisy points x_m = np.mean(noisy_points[:, 0]) y_m = np.mean(noisy_points[:, 1]) r_m = np.mean(np.sqrt((noisy_points[:, 0] - x_m)**2 + (noisy_points[:, 1] - y_m)**2)) initial_guess = [x_m, y_m, r_m] # Fitting the circle using the Levenberg-Marquardt method result = least_squares(residuals, initial_guess, args=(noisy_points,)) xc, yc, r = result.x calculated_center = np.array([xc, yc]) # Calculate the error between the centers error = np.linalg.norm(calculated_center - original_center) error_mm = error * 10 # Convert to millimeters (assuming the points might be in centimeters) # Verify the calculated center print(f'Calculated Center: {calculated_center}') print(f'Radius: {r:.4f}') print(f'Error: {error_mm:.4f} mm') # Visualization of the fitted circle theta = np.linspace(0, 2 * np.pi, 100) x_fit = calculated_center[0] + r * np.cos(theta) y_fit = calculated_center[1] + r * np.sin(theta) plt.figure(figsize=(8, 8)) plt.scatter(points[:, 0], points[:, 1], color='b', label='Original Points') plt.scatter(noisy_points[:, 0], noisy_points[:, 1], color='r', label='Noisy Points') plt.scatter(original_center[0], original_center[1], color='r', marker='x', s=100, label='Original Center') plt.plot(x_fit, y_fit, 'g--', label='Fitted Circle') plt.scatter(calculated_center[0], calculated_center[1], color='g', label='Calculated Center') plt.xlabel('X') plt.ylabel('Y') plt.legend() plt.title('Circle Fitting with Noisy Points') plt.grid(True) plt.show() </syntaxhighlight>
Oggetto:
Per favore tieni presente che tutti i contributi a Masticationpedia possono essere modificati, stravolti o cancellati da altri contributori. Se non vuoi che i tuoi testi possano essere alterati, allora non inserirli.
Inviando il testo dichiari inoltre, sotto tua responsabilità, che è stato scritto da te personalmente oppure è stato copiato da una fonte di pubblico dominio o similarmente libera (vedi
Masticationpedia:Copyright
per maggiori dettagli).
Non inviare materiale protetto da copyright senza autorizzazione!
Annulla
Guida
(si apre in una nuova finestra)