・ 点が基準線分上にあるかどうか判定

2次元での判定

数学的には、(X1,Y1) (X2,Y2) (X3,Y3) の3点が同一線上にある場合
Y1 (X2 - X3) + Y2 (X3 - X1) + Y3 (X1 - X2) = 0
となります

図面上では、ある程度の誤差を許容しなくてはならないので、(equal) の fuzz オプションを適当に設定しましょう。

(defun Jo_online2 ( )
  ;サブルーチン on_line 判定 Online:T / Not Online:nil ;
  (defun Jof_online2 ( pt;調べる点;
		      spt;線分の始点;
		      ept;線分の終点;
		      / fuzz x1 y1 x2 y2 x3 y3 hantei)
    (setq fuzz 1e-6)
    (setq x1 (car spt))
    (setq y1 (cadr spt))
    (setq x2 (car ept))
    (setq y2 (cadr ept))
    (setq x3 (car pt))
    (setq y3 (cadr pt))
    (setq hantei (+ (* y1 (- x2 x3)) (* y2 (- x3 x1)) (* y3 (- x1 x2))))
    (if (equal 0 hantei fuzz) T nil)
    )

  ;メインルーチン:
  (setq ent (entsel "\n基準線を選択:"))
  (setq pt (getpoint "調査する点を指示:"))
  (if (and
	(setq ed (entget (car ent)))
	(= (cdr (assoc 0 ed)) "LINE")
	(setq spt (cdr (assoc 10 ed)))
	(setq ept (cdr (assoc 11 ed)))
	)
    (if (Jof_online2 pt spt ept)
      (princ "\nOnline")
      (princ "\nNot Online")
      )
    )
  (princ)
  )
  

次元での判定

基準線の始点→終点のベクトルをZ軸とする座標系において、始点→調査点のベクトルのX・Y成分が0ならば線分上(延長線上を含む)にあると判断できる。
また、始点→調査点のベクトルのZ成分が基準線の長さの範囲内にあれば、延長線を含まない線分上にあるとはんていできる。
(equal) の fuzz オプションについては、2次元同様に適当に設定します。

(defun Jo_online3 ()
  ;サブルーチン(点が線分上に有るかどうか判定       返り値  online:T / not online:nil  ;
  (defun Jof_online3 (
			ptc ;調べる点;
			pts ;線分の始点;
			pte ;線分の終点;
			mode; nil:延長線上はnot online / T:延長線上はonline として判定;
			/ dis v_se vu_se v_cs v_cs cs_x cs_y cs_z fuz ret)
    (setq dis (distance pts pte))
    (setq v_se (mapcar '- pte pts))
    (setq vu_se (mapcar '/ v_se (list dis dis dis)))
    (setq v_cs (mapcar '- ptc pts))
    (setq v_cs (trans v_cs 0 vu_se))
    (mapcar 'set '(cs_x cs_y cs_z) v_cs)
    (setq fuz 1e-6)
    (cond      
      ((not mode)(setq ret (and
			       (and (equal cs_x 0 fuz) (equal cs_y 0 fuz))
			       (and (< (- 0 fuz) cs_z) (< cs_z (+ dis fuz)))
			       )))
      (t (setq ret (and (equal cs_x 0 fuz) (equal cs_y 0 fuz))))
      )
    ret
    )
  
  (setq ed (entget (car (entsel "\n線分を選択:"))))
  (setq p0 (cdr (assoc 10 ed)))
  (setq p1 (cdr (assoc 11 ed)))
  (setq pt (getpoint "\n検査点を指示"))
  (if (Jof_online3 pt p0 p1 nil)
    (princ "\nOnline")
    (princ "\nNot Online")
    )
  (princ)
  )

参考文献:「おぉとりすぷの広場」 記事番号<18625> 
参考文献:「mapcar教授の部屋」 記事番号<34>
参考文献:落合重紀 著「AutoLISP 徹底活用ガイド」 ISBN 4-88135-713-1