I am working on this routine to draw perpendicular along a polyline. This routine will be creating some 3d geometry based on a couple of 3D pick points. The problem I haven't figured out just yet is how do I calculate the perpendicular angle at a specified distance along the polyline.

I have attached the code that will place a POINT entity at the selected places. The inserted point will be replaced with some code to draw the necessary 3d geometry. I already have the 3d geometry code written. I just need to calculate the perpendicular angle of the polyline. The polyline will most likely contain some kind of arc and possible more than one arc and a tangent.

(defun C:TEST ()
  (setq	ENTITY	    (entget (car (entsel "\nSelect alignment: ")))
	VLAX-ENTITY (vlax-ename->vla-object (cdr (assoc -1 ENTITY)))
	VLAX-LENGTH (if	(vlax-property-available-p VLAX-ENTITY 'length)
		      (vlax-get-property VLAX-ENTITY 'length)
  (setq OSM (getvar "osmode"))
      (setq INCREMENT (fix (/ VLAX-LENGTH 3.0)) ;_ Arbetrary length of 3.0 for testing.
      (setvar "osmode" 0)
      (repeat (- (fix (/ VLAX-LENGTH 3.0)) 1)
	(setq TempPoint (vlax-curve-getpointatdist VLAX-ENTITY VLAX-LENGTH))
	(command "_.point" TempPoint)
						  ; This is the place in the code I need to calculate
						  ; the perpendicular angle of the polyline.  As you can
						  ; see this angle will change based on where along the
						  ; polyline the point is located.
  (vlax-release-object VLAX-ENTITY)
  (setvar "osmode" OSM)