-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Curve Fitting - add calculation and chart plotting
Test files added to ensure correctness. GitHub issue #268.
- Loading branch information
1 parent
5a83a57
commit cd6ef90
Showing
53 changed files
with
4,482 additions
and
50 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// | ||
// Copyright (C) 2024 David Cattermole. | ||
// | ||
// This file is part of mmSolver. | ||
// | ||
// mmSolver is free software: you can redistribute it and/or modify it | ||
// under the terms of the GNU Lesser General Public License as | ||
// published by the Free Software Foundation, either version 3 of the | ||
// License, or (at your option) any later version. | ||
// | ||
// mmSolver is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with mmSolver. If not, see <https://www.gnu.org/licenses/>. | ||
// ==================================================================== | ||
// | ||
|
||
use anyhow::Result; | ||
use log::debug; | ||
|
||
use crate::constant::Real; | ||
use crate::math::line::curve_fit_linear_regression_type1; | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq)] | ||
pub struct Point2 { | ||
x: Real, | ||
y: Real, | ||
} | ||
|
||
impl Point2 { | ||
pub fn x(self) -> Real { | ||
self.x | ||
} | ||
|
||
pub fn y(self) -> Real { | ||
self.y | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq)] | ||
pub struct AngleRadian { | ||
inner: Real, | ||
} | ||
|
||
impl AngleRadian { | ||
pub fn value(self) -> Real { | ||
self.inner | ||
} | ||
|
||
pub fn as_degrees(self) -> Real { | ||
self.value().to_degrees() | ||
} | ||
|
||
pub fn as_direction(self) -> (Real, Real) { | ||
(self.value().cos(), self.value().sin()) | ||
} | ||
} | ||
|
||
pub fn linear_regression( | ||
x_values: &[Real], | ||
y_values: &[Real], | ||
) -> Result<(Point2, AngleRadian)> { | ||
let mut point_x = 0.0; | ||
let mut point_y = 0.0; | ||
let mut angle = 0.0; | ||
curve_fit_linear_regression_type1( | ||
&x_values, | ||
&y_values, | ||
&mut point_x, | ||
&mut point_y, | ||
&mut angle, | ||
); | ||
debug!("angle={angle}"); | ||
|
||
let dir_x = angle.cos(); | ||
let dir_y = angle.sin(); | ||
debug!("point_x={point_x} point_y={point_y}"); | ||
debug!("dir_x={dir_x} dir_y={dir_y}"); | ||
|
||
let point = Point2 { | ||
x: point_x, | ||
y: point_y, | ||
}; | ||
|
||
let angle = AngleRadian { | ||
inner: dir_y.atan2(dir_x), | ||
}; | ||
debug!("angle={angle:?}"); | ||
|
||
Ok((point, angle)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
// | ||
|
||
pub mod camera; | ||
pub mod curve_fit; | ||
pub mod dag; | ||
pub mod line; | ||
pub mod line_intersect; | ||
|
Oops, something went wrong.