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.

回答(2 个)

Image Analyst
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.

Matt J
Matt J 2022-2-13
编辑:Matt J 2022-2-13
Seems like a direct application of,
[N,Zedges,Yedges, binZ, binY] = histcounts2(Z,Y,Zedges,Yedges)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by