|
330 | 330 |
|
331 | 331 |
|
332 | 332 | plane3d = [dip, dipdir, radius, centroid, N, M, K, mean_err, stdev_err];
|
333 |
| - |
334 |
| - |
335 | 333 | end
|
336 | 334 | %% Functions to read and write dxf
|
337 | 335 | % by Grzegorz Kwiatek 2011
|
@@ -657,94 +655,3 @@ function dxf_close(FID)
|
657 | 655 | rethrow(exception);
|
658 | 656 | end
|
659 | 657 | end
|
660 |
| -function plane3d = fit3dplane(PC) |
661 |
| -% This function is developed following the work of Jones et al. (2015) |
662 |
| -% and Seers and Hodgetts (2016) |
663 |
| -% |
664 |
| -% INPUT |
665 |
| -% 'PC' (point cloud) is a vector or a matrix N x 3 (N=number of points) |
666 |
| -% that contain X Y Z coordinate of the points of the cloud |
667 |
| - |
668 |
| -centroid = mean(PC); % calculate centroid of point cloud |
669 |
| - |
670 |
| -%[U, S, W] = svd(PC); |
671 |
| - |
672 |
| -C = cov(PC); % calculate the covariance matrix 'C' |
673 |
| - |
674 |
| -[V, D] = eig(cov(PC)); % calculate eigenvector 'V' and eigenvalue 'D' of the |
675 |
| -% covariance matrix 'C' |
676 |
| - |
677 |
| - |
678 |
| -M = log(D(3,3)/D(1,1));% calculate vertex coplanarity 'M' |
679 |
| -K = log(D(3,3)/D(2,2))/log(D(2,2)/D(1,1));% calculate vertex collinearity |
680 |
| -%'K' |
681 |
| - |
682 |
| - |
683 |
| -N = V(:,1)'; |
684 |
| - |
685 |
| -% Normals have to be oriented upward!!! (Normals have to be horiented in same |
686 |
| -% direction) |
687 |
| - |
688 |
| -if N(1,3)<0 %if normal is oriented downward |
689 |
| - N(1,1)=-N(1,1); |
690 |
| - N(1,2)=-N(1,2); |
691 |
| - N(1,3)=-N(1,3); |
692 |
| -end |
693 |
| -cosAlpha = N(1,1)/norm(N); |
694 |
| -cosBeta = N(1,2)/norm(N); |
695 |
| -cosGamma = N(1,3)/norm(N); |
696 |
| - |
697 |
| -dip = 90 + rad2deg(asin(-cosGamma)); |
698 |
| - |
699 |
| -if cosAlpha > 0 && cosBeta > 0 |
700 |
| -dipdir = rad2deg(atan(cosAlpha/cosBeta)); |
701 |
| -elseif cosAlpha > 0 && cosBeta < 0 |
702 |
| -dipdir = 180 + rad2deg(atan(cosAlpha/cosBeta)); |
703 |
| -elseif cosAlpha < 0 && cosBeta < 0 |
704 |
| -dipdir = 180 + rad2deg(atan(cosAlpha/cosBeta)); |
705 |
| -elseif cosAlpha < 0 && cosBeta > 0 |
706 |
| -dipdir = 360 + rad2deg(atan(cosAlpha/cosBeta)); |
707 |
| -end |
708 |
| - |
709 |
| -%calculate radius of plane = max distance point(projected onto the plane)-centroid of fitted plane |
710 |
| -Plane=createPlane(centroid,N); |
711 |
| -for i=1:length(PC(:,1)) |
712 |
| -PT(i,:) = projPointOnPlane(PC(i,:), Plane); |
713 |
| -end |
714 |
| - |
715 |
| -for i=1:numel(PC(:,1)) |
716 |
| -pdist1 (i) =sqrt((centroid(1,1)-PT(i,1))^2 + (centroid(1,2)-PT(i,2))^2 + (centroid(1,3)-PT(i,3))^2); |
717 |
| -end |
718 |
| - |
719 |
| -[pM1, pI1] = max(pdist1); |
720 |
| - |
721 |
| -for i=1:numel(PT(:,1)) |
722 |
| - if i==pI1 |
723 |
| - pdist2(i)=0; |
724 |
| - else |
725 |
| - pdist2 (i) =sqrt((PT(pI1,1)-PT(i,1))^2 + (PT(pI1,2)-PT(i,2))^2 + (PT(pI1,3)-PT(i,3))^2); |
726 |
| - end |
727 |
| -end |
728 |
| -[pM2, pI2] = max(pdist2); |
729 |
| - |
730 |
| -centroid=mean([PT(pI1,:); PT(pI2,:)]); |
731 |
| -radius =(sqrt((PT(pI1,1)-PT(pI2,1))^2 + (PT(pI1,2)-PT(pI2,2))^2 + (PT(pI1,3)-PT(pI2,3))^2))/2; |
732 |
| - |
733 |
| -%calculation of mean error and standard deviation of fitted plane |
734 |
| -d = -sum(bsxfun(@times, N, bsxfun(@minus, centroid, PT)), 2); |
735 |
| -mean_err=mean(abs(d)); |
736 |
| -stdev_err=std(abs(d)); |
737 |
| - |
738 |
| - |
739 |
| -plane3d = [dip, dipdir, radius, centroid, N, M, K, mean_err, stdev_err]; |
740 |
| - |
741 |
| - |
742 |
| -% REFERENCES: |
743 |
| -% |
744 |
| -% - Jones, R. R., Pearce, M. A., Jacquemyn, C., & Watson, F. E. (2016). |
745 |
| -% Robust best-fit planes from geospatial data. Geosphere, 12(1), 196-202. |
746 |
| -% |
747 |
| -% - Seers, T. D., & Hodgetts, D. (2016). Probabilistic constraints on |
748 |
| -% structural lineament best fit plane precision obtained through |
749 |
| -% numerical analysis. Journal of Structural Geology, 82, 37-47. |
750 |
| -end |
0 commit comments