# How can I generate data points form arbitrary shape in 2D in MATLAB ?

조회 수: 7 (최근 30일)
Ammar 2016년 12월 1일
답변: Walter Roberson 2017년 1월 14일
Dear All, I would like to ask: How can I generate data points form arbitrary shape in 2D in MATLAB ?

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

### 답변 (3개)

Image Analyst 2016년 12월 1일
numberOfVertices = 15;
x = rand(1, numberOfVertices);
y = rand(1, numberOfVertices);
If you want an image, use
binaryImage = poly2mask(x, y, rows, columns);
##### 댓글 수: 7이전 댓글 5개 표시이전 댓글 5개 숨기기
Image Analyst 2016년 12월 1일
Not that I know of. Perhaps if you were able to read a font file. In the meantime, here's some code that will create a heart shape:
t = linspace(-pi,pi, 350);
X = t .* sin(pi * .872*sin(t)./t);
Y = -abs(t) .* cos(pi * sin(t)./t);
plot(X,Y);
fill(X, Y, 'r');
axis square;
set(gcf, 'Position', get(0,'Screensize'));
title('Happy Valentines Day', 'FontSize', 28);
There is also code to create a Batman logo: http://www.mathworks.com/matlabcentral/answers/13131-batman-equation-in-matlab#answer_17935 But nothing for a letter B I'm afraid. Sorry.
Ammar 2016년 12월 2일
Dear Image Analyst, thank you very very much for your help. I found something in the Internet as well to generate the data points and when plot the data points give me concave shape. Please, could you look at this code and modify it to give letter B. i.e. generate data points and when I plot those data points give me the shape letter B. Regards.
C1 = [0 0]; % center of the circle C2 = [-5 7.5]; R1 = [8 10]; % range of radii R2 = [8 10]; A1 = [1 3]*pi/2; % [rad] range of allowed angles A2 = [-1 1]*pi/2;
nPoints = 1000;
urand = @(nPoints,limits)(limits(1) + rand(nPoints,1)*diff(limits)); randomCircle = @(n,r,a)(pol2cart(urand(n,a),urand(n,r)));
[P1x,P1y] = randomCircle(nPoints,R1,A1); P1x = P1x + C1(1); P1y = P1y + C1(2);
[P2x,P2y] = randomCircle(nPoints,R2,A2); P2x = P2x + C2(1); P2y = P2y + C2(2);
x=[P1x P1y]; y=[P2x P2y]; Data4=[x; y]; plot(Data4(:,1),Data4(:,2),'.')

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

Image Analyst 2016년 12월 1일
Do you want the boundary points of a binary image shape? If so, use bwboundaries().
##### 댓글 수: 2없음 표시없음 숨기기
Ammar 2016년 12월 1일
Dear Image Analyst, I would like to thank you for this answer. Please, I am looking for data points when I plot them give me arbitrary shape. For example, shape like star or curve or Shape of letter B. I need the real data points give me those figures. Regards
Image Analyst 2017년 1월 14일
And where do you think those real data points will come from if you don't have them already? Apparently you didn't think they can come from images of shapes as I suggested. So exactly where are you going to get those boundary points?

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

Walter Roberson 2017년 1월 14일
Daya tables for one of the famous vector fonts is given at http://paulbourke.net/dataformats/hershey/

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

### 카테고리

Help CenterFile Exchange에서 Valentines Day에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by