home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
BuildingFinder
/
Lisp
/
correct_angle.backup
next >
Wrap
Lisp/Scheme
|
1995-06-07
|
4KB
|
104 lines
(in-package 'cme)
(defun lenvec-2d (vec)
(sqrt (+ (* (car vec) (car vec))
(* (cadr vec) (cadr vec)))))
(defun cos-angle-2d (vec1 vec2)
(/ (+ (* (car vec1) (car vec2))
(* (cadr vec1) (cadr vec2)))
(lenvec-2d vec1)
(lenvec-2d vec2)))
(defun backproj-aux (proj u v &optional (z 0.0))
(project-to-world
proj
(coerce u 'double-float)
(coerce v 'double-float)
(coerce z 'double-float)))
(defun make-vec-2d (x1 y1 x2 y2)
(list (- x2 x1) (- y2 y1)))
(defun farthest-point (basex basey ax ay bx by)
(if (< (lenvec-2d (make-vec-2d basex basey ax ay))
(lenvec-2d (make-vec-2d basex basey bx by)))
(list bx by)
(list ax ay)))
(defvar *return-struct2* (lci::make-double_2))
(defun fill-double2-struct (struct x y)
(setf (lci::double_2-d1 struct) (coerce x 'double-float))
(setf (lci::double_2-d2 struct) (coerce y 'double-float))
struct)
(defun is-corner-p (proj u1 v1 vertu vertv u2 v2 angle a2 b2)
(let* ((lsinangle (lenvec-2d (make-vec-2d vertu vertv u2 v2)))
(lcosangle (* lsinangle (tan angle)))
(du (* lcosangle a2))
(dv (* lcosangle b2))
(minu2 (- u2 du))
(minv2 (- v2 dv))
(maxu2 (+ u2 du))
(maxv2 (+ v2 dv)))
#| (format t "angle is ~d~%" angle)
(format t "lsinang, lcosang are ~d, ~d~%" lsinangle lcosangle)
(format t "vertu,v is ~a~%" (list vertu vertv))
(format t "u1,v1 is ~a~%" (list u1 v1))
(format t "minu2,v2 is ~a~%" (list minu2 minv2))
(format t "maxu2,v2 is ~a~%" (list maxu2 maxv2)) |#
(multiple-value-bind (vx vy) (backproj-aux proj vertu vertv)
(if (null vx)
(fill-double2-struct *return-struct2* -1.0 -1.0)
(multiple-value-bind (x1 y1) (backproj-aux proj u1 v1)
(multiple-value-bind (minx2 miny2) (backproj-aux proj minu2 minv2)
(multiple-value-bind (maxx2 maxy2) (backproj-aux proj maxu2 maxv2)
(let* ((basevec (make-vec-2d vx vy x1 y1))
(minvec (make-vec-2d vx vy minx2 miny2))
(maxvec (make-vec-2d vx vy maxx2 maxy2))
(cosangle1 (cos-angle-2d basevec minvec))
(cosangle2 (cos-angle-2d basevec maxvec)))
#| (format t "basevec is ~a~%" basevec)
(format t "minvec is ~a~%" minvec)
(format t "maxvec is ~a~%" maxvec)
(format t "angle1, angle2 is ~d, ~d~%" (acos cosangle1) (acos cosangle2))
(format t "cos angle test is ~d < 0 < ~d~%" (min cosangle1 cosangle2)
(max cosangle1 cosangle2)) |#
(if (plusp (* cosangle1 cosangle2))
(fill-double2-struct *return-struct2* -1.0 -1.0)
(fill-double2-struct *return-struct2* vertu vertv))))))))))
(defun form-line-vector (u1 v1 u2 v2)
(let ((a (- v1 v2))
(b (- u2 u1))
(c (- (* u1 v2) (* u2 v1))))
(let ((scale (sqrt (+ (* a a) (* b b)))))
(values (/ a scale) (/ b scale) (/ c scale)))))
(defun line-intersect-point (a1 b1 c1 a2 b2 c2)
(let ((p (- (* b1 c2) (* b2 c1)))
(q (- (* c1 a2) (* c2 a1)))
(r (- (* a1 b2) (* a2 b1))))
(unless (= r 0)
(values (/ p r) (/ q r)))))
(defun lines-form-corner-p (proj au1 av1 au2 av2 bu1 bv1 bu2 bv2 angthreshold)
(multiple-value-bind (a1 b1 c1) (form-line-vector au1 av1 au2 av2)
(multiple-value-bind (a2 b2 c2) (form-line-vector bu1 bv1 bu2 bv2)
(multiple-value-bind (u v) (line-intersect-point a1 b1 c1 a2 b2 c2)
(if u
(let ((farapt (farthest-point u v au1 av1 au2 av2))
(farbpt (farthest-point u v bu1 bv1 bu2 bv2)))
(is-corner-p proj
(car farapt) (cadr farapt)
u v
(car farbpt) (cadr farbpt)
angthreshold a2 b2))
(fill-double2-struct *return-struct2* -1.0 -1.0))))))