Draw angles lines over circle and get the intersecting points

我是研究僧i 提交于 2019-12-11 08:37:29

问题


I wish to draw angle lines over a circle (I change the angles in the script). The plot line I get is 0 angle, why does the script not show me all of them, and how can I fix it? In addition, how can I calculate the intersection points?

Script:

clc;
clear;
close all;

r=1000;

% based on : https://stackoverflow.com/questions/29194004/how-to-plot-a-circle-in-matlab
nCircle = 1000;

t = linspace(0,2*pi,nCircle);

xCircle = 0+ r*sin(t);  
yCircle = 0+ r*cos(t);  

line(xCircle,yCircle );

axis equal;
hold on;

nAngles = 45;
inceasedNumber = 360/nAngles;
lineLength = r+50;

for angle = 0:359:inceasedNumber
    xLine(1) = 0;
    yLine(1) = 0;
    xLine(2) = xLine(1) + lineLength * cosd(angle);
    yLine(2) = yLine(1) + lineLength * sind(angle);
    plot(xLine, yLine);
end

回答1:


I think there is a mistake in the definition of your for loop. The stepsize must appear in the middle between start and end of the iteration:

for angle = 0:inceasedNumber:359

Furthermore MATLAB is using Radians to specify an angle, hence 360° equals 2pi and you have to change your inputs accordingly.

For the intersection of the lines and the circle I would consider geometry before implementation ;)



来源:https://stackoverflow.com/questions/51147322/draw-angles-lines-over-circle-and-get-the-intersecting-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!