Does Gnu Octave have any existing code for drawing lines or polygons?

Background:

I want to be able to take a 2d matrix (the image is indeed) and a set of points defining a polygon and draw that polygon in the matrix.

Before I run away and reinvent the wheel, I thought I'd ask if anyone knows of existing libraries or codes in Octave that do this. So far, my searches through Octave and google packages have been empty.

Otherwise not too hard to implement, but I'm not sure how to draw the filled polygon. Is there a simple / efficient way to determine which points are inside the polygon and which are outside? Thank.

Edit:

My target is displaying nothing. In fact, what I am specifically looking at are some image processing tools such as building a convex hull, finding its area, finding parts of a convex hull not in the original object, etc.

I don't see Gnu Plot actually returning data to me that I can work with. If I'm wrong, be sure to tell me how to do it. Thank.

+2


source to share


2 answers


For finding points inside a polygon, you can try Darren Engwirda MATLAB function hosted on MATLAB Central: http://www.mathworks.com/matlabcentral/fileexchange/10391



I have skimmed the code briefly and don't see anything special, especially for MATLAB, so it might work like-in Octave.

+1


source


EDIT: Edit the top of the document to make it easier to find:

There are many ways to make gnuplot render directly to a file (scroll down to "Terminal"), which you can then read for analysis. For example, you can output to a bitmap format that is surprisingly easy to read and write (if not small and elegant). Note that by definition PBM will provide you with an array of blacks and whites.

For example, check out this use of the "set terminal" and "set output" commands to display in a series of Unix pipes that produce a pbm and then a png file.

End EDIT:



Gnu Octave uses gnuplot by default for plotting, and it happens that gnuplot does a good job at creating filled polygons. Here are some helpful demonstrations of exactly this kind of thing. For example, here are some filled polygons :

# 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

      

Here's another demo script that draws a crazy face at the bottom of the filled curves page:

# 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 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

      

+1


source







All Articles