LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-11-2011, 02:10 PM   #1
zenbo
Member
 
Registered: Dec 2011
Posts: 32

Rep: Reputation: Disabled
programm for perspective-grid


hey guys

i am looking for a program to create perspective-grids to draw skyscrapers, houses etc. in perspective.heres a sample.

http://www.perspectivegrid.com/index.php?page=9^0^0

thanks and greetings zenbo

zenbo

Last edited by zenbo; 12-13-2011 at 06:55 AM.
 
Old 12-11-2011, 08:18 PM   #2
S. Chapelin
Member
 
Registered: Jan 2010
Location: Quebec
Posts: 134

Rep: Reputation: 5
I don't know if I understand your request, but Blender is great for setting up 3d scenes which you can then render as a picture or film with a moving camera. It's free. I've been playing with it for years. You can make anything from buildings to people, etc.
 
Old 12-11-2011, 08:27 PM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
I wasn't sure what a "perspective-grid" was either. Then I did a quick search. If i understand correctly, it's just a 2D projection of squares/rectangles as they diminish to a fixed vanishing point.

Anyway, my terminology notwithstanding, I did see a link to a You Tube video that purports to show how to create perspective grids in GIMP (which should be included in virtually every Linux distribution).

Here's the link: GIMP: How to Create Perspective Grids with the Path Tool
 
Old 12-13-2011, 06:53 AM   #4
zenbo
Member
 
Registered: Dec 2011
Posts: 32

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Dark_Helmet View Post
I wasn't sure what a "perspective-grid" was either. Then I did a quick search. If i understand correctly, it's just a 2D projection of squares/rectangles as they diminish to a fixed vanishing point.

Anyway, my terminology notwithstanding, I did see a link to a You Tube video that purports to show how to create perspective grids in GIMP (which should be included in virtually every Linux distribution).

Here's the link: GIMP: How to Create Perspective Grids with the Path Tool
thanks, but that tool is not good enough, it would take me forever...

heres what i mean, those grids are for artists to draw houses etc. over them:

http://www.perspectivegrid.com/index.php?page=9^0^0
 
Old 12-15-2011, 07:31 AM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Well, I was bored and struck by inspiration. So I wrote a script to generate some basic perspective grids using gnuplot.

This probably won't do everything you want it to do. However, it shows that with some scripting, you can modify it and get the features you want.

To use it, you will need to have gnuplot and bc installed. Almost every distribution has bc. So the only thing you might need to install would be gnuplot.

The way it works is, you specify vanishing point coordinates on the command line. You can specify as many as you like, but I've never seen more than two. You also specify an angle increment for each vanishing point. For each vanishing point, a horizontal line is drawn. Then an angled line is drawn through each vanishing point at each angle increment specified.

For instance, you could run the script like so:
Code:
<script_name> -point 10 7 -angle 5 -point 1 7 -angle 10
That would create two vanishing points: (10, 7) and (1, 7). The first vanishing point (10, 7) will have radial lines drawn from it at 5, 10, 15, 20, ... 360 degrees. The second vanishing point (1, 7) will have radial lines drawn from it at 10, 20, 30, 40, ... 360 degrees. Note: the "-angle" option influences the point most recently specified.

The coordinates are in "inches" and the origin would be the bottom-left of the image produced. The script defaults to creating an image for a plain 8.5 x 11 sheet of paper in landscape. The visible coordinates are restricted to the paper size. For instance, using the defaults, x-values from 0 to 11 would be visible and y-values from 0 to 8.5 would be visible.

There is no restriction on the placement of the vanishing points--they need not be placed within the viewable area.

Some caveats:
(1) Because gnuplot is used as the drawing workhorse, it is not a simple matter to have it draw a vertical line. It's not impossible to do (there are directives to manually draw non-function related lines), but I didn't look into it much. Besides, manually drawing one vertical line per vanishing point ain't a lot of inconvenience.

(2) Currently, the angle increment(s) must be integers and they should divide into 180 degrees evenly. If they do not divide into 180 evenly, the radial lines will be "unbalanced."

(3) While this script cannot create the image shown on the website you linked to, it is feasible to use the script two or more times and piece the resulting images together. For instance, to create the "floor" of the image on that webpage, you could run the script once with a few vanishing points (e.g. "<script_name> -point 5.5 8.5 -angle 5 -point 5.5 8 -angle 180 -point 5.5 7 -angle 180 -point 5.5 5 -angle 180"). By placing the first point at the upper limit of the viewing area, you "cut off" the top half of the radial lines. The subsequent points are horizontal lines because their angle increment is 180. You repeat the process for the "roof" by creating another plot, but this time putting the first vanishing point at the bottom of the viewing area and placing the horizontal lines above.

You might also use image manipulation software to do some scaling. Though, it is possible to do that directly through gnuplot. I did not add that into the script, but it could be done.

In all, it's passable and decent (in my opinion) for a few hours of hacking. If you want to try it out, make sure you read the script's comments regarding options it recognizes (e.g. -point, -angle, -dpi, -paperwidth, -paperheight, -output). There is NO nice "usage" help message.

Copy the script into a text editor, save it, make it executable (chmod u+x <script_name>), and then give it a try if you like.

Here's the script
Code:
#!/bin/bash

# Command variables. Currently the script needs gnuplot, bc, printf, and rm
# Customize to your location if the paths are different
cmdGNUPLOT=/usr/bin/gnuplot
cmdBC=/usr/bin/bc
cmdPRINTF=/usr/bin/printf
cmdRM=/bin/rm

# Default angle increment
defaultANGLE=5

# File to hold all the gnuplot commands
dataFILE=/tmp/perspective_grid.gnuplot

# File to save the plot/image to
outputFILE=perspective_grid.png

# Default resolution of the image
dotsPerInch=300

# Physical dimensions of the target paper/canvas (in inches)
paperWidth=11
paperHeight=8.5

# There really should be a "usage" message and/or argument-checker, but
# I'm not motivated to do that right now.
if [ $# -lt 2 ] ; then
  echo "args error"
  exit 1
fi

# coordID is a marker into the array containing vanishing points
coordID=-1
while [ $# -gt 0 ] ; do

  # "-point" identifies a new vanishing point
  # format: "-point <x coordinate> <y coordinate>"
  # coordinates can be floating point
  if [ "${1}" = "-point" ] ; then
    let coordID=coordID+1
    x_coord[${coordID}]=${2}
    y_coord[${coordID}]=${3}
    shift 3
    continue
  fi

  # "-angle" specifies the frequency of radial lines through the vanishing
  #    point in terms of degrees
  # format: "-angle <degrees>"
  # The angle will be applied to the most recently defined vanishing point on
  # the command line.
  # Currently, the angle argument MUST be an integer AND it must be able to
  # divide 180 degrees evenly
  if [ "${1}" = "-angle" ] ; then
    angle_data[${coordID}]=${2}
    shift 2
    continue
  fi

  # "-dpi" specifies the final plot/image resolution (as calculated by the
  #    paper/canvas dimensions)
  # format: "-dpi <dots per inch>
  # The argument should be an integer. Script may work if a float. Untested.
  if [ "${1}" = "-dpi" ] ; then
    dotsPerInch=${2}
    shift 2
    continue
  fi

  # "-paperwidth" and "-paperheight" specify the physical dimensions of the
  #    paper/canvas
  # format: "-paperwidth <size in inches>"
  #         "-paperheight <size in inches>"
  # The argument to either option can be floating point.
  if [ "${1}" = "-paperwidth" ] ; then
    paperWidth=${2}
    shift 2
    continue
  fi

  if [ "${1}" = "-paperheight" ] ; then
    paperHeight=${2}
    shift 2
    continue
  fi


  # "-output" specifies the output image filename
  # format: "-output <filename>"
  if [ "${1}" = "-output" ] ; then
    outputFILE=${1}
    shift 2
    continue
  fi

  echo "ERROR: Unrecognized argument: ${1}"
  exit 2
done

# Calculate the needed resolution of the generated image
pixelWidth=$( echo "${dotsPerInch}*${paperWidth}" | ${cmdBC} -l )
pixelHeight=$( echo "${dotsPerInch}*${paperHeight}" | ${cmdBC} -l )

# Strip/truncate any decimal places--need an integer
pixelWidth=$( ${cmdPRINTF} "%.0f" ${pixelWidth} )
pixelHeight=$( ${cmdPRINTF} "%.0f" ${pixelHeight} )

# Gnuplot directives
# set output -> tells gnuplot where to save the image
# set terminal png size X,Y -> tells gnuplot to save as PNG and at what size
# unset xtics, unset ytics -> remove the numeric values on the axes
# set angle degrees -> use degrees rather than (default) radians
# set key off -> turn off the plot's legend
# set xrange[0:X] -> specify the plot/image's horizontal view
# set yrange[0:Y] -> specify the plot/image's vertical view
echo "set output \"${outputFILE}\"" > ${dataFILE}
echo "set terminal png size ${pixelWidth},${pixelHeight}" >> ${dataFILE}
echo "set size square" >> ${dataFILE}
echo "unset xtics" >> ${dataFILE}
echo "unset ytics" >> ${dataFILE}
echo "set angle degrees" >> ${dataFILE}
echo "set key off" >> ${dataFILE}
echo "set xrange[0:${paperWidth}]" >> ${dataFILE}
echo "set yrange[0:${paperHeight}]" >> ${dataFILE}

# Like with the command line argument parsing, coordID will serve as an
# index into the vanishing point array to work with. Only this time, it
# will work backward.
let coordID=coordID+1

# function_counter is just a number used to suffix the various function
# definitions given to gnuplot so that each function will have a unique
# name.
function_counter=0
while [ ${coordID} -gt 0 ] ; do
  let coordID=coordID-1

  # Give the user a warm and fuzzy by restating command line arguments in a
  # more concise form
  echo "Perspective point: ( ${x_coord[${coordID}]}, ${y_coord[${coordID}]})"
  if [ -z "${angle_data[${coordID}]}" ] ; then
    angle_data[${coordID}]=${defaultANGLE}
  fi
  echo "  Line every ${angle_data[${coordID}]} degrees"

  # angle_counter starts at 180 and is repeatedly subtracted by the specified
  # angle increment
  angle_counter=180
  while [ ${angle_counter} -gt 0 ] ; do

    # Angle = 180 is a horizontal line
    if [ ${angle_counter} -eq 180 ] ; then
      echo "f${function_counter}(x) = ${y_coord[${coordID}]}" >> ${dataFILE}
      let function_counter=function_counter+1
    fi

    if [ ${angle_counter} -eq 90 ] ; then
      echo "# No support for vertical lines yet" >> ${dataFILE}
    else
      # Most interesting case. The function defining the line to draw is:
      # f(x) = (x - vanishing_x) * tan(angle) + vanishing_y
      echo "f${function_counter}(x) = (x - ${x_coord[${coordID}]}) * tan(${angle_counter}) + ${y_coord[${coordID}]}" >> ${dataFILE}
      let function_counter=function_counter+1
    fi

    let angle_counter=angle_counter-${angle_data[${coordID}]}
  done
done

# Construct our "plot" directive to gnuplot by counting backwards through
# all the functions defined in the loop above.
#
# The "lt -1" added after each function reference just tells gnuplot to
# use a black line. By default, gnuplot wants to use multi-colored
# lines to differentiate each function.
echo -n "plot " >> ${dataFILE}
while [ ${function_counter} -gt 0 ] ; do
  let function_counter=function_counter-1
  echo -n "f${function_counter}(x) lt -1" >> ${dataFILE}
  if [ ${function_counter} -gt 0 ] ; then
    echo -n ", " >> ${dataFILE}
  else
    echo "" >> ${dataFILE}
  fi
done

# Creation of the gnuplot data file is finished. Launch gnuplot and point
# it to the file.
${cmdGNUPLOT} ${dataFILE}

if [ $? -eq 0 ] ; then
  echo "GNUPlot exited cleanly. See \"${outputFILE}\" for image"
else
  echo "GNUPlot failed. Please check your arguments and/or the data file given"
  echo " to GNUPlot:"
  echo " ${dataFILE}"
  exit 3
fi

# Cleanup
${cmdRM} ${dataFILE}  

exit 0

Last edited by Dark_Helmet; 12-15-2011 at 07:33 AM.
 
1 members found this post helpful.
Old 12-15-2011, 02:21 PM   #6
zenbo
Member
 
Registered: Dec 2011
Posts: 32

Original Poster
Rep: Reputation: Disabled
wow!!!!!

thanks alot, i hope i get this thing running!!
thanks mate, i appreciate it!!!!!!!

greetings zenbo
 
Old 12-15-2011, 02:31 PM   #7
zenbo
Member
 
Registered: Dec 2011
Posts: 32

Original Poster
Rep: Reputation: Disabled
im quite a newb, i will download that program, and see if i can run your script, maybe ill need some help, and you happen to have time to check this thread, ill keep ya informed.

thanks and greetings zenbo
 
Old 12-15-2011, 02:33 PM   #8
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Well, I'm actually working on improving it a bit.

I'm trying to add angle start/stop for the radial lines, give the alternative option of saying "I want X radial lines spaced equally between the start-stop angles," and allow for floating-point angle values.

And I'm looking at changing the drawing mechanism from functions to two-point line segments--which would allow for vertical lines easily enough. Though, I need to look at the gnuplot docs just to make sure what I'm thinking is possible.

I'll post a revised script with what I get working. I may not get everything I want added, but I'll get some.
 
Old 12-15-2011, 02:45 PM   #9
zenbo
Member
 
Registered: Dec 2011
Posts: 32

Original Poster
Rep: Reputation: Disabled
ok, first prob, i downloaded gnuplot, but cant find it, its not where the other progs are...

also i pasted the script into the terminal, and pressed enter, after that the terminal desapeared..

Last edited by zenbo; 12-15-2011 at 02:54 PM.
 
Old 12-15-2011, 02:56 PM   #10
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
You'll be using this from the command line. You won't ever actually manually open gnuplot--the script takes care of that.

So, open a terminal: if you're using Ubuntu or something Debian-based, there should be an Applications->Accessories->Terminal menu item (or something similar). That will get you to a command prompt.

Save the script somewhere. And then, in the terminal, issue "cd <path>" where <path> is the directory to where you saved the script.

Once in the same directory (you can confirm by typing "ls -l" at the terminal, and you should see the filename of the script you saved), then issue the command "chmod u+x <filename>" where <filename> is whatever you named your local copy of the script.

To run it, the type "./<filename> <options>" where <options> are whatever switches you want to give the script. It should print some info, and if all is successful, there will be a new PNG file in the same directory. You can use whatever image-viewing utility you like to look at it. Just navigate to it with whatever file manager you use and double-click.

EDIT:
Quote:
Originally Posted by zenbo
also i pasted the script into the terminal, and pressed enter, after that the terminal desapeared..
Paste it into an editor like gedit. Then save it as something like "perspective_grid.bash" or whatever name you think is appropriate.

The reason the terminal disappeared was because pasting it directly caused the terminal to try and execute the script then and there. There are some "exit" statements that would have caused the terminal to close. It's not a big deal. Like I said, just save it as a file, and you'll launch it from the terminal a little later.

EDIT2:
And to make sure that gnuplot is installed, type "which gnuplot" at the terminal. If it doesn't spit out anything but another prompt, then gnuplot has not been installed. You should see something like this:
Code:
user@localhost:~$ which gnuplot
/usr/bin/gnuplot
user@localhost:~$

Last edited by Dark_Helmet; 12-15-2011 at 03:02 PM.
 
Old 12-15-2011, 03:47 PM   #11
zenbo
Member
 
Registered: Dec 2011
Posts: 32

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Dark_Helmet View Post

So, open a terminal: if you're using Ubuntu or something Debian-based, there should be an Applications->Accessories->Terminal menu item (or something similar). That will get you to a command prompt.
im still stuck here, im with linux-mint, when opening the terminal i cant find:Applications->Accessories->Terminal

you dont mean typing it in, right?

did you mean alt+F2 , (run application) ?
 
Old 12-15-2011, 03:51 PM   #12
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
You don't necessarily need to use that specific method. In an earlier reply, you mentioned that you had pasted the script directly into the terminal and the terminal disappeared.

However you opened that previous terminal is fine--just so long as you can get to a command line.

Last edited by Dark_Helmet; 12-15-2011 at 03:52 PM.
 
Old 12-15-2011, 03:59 PM   #13
zenbo
Member
 
Registered: Dec 2011
Posts: 32

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Dark_Helmet View Post
You don't necessarily need to use that specific method. In an earlier reply, you mentioned that you had pasted the script directly into the terminal and the terminal disappeared.

However you opened that previous terminal is fine--just so long as you can get to a command line.
i dont get it mate, what should i open, where can i find a comand line?
 
Old 12-15-2011, 04:07 PM   #14
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Quote:
also i pasted the script into the terminal, and pressed enter, after that the terminal desapeared
However you opened the terminal you were talking about in the above message is fine.

Other options:
1. Navigate through your programs menu (or whatever Mint refers to it as) and look for any subgroup that has an entry for "terminal" or "command line." And start it from there.

2. You can use the alt+f2 shortcut if you like and run "gnome-terminal" or "xterm" or "konsole" or whatever terminal emulator you have installed.
 
Old 12-15-2011, 04:18 PM   #15
zenbo
Member
 
Registered: Dec 2011
Posts: 32

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Dark_Helmet View Post
However you opened the terminal you were talking about in the above message is fine.

Other options:
1. Navigate through your programs menu (or whatever Mint refers to it as) and look for any subgroup that has an entry for "terminal" or "command line." And start it from there.

2. You can use the alt+f2 shortcut if you like and run "gnome-terminal" or "xterm" or "konsole" or whatever terminal emulator you have installed.
can i open alt+f2 and put in your script and run it?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
opengl perspective question Valkyrie_of_valhalla Programming 2 12-14-2009 12:13 PM
How window in programm can be resized by another programm. rexStart Programming 1 09-23-2008 03:47 AM
LXer: Perspective is as Perspective Does LXer Syndicated Linux News 0 07-21-2006 09:03 AM
Eclipse has no Java perspective netjack SUSE / openSUSE 1 05-01-2006 10:33 AM
Noobs perspective on install aikidoist72 Debian 2 02-04-2005 11:26 PM


All times are GMT -5. The time now is 11:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration