![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179336/image.jpeg)
Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
creating a polygon using device
조회 수: 3 (최근 30일)
이전 댓글 표시
I have 2 functions in matlab t.go (which moves my device 0.1 units forward starting at the origin, facing absolute right at the star) and t.turn(angle) which turns the device with an angle you input. How would I go about drawing I would say a 25 sided polygon around the origin who's distance from the origin to the edge of the polygon is 5.
댓글 수: 0
답변 (2개)
Image Analyst
2015년 11월 15일
Do you mean like this:
theta = 0 : 360/25 : 360;
x = 5 * sind(theta);
y = 5 * cosd(theta);
plot(x, y, 'b*-', 'LineWidth', 2);
grid on;
hold on;
axis square
% Draw lines from origin to the points in red
for k = 1 : length(y)
plot([0,x(k)], [0, y(k)], 'r-');
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179336/image.jpeg)
If you want the angle to turn from one side to head towards the next (x, y) location, that's just simple high school trigonometry that I would think you can handle. Let me know if you can't figure it out.
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!