Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
can i open alt+f2 and put in your script and run it?
Not yet.
1. Copy the script into a text editor.
2. Save the script to a file. Name it "perspective_grid.bash" -- take note of the directory the file is saved in (e.g. /home/<username>/Documents)
3. Open a terminal (e.g. alt+f2 and type "gnome-terminal" in the prompt)
- you should get a new window that allows you to type commands
4. Verify that gnuplot is installed by typing "which gnuplot" as a command in the new terminal window. You should see output similar to what I showed at the end of one of my earlier replies.
5. Type "cd /home/<username>/Documents" as a command in the new terminal window -- this is the same directory mentioned in step #2 and <username> should be replaced with whatever you saw previously. Also, just in case, directory names in Linux are case-sensitive. In other words "documents" is not the same as "Documents"
6. Type "ls -l" as a command in the terminal window. You should see a text listing of all the files in the directory. Confirm that "perspective_grid.bash" is listed
7. Type "chmod u+x perspective_grid.bash" as a command in the terminal window. You won't see any output--just another prompt.
8. Type "./perspective_grid.bash -point 4 4" as a command in the terminal window. The script will print some information, and if all goes well, a new file should be created called "perspective_grid.png"
9. Use a graphical file manager to view your Documents directory. Double-click the icon for "perspective_grid.png" and it should open in your default image viewer program. You should be able to print/shrink/stretch/whatever through that program's tools.
10. To create another image, go back to the terminal and type "./perspective_grid.bash <options>" where <options> is replaced by the sequence of items you want (e.g. different vanishing points, angles, paper dimensions, etc.)--as described by the comments in the script.
11. Once you think the script can handle what you need, then we can talk about getting it so you can run it straight from the alt+f2 prompt.
Look through your programs menu. Look for an "accessories" sub group. There should be an entry titled "gedit Text Editor" or something similar.
Alternatively, you can use alt+f2 again. If you use alt+f2, then type "gedit" as the command. A new window should open that will allow you to type or copy-paste text into a new document and save it.
Look through your programs menu. Look for an "accessories" sub group. There should be an entry titled "gedit Text Editor" or something similar.
Alternatively, you can use alt+f2 again. If you use alt+f2, then type "gedit" as the command. A new window should open that will allow you to type or copy-paste text into a new document and save it.
mmh ok,
reply to which gnupol is :"/usr/bin/gnuplot"
then i dont get:"cd /home/<username>/Dokumente" , whats the username? the documents name? my name?
do i write these ">" as well?
then i dont get:"cd /home/<username>/Dokumente" , whats the username? the documents name? my name?
The username is probably the same as your Linux user account name. For instance, on my machine, I have an account named "darkhelmet". If I were to follow the directions I gave, I would type: "cd /home/darkhelmet/Documents"
I only use the '<' and '>' to help signify that a specific portion of the instructions should be replaced with whatever matches your setup. You would not type them as part of the command.
EDIT:
But again, I used that as an example of what is normal on systems I have used. The main thing is, it should match the directory that you saved the script to.
If you have trouble finding the file, go to the terminal window and type exactly this (you should be able to copy-paste it into your terminal):
Code:
cd $( dirname $( find ${HOME} -name "perspective_grid.bash" | head -n 1 ) )
The above command will find the file and issue the appropriate cd command to satisfy step #5 above.
Last edited by Dark_Helmet; 12-15-2011 at 05:01 PM.
The username is probably the same as your Linux user account name. For instance, on my machine, I have an account named "darkhelmet". If I were to follow the directions I gave, I would type: "cd /home/darkhelmet/Documents"
I only use the '<' and '>' to help signify that a specific portion of the instructions should be replaced with whatever matches your setup. You would not type them as part of the command.
didnt work:
(_)-(_)
wallride@wallride-MXC062 ~ $ which gnuplot
/usr/bin/gnuplot
wallride@wallride-MXC062 ~ $ cd /home/rob/Documents
bash: cd: /home/rob/Documents: No such file or directory
wallride@wallride-MXC062 ~ $ cd /home/rob/Dokumente
bash: cd: /home/rob/Dokumente: No such file or directory
wallride@wallride-MXC062 ~ $ cd /home/ROB/Dokumente
bash: cd: /home/ROB/Dokumente: No such file or directory
wallride@wallride-MXC062 ~ $ cd /home/ROB/Documents
bash: cd: /home/ROB/Documents: No such fi
So now you can play around with it some. For instance, try this:
Code:
./grid -point 12 5 -angle 1 -point -2 5 -angle 1
That will give you the criss-crossing lines where both vanishing points are located off the viewable canvas/paper. Play around and see what it can do.
I've already improved the script to allow vertical lines and start/stop angles. I'll post the updated script once I work out on or two more bugs.
hey this was fun!!!
there are 1,2 and 3 point perspectives, 1 and 2 point perspectives are placed on the horizont line, the third point is placed above ( or under the horizont-line ).
allright mate,im off to sleep, i wish you a good evening, and greetings from central europe. tomorow were suposed to have storms here.
I'm pasting the revised script. Just open up your text editor again, copy-paste it, etc. like before.
If you overwrite the previous copy, you shouldn't need to do the chmod command again.
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
commandFile=/tmp/perspective_grid.gnuplot
vectorDataFile=/tmp/perspective_grid.vector_data
# 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
function PrintUsage() {
cat <<EOF
Usage:
${0##*/} -point <x> <y> [option ...] [-point <x> <y> [option ...]] ...
Creates an image file with one or more points--each point with radial lines
drawn extending outward from the point based on other options.
The options are as follows:
-point <x> <y> Specifies a point to draw radial lines from. The x and y
coordinates are required. The coordinates are in relation
to the origin--located at the lower left corner of the
image produced. Coordinates can be thought of as
representing "inches." Coordinates may be floating point
(e.g. 2.5 3.125)
Any number of points may be specified. Points do not need to
be located within the final viewing area.
-angleinc <deg> Specifies an increment value for radial lines measured in
degrees. For example, "-angleinc 10" would draw radial lines
at 10, 20, 30, 40, ... etc. degrees. The increment value
may be floating point.
This option affects the most recently specified "-point"
defined on the command line and ONLY that point.
Note: the "-radials" option overrides this option.
DEFAULT: ${defaultANGLE}
-anglestart <deg> Specifies the angle at which to start drawing radial lines
measured in degrees. An angle of 0 begins at "3 o'clock" and
the angle moves counter-clockwise as the angle value
increases. The value may be floating point. A radial line
is drawn at the start angle regardless of any other options.
This option affects the most recently specified "-point"
defined on the command line and ONLY that point.
DEFAULT: 0
-anglestop <deg> Specifies the angle at which to stop drawing radial lines
measured in degrees. An angle of 0 begins at "3 o'clock" and
the angle moves counter-clockwise as the angle value
increases. The value may be floating point. A radial line
is drawn at the stop angle regardless of any other options.
This option affects the most recently specified "-point"
defined on the command line and ONLY that point.
DEFAULT: 360
-radials <cnt> Specifies a fixed number of radial lines to draw between
starting and stopping angles. This does not include the lines
drawn for the starting and stopping angles themselves. The
argument must be an integer.
This option affects the most recently specified "-point"
defined on the command line and ONLY that point.
Note: this option overrides the "-angleinc" option
-dpi <resolution> Specifies the resolution of the final image. Argument must
be an integer.
DEFAULT: ${dotsPerInch}
-paperWidth <dim> Specifies the physical width of the final image in "inches."
This is used along with the dots per inch to determine the
true horizontal resolution for the image. Argument may be a
floating point.
DEFAULT: ${paperWidth}
-paperHeight <dim> Specifies the physical height of the final image in "inches."
This is used along with the dots per inch to determine the
true vertical resolution for the image. Argument may be a
floating point.
DEFAULT: ${paperHeight}
-output <filename> Specifies the filename to save the final image to.
DEFAULT: ${outputFILE}
EOF
exit 5
}
# There really should be a "usage" message and/or argument-checker, but
# I'm not motivated to do that right now.
if [ $# -lt 3 ] ; then
PrintUsage
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
# "-angleinc" specifies the frequency of radial lines through the vanishing
# point in terms of degrees
# format: "-angleinc <degrees>"
# The angle effect will be applied to the most recently defined vanishing
# point the command line.
# Note: specifying "-radials" will override "-angleinc"
if [ "${1}" = "-angleinc" ] ; then
angle_increment[${coordID}]=${2}
shift 2
continue
fi
# "-anglestart" specifies the beginning angle at which to draw radial lines
# through the vanishing point (in degrees)
# format: "-anglestart <degrees>"
# The angle effect will be applied to the most recently defined vanishing
# point the command line.
if [ "${1}" = "-anglestart" ] ; then
angle_start[${coordID}]=${2}
shift 2
continue
fi
# "-anglestop" specifies the final angle at which to draw radial lines
# through the vanishing point (in degrees)
# format: "-anglestop <degrees>"
# The angle effect will be applied to the most recently defined vanishing
# point the command line.
if [ "${1}" = "-anglestop" ] ; then
angle_stop[${coordID}]=${2}
shift 2
continue
fi
# "-radials" specifies the the number of evenly spaced radial lines to draw
# through the vanishing point (in degrees)
# format: "-radials <line count>"
# The angle effect will be applied to the most recently defined vanishing
# point the command line.
# Note: specifying "-radials" will override "-angleinc"
if [ "${1}" = "-radials" ] ; then
angle_count[${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}"
PrintUsage
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} )
# Truncate working files
> ${commandFile}
> ${vectorDataFile}
# 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 clip two -> forces gnuplot to all lines even if endpoints are not in
# viewable area
# 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
# plot <stuff> -> give gnuplot a coordinate file, treat the coordinates
# as vector data, do no display heads on the vectors, and
# use simple monochrome/black lines
echo "set output \"${outputFILE}\"" >> ${commandFile}
echo "set terminal png size ${pixelWidth},${pixelHeight}" >> ${commandFile}
echo "unset xtics" >> ${commandFile}
echo "unset ytics" >> ${commandFile}
echo "set clip two" >> ${commandFile}
echo "set angle degrees" >> ${commandFile}
echo "set key off" >> ${commandFile}
echo "set xrange[0:${paperWidth}]" >> ${commandFile}
echo "set yrange[0:${paperHeight}]" >> ${commandFile}
echo "plot '${vectorDataFile}' with vectors nohead lt -1" >> ${commandFile}
# 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
if [ -z "${angle_start[${coordID}]}" ] ; then
angle_start[${coordID}]=0
fi
if [ -z "${angle_stop[${coordID}]}" ] ; then
angle_stop[${coordID}]=360
fi
if [ ! -z "${angle_count[${coordID}]}" ] ; then
angle_increment[${coordID}]=$( ${cmdPRINTF} "%6.3f" $( echo "(${angle_stop[${coordID}]}-${angle_start[${coordID}]}) / (${angle_count[${coordID}]}+1)" | ${cmdBC} -l ) )
fi
# 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_increment[${coordID}]}" ] ; then
angle_increment[${coordID}]=${defaultANGLE}
fi
echo " Radial line every ${angle_increment[${coordID}]} degrees"
echo " Starting: ${angle_start[${coordID}]}"
echo " Stopping: ${angle_stop[${coordID}]}"
# angle_counter starts at specified starting angle and is repeatedly
# incremented by the specified angle increment
angle_counter=${angle_start[${coordID}]}
angle_loop_finished=0
while [ ${angle_loop_finished} -eq 0 ] ; do
# Special case: vertical line
# Angle == 90: vertical line extending "up" (positive y)
if [ $( echo "${angle_counter} == 90" | ${cmdBC} -l ) = "1" ] ; then
y_offset=$( echo "${paperHeight} - ${y_coord[${coordID}]} + 1" | ${cmdBC} -l )
echo "${x_coord[${coordID}]} ${y_coord[${coordID}]} 0 ${y_offset} " >> ${vectorDataFile}
# Special case: vertical line
# Angle == 270: vertical line extending "down" (negative y)
elif [ $( echo "${angle_counter} == 270" | ${cmdBC} -l ) = "1" ] ; then
y_offset=$( echo "-1 * (${y_coord[${coordID}]} + 1)" | ${cmdBC} -l )
echo "${x_coord[${coordID}]} ${y_coord[${coordID}]} 0 ${y_offset} " >> ${vectorDataFile}
# The following is the "normal" which can be handled with trigonometric
# functions to determine offsets
else
if [ $( echo "(${angle_counter} > 90) && (${angle_counter} < 270)" | ${cmdBC} -l ) = "1" ] ; then
x_offset=$( echo "-1 * (${x_coord[${coordID}]} + 1)" | ${cmdBC} -l )
else
x_offset=$( echo "${paperWidth} - ${x_coord[${coordID}]} + 1" | ${cmdBC} -l )
fi
y_offset=$( echo "${x_offset} * s(${angle_counter}*8*a(1)/360)/c(${angle_counter}*8*a(1)/360)" | ${cmdBC} -l )
echo "${x_coord[${coordID}]} ${y_coord[${coordID}]} ${x_offset} ${y_offset}" >> ${vectorDataFile}
fi
# Increment the angle by the desired amount
angle_counter=$( ${cmdPRINTF} "%6.3f" $( echo "(${angle_counter}+${angle_increment[${coordID}]})" | ${cmdBC} -l ) )
# Check if the increment caused us to exceed the given stop angle.
# If so, flag that we're done with the radials for this vanishing point
if [ "$( echo "${angle_counter} > ${angle_stop[${coordID}]}" | ${cmdBC} )" = "1" ] ; then
angle_loop_finished=1
fi
# Check if the angle exceeds 360. If so, subtract 360 to keep the angle
# in the range [0, 360)
if [ "$( echo "${angle_counter} > 360" | ${cmdBC} )" = "1" ] ; then
angle_counter=$( ${cmdPRINTF} "%6.3f" $( echo "${angle_counter} - 360" | ${cmdBC} -l ) )
fi
done
# Once out of the radial line loop, check that we don't need to specifically
# draw the line at the stop angle.
if [ "$( echo "${angle_counter} == ${angle_stop[${coordID}]}" | ${cmdBC} )" = "0" ] ; then
angle_counter=${angle_stop[${coordID}]}
# Special case: vertical line
# Angle == 90: vertical line extending "up" (positive y)
if [ $( echo "${angle_counter} == 90" | ${cmdBC} -l ) = "1" ] ; then
y_offset=$( echo "${paperHeight} - ${y_coord[${coordID}]} + 1" | ${cmdBC} -l )
echo "${x_coord[${coordID}]} ${y_coord[${coordID}]} 0 ${y_offset} " >> ${vectorDataFile}
# Special case: vertical line
# Angle == 270: vertical line extending "down" (negative y)
elif [ $( echo "${angle_counter} == 270" | ${cmdBC} -l ) = "1" ] ; then
y_offset=$( echo "-1 * (${y_coord[${coordID}]} + 1)" | ${cmdBC} -l )
echo "${x_coord[${coordID}]} ${y_coord[${coordID}]} 0 ${y_offset} " >> ${vectorDataFile}
# The following is the "normal" which can be handled with trigonometric
# functions to determine offsets
else
if [ $( echo "(${angle_counter} > 90) && (${angle_counter} < 270)" | ${cmdBC} -l ) = "1" ] ; then
x_offset=$( echo "-1 * (${x_coord[${coordID}]} + 1)" | ${cmdBC} -l )
else
x_offset=$( echo "${paperWidth} - ${x_coord[${coordID}]} + 1" | ${cmdBC} -l )
fi
y_offset=$( echo "${x_offset} * s(${angle_counter}*8*a(1)/360)/c(${angle_counter}*8*a(1)/360)" | ${cmdBC} -l )
echo "${x_coord[${coordID}]} ${y_coord[${coordID}]} ${x_offset} ${y_offset}" >> ${vectorDataFile}
fi
fi
done
# Creation of the gnuplot data file is finished. Launch gnuplot and point
# it to the file.
${cmdGNUPLOT} ${commandFile}
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 " ${commandFile}"
exit 3
fi
# Cleanup
${cmdRM} ${commandFile}
${cmdRM} ${vectorDataFile}
exit 0
I think this is as far as I'll take this script. The new features are to specify start and stop angles for the radial lines on a per-perspective-point basis. Start/stop angles and angle increments can use floating point values now. Alternatively to an angle increment, theres a "radials" option that allows you to specify a fixed number of radial lines drawn between the start and stop angles.
To draw a two-point perspective grid of a "floor" you could do this (with the revised script):
i am looking for a program to create perspective-grids to draw skyscrapers, houses etc. in perspective.
So back to basics. What is the end purpose of your need.
Because if it is to draw skyscrapers, houses etc. in perspective, as you say, fire up Blender, build the skyscrapers, houses etc., place the camera at the angle you need to get the perspective you want and take a picture (render the scene). You can make your buildings as complicated or as simple as you want. If it's for a presentation, you can go professional polish all the way. You can make your buildings of futuristic metal, plastic or alien goo, in any color you want. Or you can just pop some cubes on a plane. There is no limit to what you can do in Blender. And the best thing is that Blender does all the perspective calculations for you.
But then maybe that is not the end purpose of your need.
So back to basics. What is the end purpose of your need.
Because if it is to draw skyscrapers, houses etc. in perspective, as you say, fire up Blender, build the skyscrapers, houses etc., place the camera at the angle you need to get the perspective you want and take a picture (render the scene). You can make your buildings as complicated or as simple as you want. If it's for a presentation, you can go professional polish all the way. You can make your buildings of futuristic metal, plastic or alien goo, in any color you want. Or you can just pop some cubes on a plane. There is no limit to what you can do in Blender. And the best thing is that Blender does all the perspective calculations for you.
But then maybe that is not the end purpose of your need.
putting a tracingpaper over a grid allows me to illustrate the houses first try, there aint no faster way.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.