How to find out the coordinates of the rectangles through which a straight line passes?
조회 수: 2 (최근 30일)
이전 댓글 표시
clc;
clear all;
close all;
d1=5; %d1=Number of horizontal pixels+1
d2=5; %d2=Number of vertical pixels+1
dos=20;
X=zeros(d2,d1);
y=linspace(4,16,d1);
z=linspace(0,4,d2);
[Y,Z]=meshgrid(y,z);
A=mesh(X,Y,Z);
hold on
X1=zeros(d2,d1)+dos; %
y1=linspace(7,13,d1);
z1=linspace(0,2,d2);
[Y1,Z1]=meshgrid(y1,z1);
A1=mesh(X1,Y1,Z1);
%% Plotting of Straight Line Radiation from A towards A1
for k=(z(1)+0.5*(z(d2)-z(1))/(d2-1)):(z(d2)-z(1))/(d2-1):z(d2)
for j=(y(1)+0.5*(y(d1)-y(1))/(d1-1)):(y(d1)-y(1))/(d1-1):y(d1)
line([X(1),35],[j,j],[k,k],'Color','red');
end
end
I have two meshes 'A' and 'A1'.I have plotted straight lines from the centre of each rectangular cell of 'A'towards 'A1'.
I want to find out the coordinates of the rectangular cells of A1 through which any straight line from A passes. I can do this visually also but if the value of 'd1' and 'd2' will increase,then the process will become tiresome.
댓글 수: 0
답변 (2개)
Image Analyst
2022년 2월 13일
From your plot, it looks like the red lines emanating from your left rectangle (in the Y-Z plane) intersect the inner, smaller rectangle perpendicularly. In that case, can't you just see if the (y, z) coordinate of the red line falls within the (y,z) range spanned by your inner rectangle. If it does, the (y,z) coordinates are the same, unless you're defining a new coordinate system for your inner rectangle.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!