How to Find Angles and Distances

How to Find Angles and Distances
Site menu


Login form


Search


Site friends
  • Create your own site


  • Statistics

    Total online: 1
    Guests: 1
    Users: 0


    Welcome, Guest ยท RSS 16 September 2024
    How to find Angles and Distances


    In chapter 6, you learned how to prompt the user for angles and distances. At time, however, you will want to find angles and distances
    based on the location of existing point variables rather than relying on user input every time you need to find an angle.
    Suppose you want to find a way to break two parallel lines between two points in a manner similar to the standard AutoCAD break command. In addition, you would like this function to join the ends of the two broken portions of each line to form an opening. Figure 6.1 shows a drawing of the process along with a description of what must occur. This drawing can be developed into pseudocode for your program. A function similar to this is commonly used in architectural drawings to place an opening in a wall.

    Figure 6.1: Sketch of the parallel line break program
    In Chapter 3, we discussed the importance of designing your program to be simple to use. This program is designed to obtain the
    information needed to perform its task using the minimum of user input. Since it is similar to the break command, it also tries to mimic
    the break program to some degree so the user feels comfortable with it. As you read through this section, pay special attention to the
    way information is gathered and used to accomplish the final result.
    Open an AutoLISP file called Break2.lsp and copy the program in figure 6.2. Open a new AutoCAD file called Chapt6. Draw a line
    from point 2,4 to 12,4 then offset that line a distance of 0.25 units. Your screen should look like figure 6.3.


    ;Program to break 2 parallel lines -- Break2.lsp
    (defun c:break2 (/ pt1 pt2 pt3 pt4 pt0 ang1 dst1)
    (setvar "osmode" 512) ;near osnap mode
    (setq pt1 (getpoint "\nSelect object: ")) ;get first break point
    (setq pt2 (getpoint pt1 "\nEnter second point: ")) ;get second break point
    (setvar "osmode" 128) ;perpend osnap mode
    (Setq pt3 (getpoint pt1 "\nSelect parallel line: "));get 2nd line
    (Setvar "osmode" 0) ;no osnap mode
    (setq ang1 (angle pt1 pt3)) ;find angle btwn lines
    (setq dst1 (distance pt1 pt3)) ;find dist. btwn lines
    (setq pt4 (polar pt2 ang1 dst1)) ;derive pt4 on 2nd line
    (command
    "break" pt1 pt2 ;break 1st line
    "break" pt3 pt4 ;break 2nd line
    "line" pt1 pt3 "" ;close ends of lines
    "line" pt2 pt4 ""
    )
    )
    The parallel line break program


    Figure 6.3: Two parallel lines drawn
    1. Load the Break2.lsp file and enter break2 at the Command prompt.
    2. At the prompt:
    Select object:
    The osnap cursor appears. Pick the lowermost line near coordinate 5,4.
    3. At the next prompt:
    Enter second point:
    Pick the lowermost line again near coordinate 10,4.
    4. Finally, at the prompt:
    Select parallel line:
    pick the upper line near its midpoint. The two line break and are joined at their break points to form an opening (see figure 6.4)


    Figure 6.4: The lines after using Break2
    Now draw several parallel lines at different orientations and try the Break2 program on each pair of lines. Break2 places an opening in
    a pair of parallel lines regardless of their orientation. Let's look at how break2 accomplishes this.

    Next -> Understanding the Angle, Distance, and Polar Functions