I want to find weight matrix for Algebraic reconstruction method. For this I have to find the line intersection with grid. I can find direct line intersection with line but I have to store the intersected line segment grid number wise. So suppose if in grid first square don't intersect with grid then put zero on first element of weight matrix.
Here code which I tried for line intersection:
ak = 3:6
aka = 3:6
x = zeros(size(aka))
y = zeros(size(ak))
for k = 1:length(ak)
line([ak(1) ak(end)], [aka(k) aka(k)],'color','r')
end
% Vertical grid
for k = 1:length(aka)
line([ak(k) ak(k)], [aka(1) aka(end)],'color','r')
end
hold on;
X =[0 15.5]
Y = [2.5 8.5]
m = (Y(2)-Y(1))/(X(2)-X(1)) ;
c = 2.5 ;
plot(X,Y)
axis([0 10 0 10])
axis square
% plotting y intercept
for i = 1:4
y(i) = m * ak(i) + c
if y(i)<2 || y(i)>6
y(i) = 0
end
end
% plotting x intercept
for i = 1:4
x(i) = (y(i) - c)/m
if x(i)<2 || x(i)>6
x(i) = 0
end
end
z = [x' y']
I have a line, defined by the parameters m, h
, where y = m*x + h
This line goes across a grid (i.e. pixels).
For each square (a, b)
of the grid (i.e. the square [a, a+1]x[b, b+1]
), I want to determine if the given line crosses this square or not, and if so, what is the length of the segment in the square so that I can construct the weight matrix which is essential for algebraic reconstruction method.