Gnu Octave是否有任何用于绘制线条或多边形的代码?
题
背景:
我希望能够采用2d矩阵(真正的图像)和一组定义多边形的点,并将该多边形绘制到矩阵中。
在我跑掉并重新发明轮子之前,我想我会问是否有人知道Octave中的任何现有库或代码都是这样做的。到目前为止,我对Octave软件包和google的搜索都是空的。
没错,既不太难实现,但我不确定如何绘制填充多边形。是否有一种简单/有效的方法来判断哪些点位于多边形内部哪些点位于外部?感谢。
编辑:
我的目的不是展示任何东西。实际上,我特别关注的是一些图像处理的东西,比如绘制一个凸包,找到它的区域,找到不在原始对象中的凸包部分等等。
我没有看到Gnu Plot实际上给了我任何可以使用的数据。如果我错了,请务必告诉我如何。感谢。
解决方案
为了在多边形内找到点,您可以尝试在MATLAB Central上发布的Darren Engwirda的MATLAB函数: http://www.mathworks.com/matlabcentral/fileexchange/10391
我简要介绍了代码并没有看到特别是MATLAB特有的东西,所以它可以在Octave中按原样运行。
其他提示
编辑:回应OP的编辑顶部,以便更容易找到:
使gnuplot直接渲染到文件的各种方法(向下滚动到“终端”,然后您可以读入以进行分析。例如,您可以输出到便携式位图格式,这非常容易读写(如果不小而优雅)。请注意,根据定义,PBM将为您提供黑色和白色的数组。
例如,请查看“set terminal”的使用情况。和“设定输出”命令呈现给一系列产生pbm然后是png文件的Unix管道。
结束编辑:
Gnu Octave默认使用gnuplot进行绘图,并且gnuplot非常适合生成填充多边形。以下是一些有用的演示。例如,这里有一些填充的多边形:
# set terminal png transparent nocrop enhanced font arial 8 size 420,320
# set output 'fillcrvs.4.png'
set grid nopolar
set grid xtics nomxtics ytics nomytics noztics nomztics \
nox2tics nomx2tics noy2tics nomy2tics nocbtics nomcbtics
set grid front linetype 0 linewidth 1.000, linetype 0 linewidth 1.000
set key outside right top vertical Right noreverse enhanced autotitles nobox
set title "The red bat: abs(x) with filledcurve xy=2,5"
plot abs(x) with filledcurve xy=2,5
这是另一个演示脚本,它在底部绘制了疯狂的面孔。填充的曲线页面:
# set terminal png transparent nocrop enhanced font arial 8 size 420,320
# set output 'fillcrvs.6.png'
unset border
set dummy t,y
set grid nopolar
set grid xtics nomxtics ytics nomytics noztics nomztics \
nox2tics nomx2tics noy2tics nomy2tics nocbtics nomcbtics
set grid layerdefault linetype 0 linewidth 1.000, linetype 0 linewidth 1.000
unset key
set label 1 "gnuplot" at 0, 1.2, 0 centre norotate front nopoint offset character 0, 0, 0
set label 2 "gnuplot" at 0.02, -0.6, 0 centre norotate front nopoint offset character 0, 0, 0
set arrow 1 from -0.1, 0.26, 0 to 0.18, -0.17, 0 head front nofilled linetype 5 linewidth 4.000 size first 0.100,40.000,90.000
set parametric
set size ratio 1 1,1
set noxtics
set noytics
set title "Let's smile with parametric filled curves"
set xrange [ -1.00000 : 1.00000 ] noreverse nowriteback
set yrange [ -1.00000 : 1.60000 ] noreverse nowriteback
plot [t=-pi:pi] sin(t),cos(t) with filledcurve xy=0,0 lt 15, sin(t)/8-0.5,cos(t)/8+0.4 with filledcurve lt 3, sin(t)/8+0.5,cos(t)/8+0.4 with filledcurve lt 3, t/5,abs(t/5)-0.8 with filledcurve xy=0.1,-0.5 lt 1, t/3,1.52-abs(t/pi) with filledcurve xy=0,1.8 lt -1