Creating a Reusable Function

First, create the reusable function. In this tutorial, you are going to create a function that checks if the three points are aligned.

Click Play to watch the video:

  1. In the Know-how Libraries section, click Create Know-how Library .
    The Know-how Library dialog box opens.
  2. Enter a Title and click OK.
  3. In the Know-how Libraries section, click Create Know-how Function .
    The Create Library Function dialog box opens.
  4. Enter the function name and click OK.
    The function appears under the library that it is linked to below the know-how libraries in the tree.
  5. Double-click the function in the tree.
    The EKL Function Editor appears.
  6. Declare the function arguments.
  7. Enter your script.
    1. Declare the variables.
      let l1,l2(Line)
      let d1,d2(Direction)
      let v1,v2(Vector)
      let scalProd(Real)
      let prdVect(Vector)
    2. Build the lines from these points.
      l1 = line(iPt1,iPt2)
      l2 = line(iPt1,iPt3)
    3. Compute the direction from the lines.
      d1 = direction(l1)
      d2 = direction(l2)
    4. Turn the direction into mathematical vectors.
      v1 = d1->Vector()
      v2 = d2->Vector()
    5. Create a cross product on the vectors.
      prdVect = CrossProduct(v1,v2)
      if prdVect == [ 0, 0, 0 ]
                      ToReturn = TRUE
      else
                      ToReturn = FALSE
      
      Note: If the cross product result is the null vector, the points are aligned. The ToReturn variable is used to store the returned value of the function.