Author Topic: Geometrical question: closest orthogonal point  (Read 6658 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Geometrical question: closest orthogonal point
« Reply #15 on: March 23, 2020, 04:04:38 PM »
Which points should be returned for a scenario in which each given point lies equidistant within each quadrant? e.g.:


Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Geometrical question: closest orthogonal point
« Reply #16 on: March 23, 2020, 04:45:33 PM »
If I understand, this should be what you are looking for.  It will return a list of the quadrant angles.

Code - Lisp: [Select]
  1. ....
  2.  
I have tried your version, can you tell me in which situations does it return a different result?
Thanks.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Geometrical question: closest orthogonal point
« Reply #17 on: March 23, 2020, 04:53:03 PM »
Which points should be returned for a scenario in which each given point lies equidistant within each quadrant? e.g.:


Which points should be returned for a scenario in which each given point lies equidistant within each quadrant? e.g.:


The points returned have no valid logic, they mainly depend on how this is written:

Code: [Select]
  (cond
    ( (and (>= Ang003      0) (>= Deg090 Ang003)) (cons 0      Deg090) )
    ( (and (>= Ang003 Deg090) (>= pi     Ang003)) (cons Deg090     pi) )
    ( (and (>= Ang003     pi) (>= Deg270 Ang003)) (cons pi     Deg270) )
    ( T                                           (cons Deg270      0) )
  )

Edit: maybe this is better:
  (cond
    ( (and (> Ang003      0) (>= Deg090 Ang003)) (cons 0      Deg090) )
    ( (and (> Ang003 Deg090) (>= pi     Ang003)) (cons Deg090     pi) )
    ( (and (> Ang003     pi) (>= Deg270 Ang003)) (cons pi     Deg270) )
    ( T                                          (cons Deg270      0) )
  )


In my scenario I don't have this problem but if you have a suggestion I will be happy to adopt it.
Thank you

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Geometrical question: closest orthogonal point
« Reply #18 on: March 23, 2020, 06:14:02 PM »
If I understand, this should be what you are looking for.  It will return a list of the quadrant angles.

Code - Lisp: [Select]
  1. ....
  2.  
I have tried your version, can you tell me in which situations does it return a different result?
Thanks.

Here are returned results (no image)
Quote
Command: (test (getpoint) (getpoint) (getpoint))
(0.0 4.71239)

Command: (test (getpoint) (getpoint) (getpoint))
(4.71239 3.14159)

Command: (test (getpoint) (getpoint) (getpoint))
(0.0 4.71239)

You can see that they return different results for where points are picked.  My code does not allow for the two returned angles to be the same value, so if they were going to be the same value, it returns the other angle associated with that quadrant.

Quote
Command: (test (getpoint) (getpoint) (getpoint))
(3.14159 1.5708)

This is the result for picking the same point in the second (top-left) quadrant.  You get the Pi (180 degrees) and Pi/2 (90 degrees).

Hope that makes sense.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.


T.Willey

  • Needs a day job
  • Posts: 5251
Re: Geometrical question: closest orthogonal point
« Reply #20 on: March 24, 2020, 10:19:47 AM »
Is that not was is desired, Marc?  Did I not understand correctly?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Geometrical question: closest orthogonal point
« Reply #21 on: March 24, 2020, 11:14:43 AM »
Is that not was is desired, Marc?  Did I not understand correctly?
Yes that's what I wanted to achieve. What I don't understand is the difference or advantage of your version which is much more complicated.
Thanks for your patience.  :-)
Edit: Maybe I understood: the correct sequence based on the selected points ... Yes it is a more appropriate result!

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Geometrical question: closest orthogonal point
« Reply #22 on: March 24, 2020, 12:51:52 PM »
I don't think mine is very complicated.  I test to see which quadrant the point lies, then see if it's greater than the 45 degree line of said quadrant and return the appropriate angle.  But for the second angle I make sure that if they are in the same quadrant, you get the second angle of the quadrant so that the same angle is not returned for both.  You're welcome.  This is a place of learning, so asking why one coded it a certain way is fine.  I hope my explanation make sense to you (though it looks like you figured it out before I posted this message).
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Geometrical question: closest orthogonal point
« Reply #23 on: March 24, 2020, 01:19:04 PM »
I don't think mine is very complicated.  I test to see which quadrant the point lies, then see if it's greater than the 45 degree line of said quadrant and return the appropriate angle.  But for the second angle I make sure that if they are in the same quadrant, you get the second angle of the quadrant so that the same angle is not returned for both.  You're welcome.  This is a place of learning, so asking why one coded it a certain way is fine.  I hope my explanation make sense to you (though it looks like you figured it out before I posted this message).
Ok, thanks for the explanation, I have to understand if for my use it is a useful twining. Basically I have to draw an arc in the quadrant where the angle bisector lies (which is always less than 180 degrees).  :-)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Geometrical question: closest orthogonal point
« Reply #24 on: March 24, 2020, 02:57:52 PM »
Assuming I've understood the requirements, here's my suggestion:
Code - Auto/Visual Lisp: [Select]
  1. (defun foo ( c p q / a b d )
  2.     (setq a (angle '(0 0) (mapcar '+ (mapcar '- p c) (mapcar '- q c)))
  3.           b (+ (if (< 0 (sin a)) 0 pi) (if (< 0 (* (sin a) (cos a))) 0 (/ pi 2)))
  4.           d (distance c p)
  5.     )
  6.     (list (polar c b d) (polar c (+ b (/ pi 2)) d))
  7. )

A program to test:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / c p q )
  2.     (if (and (setq c (getpoint "\nCentre: "))
  3.              (setq p (getpoint c "\nP1: "))
  4.              (setq q (getpoint c "\nP2: "))
  5.         )
  6.         (foreach x (foo c p q) (entmake (list '(0 . "POINT") (cons 10 (trans x 1 0)))))
  7.     )
  8.     (princ)
  9. )

Assumes (= (distance c p) (distance c q)) per the images.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Geometrical question: closest orthogonal point
« Reply #25 on: March 24, 2020, 05:32:50 PM »
Assuming I've understood the requirements, here's my suggestion:
Code - Auto/Visual Lisp: [Select]
  1. (defun foo ( c p q / a b d )
  2.     (setq a (angle '(0 0) (mapcar '+ (mapcar '- p c) (mapcar '- q c)))
  3.           b (+ (if (< 0 (sin a)) 0 pi) (if (< 0 (* (sin a) (cos a))) 0 (/ pi 2)))
  4.           d (distance c p)
  5.     )
  6.     (list (polar c b d) (polar c (+ b (/ pi 2)) d))
  7. )

A program to test:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / c p q )
  2.     (if (and (setq c (getpoint "\nCentre: "))
  3.              (setq p (getpoint c "\nP1: "))
  4.              (setq q (getpoint c "\nP2: "))
  5.         )
  6.         (foreach x (foo c p q) (entmake (list '(0 . "POINT") (cons 10 (trans x 1 0)))))
  7.     )
  8.     (princ)
  9. )

Assumes (= (distance c p) (distance c q)) per the images.
Thanks Lee, it seem very good for my needs and can be simply:
Code: [Select]
(defun foo2 ( c p q / a b)
    (setq a (angle '(0 0) (mapcar '+ (mapcar '- p c) (mapcar '- q c)))
          b (+ (if (< 0 (sin a)) 0 pi) (if (< 0 (* (sin a) (cos a))) 0 (/ pi 2)))
    )
    (cons b (+ b (/ pi 2)))
)
Grazie.  :-)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Geometrical question: closest orthogonal point
« Reply #26 on: March 24, 2020, 05:40:06 PM »
Alternatively, just -
Code - Auto/Visual Lisp: [Select]
  1. (defun foo3 ( c p q / a )
  2.     (setq a (* (/ pi 2) (fix (/ (angle '(0 0) (mapcar '+ (mapcar '- p c) (mapcar '- q c))) (/ pi 2)))))
  3.     (cons a (+ a (/ pi 2)))
  4. )

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Geometrical question: closest orthogonal point
« Reply #27 on: March 24, 2020, 06:46:24 PM »
Alternatively, just -
Code - Auto/Visual Lisp: [Select]
  1. (defun foo3 ( c p q / a )
  2.     (setq a (* (/ pi 2) (fix (/ (angle '(0 0) (mapcar '+ (mapcar '- p c) (mapcar '- q c))) (/ pi 2)))))
  3.     (cons a (+ a (/ pi 2)))
  4. )
More succinct than that I think is not possible!    8-)   Notte.