Understanding the Angle, Distance, and Polar Functions

Understanding the Angle, Distance, and Polar Functions
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

    Understanding the Angle, Distance, and Polar Functions



    The first line after defun function uses the setvar function to set the osnap system variable to the nearest mode.
    (defun C:BREAK2 (/ pt1 pt2 pt3 pt4 pt0 ang1 dst1)
    (setvar "osmode" 512)
    This ensures that the point the user picks at the next prompt is exactly on the line. It also give the user a visual cue to pick something
    since the osnap cursor appears.
    When setvar is used with the osmode system variable, a numeric code must also be supplied. This code determines the osnap mode to be used.


    Table 6.1 shows a list of the codes and their meaning.
    Code Equivalent Osnap mode 1 Endpoint
    2 Midpoint
    4 Center
    8 Node
    16 Quadrant
    32 Intersection
    64 Insertion
    128 Perpendicular
    256 Tangent
    512 Nearest
    1024 Quick

    Table 6.1: Osmode codes and their meaning
    The next line prompts the user to select an object using the getpoint function:

    (setq pt1 (getpoint "\nSelect object: "))

    Here, the variable pt1 is used to store the first point location for the break. Since the nearest osnap mode is used, the osnap cursor
    appears and the point picked falls exactly on the line (see Figure 6.5).


    Getting a point using the "nearest" osnap mode.
    Next, another prompt asks the user to pick another point:

    (setq pt2 (getpoint pt1 "\nEnter second point: "))

    The variable pt2 is assigned a point location for the other end of the break. The next line:

    (setvar "osmode" 128)

    sets the osnap mode to perpendicular in preparation for the next prompt:

    (Setq pt3 (getpoint pt1 "\nSelect parallel line: "))

    Here, the user is asked to select the line parallel to the first line. The user can pick any point along the parallel line and the
    perpendicular osnap mode ensures that the point picked on the parallel line is "perpendicular" to the first point stored by the variable
    pt1. The perpendicular osnap mode will only work, however, if a point argument is supplied to the Getpoint function. In this case, the
    point pt1 is supplied as a reference from which the perpendicular location is to be found (see figure 6.6). This new point variable pt3
    will be important in calculating the location of the two break points on the parallel line.


    Figure 6.6: Picking the point perpendicular to the first point.

    The next line sets the osnap mode back to "none":

    (Setvar "osmode" 0)
    The next two lines find the angle and distance described by the two point variables pt1 and pt3.
    (setq ang1 (angle pt1 pt3))


    (setq dst1 (distance pt1 pt3))

    You can obtain the angle described by two points using the Angle function. Angles syntax is:
    ( angle [coordinate list][coordinate list] )
    The arguments to angle are always coordinate lists. The lists can either be variables or quoted lists.
    Angle returns a value in radians. You looked at radians briefly in chapter 4. A radian is system to measure angles based on a circle of 1
    unit radius. In such a circle, an angle can be described as a distance along the circle's circumference. You may recall from high school
    geometry that a circle's circumference is equal to 2 times pi times its radius. since the hypothetical circle has a radius of 1, we drop the
    one from the equation.
    circumference = 2pi
    90 degrees is equal to one quarter the circumference of the circle or pi/2 radians or 1.5708 (see figure 6.7). 180 degrees is equal to half
    the circumference of a circle or 1 pi radians or 3.14159. 360 degrees is equal the full circumference of the circle or to 2 pi radians or
    6.28319.

    A simple formula to convert degrees to radians is:

    radians * 57.2958

    To convert degrees to radians the formula is:
    degrees * 0.0174533
    Angle uses the current UCS orientation as its basis for determining angles. Though you can supply 3 dimensional point values to angle,
    the angle returned is based on a 2 dimensional projection of those points on the current UCS (see figure 6.7). Finally, radians are
    always measured with a counterclockwise directions being positive.


    Figure 6.7: Degrees and radians
    The distance function is similar to angle in that it requires two point lists for arguments:
    (distance [coordinate list][coordinate list])
    The value returned by distance is in drawing units regardless of the current unit style setting. This means that if you have the units set
    to Architectural, distance will return distances in one inch units.
    By storing the angle and distance values between pt1 and pt3, the program can now determine the location of the second break point on
    the parallel line. This is done by applying this angle and distance information to the second break point of the first line using the
    following expression:
    (setq pt4 (polar pt2 ang1 dst1))
    Here the angle variable ang1 and the distance variable dst1 are used as arguments to the polar function to find a point pt4. Polar returns
    a point value (see figure 6.8).


    Figure 6.8: Using the polar function to find a new point.
    The syntax for polar is:
    (polar [point value][angle in radians][distance])
    Polar is used to find relative point locations. It requires a point value as its first argument followed by an angle and distance value. The
    new point value is calculated by applying the angle and distance to the point value supplied. This is similar to describing a relative
    location in AutoCAD using the at sign. For example, to describe a relative location of .25 units at 90 degrees from the last point entered
    you would enter the following in AutoCAD:
    @.25<90
    The same relative location would look like the following using the polar function:
    (setq pt1 (getvar "lastpoint"))
    (polar pt1 1.5708 .25)
    The first expression in this example uses the getvar function to obtain the last point selected. Setq then assigns that point to the variable
    pt1. Polar is used in the next line to find a point that is 1.5708 radians (45 degrees) and 2 units away from the lastpoint.
    The last several lines of the Break2 program use all the point variables to first break the two lines then draw the joining lines between
    them.
    (command
    "break" pt1 pt2
    "break" pt3 pt4
    "line" pt1 pt3 ""
    "line" pt2 pt4 ""
    )
    )
    In the Break2 program, you could have used the getdist and getangle functions but to do so would mean including an additional
    prompt. By using the combination of the perpend osnap mode along with the getpoint function, you establishes a point value from


    which both the angle and distance value is derived. In general, if you know that you will need to gather both distance and angle
    information, it is better to establish coordinate variables first then derive angles and distances from those coordinates using the distance
    and angle functions.

    Next -> Using Trigonometry to Solve a Problem