我在Matlab编程风电场,在那里我需要计算距离具有角度Alpha的线的距离,并通过平面中每个点(x2,y2)的点(x,y)。
就像我上传的图像一样,我需要计算距离s [m,n]和r [m,n]的二维矩阵。
到目前为止我的代码:
for I=1:1:2000
xquery=I;
for J=1:1:2000
yquery=J; %Yquery point from -999 tp 1001
if (xquery-xcen1<0)
Raddist1(I,J)=0; %Radial distance from query point
Axialdis(I,J)=0; %Axial distance from query point
%q=q+1;
elseif m1==0 %If line is parallel to x-axis
m2=0;
a1=xquery; %X-coordinate equals query point
b1=intercept1; %Y-coordinate equals Y-axis intercept as slope m=0 for horizontal line.
linex(I,J)=a1; %Storing X value of intersection between perpendicular line
liney(I,J)=b1;
line(linex,liney);
dist1=(a1-xquery)^2+(b1-yquery)^2;
Raddist1(I,J)=sqrt(dist1);
%yy12=m2*x+interc12; %Equation of line passing through query point and 90 degree to centerline of WT
Axialdis1(I,J)=sqrt((a1-xcen1)^2+(b1-ycen1)^2);
g=g+1;
else
h=h+1;
m2=(-1/m1);
interc12=-(m2*xquery)+yquery; % y=mx+c equation
a1=(interc12-intercept1)/ (m1-m2); %intersection X-coordinate of two line
b1=m2*a1+interc12; %intersection Y-coordinate of two line
linex(I,J)=a1;
liney(I,J)=b1;
dist=(a1-xquery)^2+(b1-yquery)^2;
Raddist1(I,J)=sqrt(dist);
yy12=m2*x+interc12; %Equation of line passing through query point and 90 degree to centerline of WT
Axialdis1(I,J)=sqrt((a1-xcen1)^2+(b1-ycen1)^2);
end
end