How do i generate a rotation matrix iteratively.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Stewart Tan
am 11 Sep. 2019
Kommentiert: Walter Roberson
am 11 Sep. 2019
I have two matrices containing coordinates:
example1 = [1 3;
4 5;
2 3;
6 17];
example2 = [1 4;
6 2;
8 9;
10 11];
and I'm implementing the RANSAC algorithm to remove outlier coordinates. To do that, I will need to include a factor of whether a not one coordinate in example1 is either a rotation, scaling or translation which result in the coordinate in example2. (1 3 -> 1 4, 4 5 -> 6 2 etc..) Hence, I will need to have a rotation matrix, scaling and translation matrix to be built iteratively within the RANSAC algorithm.
For now, I'll just keep it simple by just using a rotation matrix.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237861/image.png)
How do i generate a rotation matrix [cos θ -sin θ; sin θ cos θ] if i do not have anything else other than the two coordinate matrices above?
Edit: sorry for the confusion but the goal is to "estimate" the transformation matrix in every N iteration. The following shows:
![Snip20190911_1.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237873/Snip20190911_1.png)
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 11 Sep. 2019
example1 = [1 3;
4 5;
2 3;
6 17];
example2 = [1 4;
6 2;
8 9;
10 11];
syms theta
RM = [cos(theta) -sin(theta); sin(theta) cos(theta)];
residue = simplify( sum(sum((example2 - (RM * example1.').').^2)) );
best_theta = vpasolve(diff(residue,theta));
It is also possible to code it as a numeric minimization of residue over a bounded range, without using the symbolic toolbox.
3 Kommentare
Walter Roberson
am 11 Sep. 2019
Your original goal was restricted to rotation matrix, and my code finds the rotation matrix that produces the least squared error of rotation between the given sets of coordinates.
Walter Roberson
am 11 Sep. 2019
I would suggest that Bruno's answer is probably better for your purposes.
Weitere Antworten (1)
Bruno Luong
am 11 Sep. 2019
Bearbeitet: Bruno Luong
am 11 Sep. 2019
You can use this implementation by Matt J using the Horn's method. It do for you the scaling and translation as well.
0 Kommentare
Siehe auch
Kategorien
Mehr zu MATLAB Support Package for USB Webcams finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!