HNC CAD: Computer Graphics - 2D CAD Concepts - Introduction - Lines and Polylines

Lines and Polylines

The Straight Line

Definition
    Line
    A line is generally taken to be a straight line between two points, it consists of
    • A start coordinate pair (node)
    • An end coordinate pair (node)
    These two nodes (reference points) are used by the programmer to calculate information about the line itself. For Example: from these two nodes, the programmer could calculate the length of the line and the angle of the line.

    A line that has changes in direction may consist of, say, 3 separate lines OR may be one continuous line.

    3 lines
    The 3 lines in the middle of the diagram only look continuous but are in fact 3 separate lines and will have the following information stored.
    • A start coordinate + An end coordinate
    • A start coordinate + An end coordinate
    • A start coordinate + An end coordinate
    They are separate lines and are treated as separate lines.

    Polyline
    The polyline on the right of the diagram is made up of 3 segments that are continuous, and is generally known as a Polyline. This line has the following information.
    • A start coordinate
    • An intermediate coordinate
    • An intermediate coordinate
    • An end coordinate
    The 3 lines making up the polyline are treated in every way as if they were one continuous line.

    Example
    If you wanted to write your own CAD program. As part of the enormous amount of work you would have ahead of you, you would have to decide on the structure of the information your program would hold about the elements that go to make up a drawing. Every CAD program has a structure for the data they hold. It always differs to a competitors product and so we can never just open up, for example, an AutoCAD drawing in a MiniCAD program (unless they have special translator programs).
    We will make up our own structure to hold the drawing details given below.
    On a piece of paper draw a 99x99 unit BOX made up of separate straight lines. The structure of the data could be as follows
      LINE coords 0 0 99 0
      LINE coords 99 0 99 99
      LINE coords 99 99 0 99
      LINE coords 0 99 0 0
    Notice that each line making up the square is stored as a separate object and must contain a complete description.

    The same box could be drawn using a polyline.
      POLYLINE coords 0 0 99 0 99 99 0 99 0 0
    Notice that this description is much smaller.
CAD programs produce quick ways of drawing regular, well defined shapes like rectangles, triangles, etc. After all, they are only connected multiple lines and the most efficient way of storing them is in the form of a polyline.
So even though you may select an option to draw a hexagon, the six connected lines are stored as a single polyline sequence. When you interrogate the CAD drawing database of information there are no references to hexagons or rectangles only lines and polylines!
A rectangle only needs a diagonally opposite corner to be specified to enable the program to work out the length and height.

Exercises

Exercise 1 - Draw a line
Remember, positioning is important. Before placing the first end of the line, decide how you intend to place it (by eye, absolute, relative, etc).
  1. Select [Draw, Line]
  2. Click any where on the screen to fix the first node.
  3. Move the cursor to another place and click to fix the second node
  4. Click the right mouse button or press enter to finish the line command
You have now drawn the first element. The computer obtained the X and Y co-ordinates by storing the position of the mouse when you clicked the button to fix the point. With this method the actual values will have no relevance to you.
Exercise 2 - Draw a box of connected lines 99x99
  1. Select [Draw, Line]
  2. Put 0,0 in the command line to position the first lower corner and press enter(these are ABSOLUTE X and Y values)
  3. Put 99,0 in the command line to position the end of the first line and press enter (still ABSOLUTE X and Y values)
  4. Continue until you close the box.
In AutoCAD this action is a bit of a cheat. You have effectivly entered 4 single lines so you should have entered a start and end set of coordinates for EACH line. But AutoCAD remembered the previous coordinate for you and because you didn't end the command it assumed (correctly), that you were goint to start the second line at the same point at which the first line ended. This saved you having to call the line command 4 times and allowed you to enter only 5 sets of coordinates instead of 8 sets.

The process is exactly as if you were going to draw a Polyline.

Leaving the box on the screen
Exercise 3 - Draw another of the boxes but use a polyline and some relative co-ordinates this time.
  1. Select [Draw, Polyline]
  2. Start the second box at 100,0 by using the X,Y values
  3. Use relative DX,DY values with @ to shape the box
The two boxes look identical, but they are very different.
Experiment with them. Try clicking on them. Try deleting them. Make a note of your findings.

To change a line to a polyline
  1. Select [Modify, Object, Polyline]
  2. The command line reads {_pedit Select polyline}. Click on one of the lines to change to a polyline.
  3. The command line reads {Do you want to change it into one? Y}. enter y
  4. Just press enter. Don't make any selections.
  5. The line is now a polyline.
To join a number of line segments into one polyline
  1. Do the same as above but:-
  2. After you say 'y' to change to a polyline select 'j' to join line segments into one polyline.
  3. Click each line segment you want to join as one polyline.
Change the width of a polyline


You can change the width or weight of a polyline to enhance its appearance.
Notice the heavy and light line widths.
Notice the corners of the multi-segment polyline to the left and the two separate polylines in the middle and to the right.
To change the width:
  1. Select [Modify, Object, Polyline]
  2. Select polyline
  3. Select width 'w' press enter
  4. Enter the width value