필터 지우기
필터 지우기

Drawing a star with n points

조회 수: 16 (최근 30일)
James Connor
James Connor 2015년 10월 16일
댓글: Adam Danz 2021년 3월 25일
Hi guys I have this question to do but I have no clue for any of it.
First write a function file star.m with first line function turtle=star(turtle,npoints,R,r) which uses turtle to draw a star centred at the turtle’s current location. Inputs: • turtle: an initialized turtle to draw the star with; • npoints: the number of points the star; • R: distance from the centre of the star to the points; • r: distance from the centre to the inward corners between the points. Output turtle: turtle used for drawing in its new state. One point of the star should point in the initial direction of the turtle.
Thanks help would be appreciated.
  댓글 수: 4
Maria Koneva
Maria Koneva 2020년 6월 11일
Sounds like python
Adam Danz
Adam Danz 2021년 3월 25일
See createStarVertices() on the file exchange where you can set
  • number of rays
  • center point
  • inner and outer diameters
  • orientation

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

채택된 답변

Image Analyst
Image Analyst 2015년 10월 16일
Attached are my only two star demos. You're welcome to adapt them.
  댓글 수: 2
James Connor
James Connor 2015년 10월 18일
Hey I'm not really sure what to modify on your code to turn it into a regular star? Thanks for the help
Image Analyst
Image Analyst 2015년 10월 18일
편집: Image Analyst 2015년 10월 18일
James, try this to draw one star. Change parameters to do whatever else you need to do with your turtle to define the location and angle of the star.
% Define parameters
numberOfPoints = 5;
rotationAngle = 0;
xCenter = 3;
yCenter = 4;
% Determine the angles that the arm tips are at
theta = (0 : (numberOfPoints-1)/numberOfPoints*pi : (numberOfPoints-1)*pi) + rotationAngle;
% Define distance from the arm tip to the center of star.
amplitude = 3;
% Get x and y coordinates of the arm tips.
x = amplitude .* cos(theta) + xCenter;
y = amplitude .* sin(theta) + yCenter;
% Draw it.
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
axis square;

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by