How to expand/shrink 3D Polygon in 2D directions (X-Y)?
6 次查看(过去 30 天)
显示 更早的评论
I have a xyz=17x3 array which forms an open square shape. I want to expand the shape (inside or outside only) with respect to xy_directions only and get a new array xy=17x2 . So I can add the third column (Z) to the new array xy from the original array xyz and end up with a third array XYZ1=17x3. where * XYZ1=[xy(:,1),xy(:,2),xyz(:,3)]*. In this case, I end up with expanded shape in xy_directions but keep (Z) fixed.(which I'm wishing for)
I tried the function expandPolygon from geom2d. But the output array has some rows filled with (Inf) instead of numbers, even though it has the same length as original array xyz.
Hope you can help me with that Thank you so much.
0 个评论
回答(3 个)
Matt J
2017-12-10
编辑:Matt J
2017-12-10
I may not fully understand the question. You have a square floating in 3D space. You want to expand or contract the square within the same plane that it exists now? If so, then you can simply do (assuming you have R2016b or higher) as follows:
xyz_new= c*(xyz-mean(xyz))+mean(xyz);
where c is an expansion or contraction factor. For example, with c=1.5, you would get the orange dots below.
11 个评论
Matt J
2017-12-11
编辑:Matt J
2017-12-11
To map everything into 2D
mu=mean(xyz);
xyzc=xyz-mu;
[~,~,V]=svd(xyzc, 0);
xy=xyzc*V(:,1:2);
Now you can use the geom2D toolkit freely on the 2D data set, xy to generate xy2. As we've discussed, remove redundant colinear points to avoid Infs. To map xy2 back to the original 3D coordinate system,
XYZ1= xy2 * V(:,1:2).' + mu ;
3 个评论
Matt J
2017-12-13
Sorry, I didn't know your xyz could be non-planar. Why don't you just apply expandPolygon to xyz(:,1:2), i.e., the 2D projection of the shape onto the x-y plane?
Matt J
2017-12-13
编辑:Matt J
2017-12-13
The attached file might be close to what you want. When I do
XYZ1=expandShape(xyz,0.1);
on your last xyz data set, I get the orange dots below,
3 个评论
Matt J
2018-4-5
编辑:Matt J
2018-4-5
For such a highly non-planar shape, it is no longer clear how to define its expansion (which is why you might get unexpected results). In your previous examples, the points were all largely "piece-wise planar" and so the plane in which to expand the shape locally was pretty much unambiguous.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!