How do I obtain sampling points inside a pre-defined triangle?
8 次查看(过去 30 天)
显示 更早的评论
Dear all, I would like to ask how to get sampling points in a triangle. The triangle is arbitrary, where the vertex are defined by three points in a 3D Cartesian coordinate system. I want to have e.g. 100 sampling points within it. These can be random sampling points or regular. How can I achieve this in Matlab? I am a beginner in Matlab so every tip helps. Thanks a lot for your time and help!
best
2 个评论
the cyclist
2011-7-28
Are you struggling with the math part, or the MATLAB part? Maybe you could describe what you yourself have tried so far.
回答(2 个)
Oleg Komarov
2011-7-28
This link may give a good example: http://www.mathworks.com/matlabcentral/fileexchange/31892-generation-of-solid-shapes-using-random-number-generator
Rick Rosson
2011-7-28
Here is some code to get you started. It creates a two patch objects: one that defines a triangle in 3D space based on the X,Y, and Z coordinates (in blue), and the other defines the projection of the same triangle onto the XY-plane (in red):
X = [ 5 12 7 ];
Y = [ 10 10 18 ];
Z = [ 2 5 15 ];
h2 = patch(X,Y,[1 0 0]);
hold on;
h3 = patch(X,Y,Z,[ 0 0 1]);
xlabel('X');
ylabel('Y');
zlabel('Z');
view(30,40);
For more information:
>> doc patch
>> doc view
The next step is to figure out how to generate random points that are located on the surface of this triangle. I am not sure just yet how to do that.
HTH.
Rick
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!