Why is vec2mtx missing some grid points?
1 回表示 (過去 30 日間)
古いコメントを表示
I am using vec2mtx to figure out which cells in a regular data grid are intersected by a vector of latitude-longitude coordinates.
However, I noticed that vec2mtx is missing some of these cells.
Here is a minimum working example:
lats=[1.5,2.5]; lons=[1.5,3.25]; % just a straight line
[Z,R]=vec2mtx(lats,lons,1,[0,4],[0,4]); % convert those coordinates to a grid
figure; grid2image(Z,R); % plot the grid
hold on; plot(lons,lats,'r'); hold off; % plot the straight line
set(gca,'XTick',0:2,'YTick',0:3,'GridColor','k','GridAlpha',1); % just some adjustments to make the grid clearer
grid on;
This code generates the following figure:
where the yellow cells are equal to 1, and the blue equal to 0.
I was expecting the cell marked with the data cursor to be yellow too, considering that the border (red line) is crossing that cell too.
Is there any way to make sure vec2mtx not to miss cells like in the example above? Or, is there an alternative function to achieve what I am trying here?
0 件のコメント
回答 (1 件)
George Abrahams
2024 年 2 月 10 日
vec2mtx is an implementation of a line drawing algorithm. It takes a continuous line segment and converts it to a discrete grid of pixels.
There are many different algorithms, and I'm not sure which vec2mtx is using. However, the naïve approach you described, filling every pixel the line touches, is typically avoided as it creates lines which are very thick. See the figure below (source) for a comparison.
If you'd like to learn more, here's a good resource too:
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!