필터 지우기
필터 지우기

How do I obtain sampling points inside a pre-defined triangle?

조회 수: 3 (최근 30일)
stars775
stars775 2011년 7월 28일
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
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.
stars775
stars775 2011년 7월 29일
Good suggestion. So far I have used random numbers to generate sampling points on a square, e.g. r = rand(2,100) gives 100 sampling points within this square. But for a triangle it is difficult since it has three different lengths and thus the above mentioned method can't ensure they all fall within this triangle. Of course one can neglect some points... I am still thinking about how to do it.
And yes I am struggling with the Matlab part.

댓글을 달려면 로그인하십시오.

답변 (2개)

Oleg Komarov
Oleg Komarov 2011년 7월 28일
  댓글 수: 1
stars775
stars775 2011년 7월 29일
Thanks a lot Oleg for your answer. I will have a look at his files. Maybe it really helps.

댓글을 달려면 로그인하십시오.


Rick Rosson
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
  댓글 수: 1
stars775
stars775 2011년 7월 29일
Thanks a lot Rick. I have also generated a triangle in 3D but as you said the tricky part is how to generate random points within this surface. Thanks anyway for the tipps for patch.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Elementary Polygons에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by