Author Topic: bad argument type: 2D/3D point: nil  (Read 1646 times)

0 Members and 1 Guest are viewing this topic.

Dilan_Veras

  • Mosquito
  • Posts: 2
  • Everything will be fine
bad argument type: 2D/3D point: nil
« on: December 21, 2023, 04:03:11 AM »
Hi all
Help me find a bug in this program, it doesn't work. Gives an error message: bad argument type: 2D/3D point: nil
Code: [Select]
(defun gc:GetVector (p1 p2) (mapcar '- p2 p1))

(defun gc:CrossProduct (v1 v2)
  (list (- (* (cadr v1) (caddr v2)) (* (caddr v1) (cadr v2)))
(- (* (caddr v1) (car v2)) (* (car v1) (caddr v2)))
(- (* (car v1) (cadr v2)) (* (cadr v1) (car v2)))
  )
)

(defun gc:MidPoint (p1 p2)
  (mapcar (function (lambda (x1 x2) (/ (+ x1 x2) 2.))) p1 p2)
)

(defun circleBy3Points (p1 p2 p3 / v1 v2 norm m1 m2 cen)
  (setq v1   (gc:GetVector p1 p2)
v2   (gc:GetVector p2 p3)
norm (gc:CrossProduct v1 v2)
m1   (gc:Midpoint p1 p2)
m2   (gc:Midpoint p2 p3)
cen  (inters m1
     (mapcar '+ m1 (gc:CrossProduct v1 norm))
     m2
     (mapcar '+ m2 (gc:CrossProduct v2 norm))
     nil
     )
  )
  (entmakex
    (list
      (cons 0 "CIRCLE")
      (cons 10 (trans cen 0 norm))
      (cons 40 (distance cen p1))
      (cons 210 norm)
    )
  )
)
(circleBy3Points
(setq p1 (getpoint "\nFirst point: "))
(setq p2 (getpoint "\nSecond point: "))
(setq p3 (getpoint "\nThird point: "))
)

dexus

  • Bull Frog
  • Posts: 208
Re: bad argument type: 2D/3D point: nil
« Reply #1 on: December 21, 2023, 07:05:14 AM »
The function works fine, but there is no error checking.
So in case the input are not valid points, the error is given.
You can call it like this and the error should not appear.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:c3p (/ p1 p2 p3)
  2.   (and
  3.     (setq p1 (getpoint "\nFirst point: "))
  4.     (setq p2 (getpoint "\nSecond point: "))
  5.     (setq p3 (getpoint "\nThird point: "))
  6.     (circleBy3Points p1 p2 p3)
  7.   )
  8.   (princ)
  9. )