Author Topic: Pick two points and draw rectangular box  (Read 3865 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Pick two points and draw rectangular box
« on: December 06, 2015, 11:37:27 AM »
Hi guys,

I would like to create the two red lines to be able to create the complete box as in the attached image.

User options to pick the two points (pt1 & pt2) or (pt2 & pt1) then the program to create the two red lines with or without the next two green lines.

Thank you.


Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Pick two points and draw rectangular box
« Reply #1 on: December 06, 2015, 12:38:07 PM »
More information is required - without a constraint on the angle of the rectangle, there is no unique solution:


Coder

  • Swamp Rat
  • Posts: 827
Re: Pick two points and draw rectangular box
« Reply #2 on: December 06, 2015, 12:58:28 PM »
Thanks Lee .

I mean the smallest shape and that represents a wall .

I am attaching the sample .

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Pick two points and draw rectangular box
« Reply #3 on: December 06, 2015, 03:57:48 PM »
I mean the smallest shape and that represents a wall .

But the rectangle could be made zero size if the longest edges are parallel to the given line.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Pick two points and draw rectangular box
« Reply #4 on: December 06, 2015, 06:14:34 PM »
Coder you must decide on a pre set wall thickness or have a user input.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Coder

  • Swamp Rat
  • Posts: 827
Re: Pick two points and draw rectangular box
« Reply #5 on: December 07, 2015, 12:57:27 AM »
I am sorry for the confusion  :oops:

I already have the wall thickness and that is collected as a user input before asking the user to specify the two points and it is 0.2 currently.

many thanks.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Pick two points and draw rectangular box
« Reply #6 on: December 07, 2015, 01:22:38 AM »
Coder,
Do you know how to determine the 2 points ?

and the distance between them ?

and the actual angle of the diagonal line ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Coder

  • Swamp Rat
  • Posts: 827
Re: Pick two points and draw rectangular box
« Reply #7 on: December 07, 2015, 01:30:50 AM »
Hi Kerry.

that is all I know for this task.  :-D

Code: [Select]
(setq pt1 (getpoint "\nPlease pick the first point :"))
(setq pt2 (getpoint "\nPlease pick the second point :" pt1))
(setq len (distance pt1 pt2))
(setq ang (angle pt1 pt2))

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Pick two points and draw rectangular box
« Reply #8 on: December 07, 2015, 01:39:25 AM »
Good,
Can you calculate the sharp angle ? call it ang-a

Sin sharpAngle = a / c
where a  short side and c is the len p1 p2 .


Then calculate the longside (call it b )
b = sqrt ( (c*c )- (a+a))

added:
can we agree on a length for the short side  a ?
Your drawing is 0.2723
« Last Edit: December 07, 2015, 01:45:17 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Pick two points and draw rectangular box
« Reply #9 on: December 07, 2015, 01:56:25 AM »
These may help later

Code - Auto/Visual Lisp: [Select]
  1.  
  2. ;;;  Convert Angles from DEGREES to RADIANS
  3.  
  4. (defun kdub:dtr (ang) (* (/ ang 180.0) pi))
  5.  
  6. ;;; Convert Angles from RADIANS to DEGREES
  7.  
  8. (defun kdub:rtd (ang) (/ (* ang 180.0) pi))
  9.  
  10.  
  11. ;;;
  12. ;;; arccosine (inverse cosine)
  13. ;;; argument in the range -1.0 to 1.0 inclusive
  14. ;;; returns an angle in radians in the range pi to 0 inclusive
  15. ;;;
  16. (defun kdub:acos (num)
  17.   (if (zerop num)
  18.     (* pi 0.5)
  19.     (atan (sqrt (- 1.0 (* num num))) num)
  20.   )
  21. )
  22.  
  23.  
  24. ;;;
  25. ;;; arccosine (inverse cosine)
  26. ;;; argument in the range -1.0 to 1.0 inclusive
  27. ;;; arcsine (inverse sine) accepts an argument in the range
  28. ;;; -1.0 to 1.0 inclusive, and returns an angle in radians in
  29. ;;; the range -pi/2 to pi/2 inclusive.
  30. (defun kdub:asin (num)
  31.   (cond
  32.     ((> (abs num) 1.0)
  33.      (alert (strcat " Arc-sine error in (KDUB:asin ." "\n Spitting the dummy"))
  34.      (exit)
  35.     )
  36.     ((zerop num) 0.0)
  37.     ((= num 1.0) *:rad90)
  38.     ((= num -1.0) (- *:rad90))
  39.     (t (atan num (sqrt (- 1.0 (* num num)))))
  40.   )
  41. )
  42.  
  43.  
« Last Edit: December 07, 2015, 02:00:57 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Coder

  • Swamp Rat
  • Posts: 827
Re: Pick two points and draw rectangular box
« Reply #10 on: December 07, 2015, 02:05:19 AM »
I am weak at maths and due to this I am asking for help in this experts forum.

I couldn't come up with an answer for your questions. sorry

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Pick two points and draw rectangular box
« Reply #11 on: December 07, 2015, 02:15:14 AM »
Can you relate to these ??

Code - Auto/Visual Lisp: [Select]
  1.  
  2. ;; short side
  3. (setq a 0.272270 )
  4.  
  5. (setq pt1 (getpoint) )       ;-> (28.0686 9.16972 0.0)  
  6.  
  7. (setq pt2 (getpoint) )       ;-> (30.7512 12.2374 0.0)
  8.  
  9. ;; diagonal
  10. (setq c (distance pt1 pt2))   ;-> 4.07513
  11.  
  12. ;; angle in World
  13. (setq ang (angle pt1 pt2))    ;-> 0.852261
  14. (kdub:rtd ang )               ;-> 48.8309
  15.  
  16. ;;  longSide
  17. (setq  b (sqrt (- (* c c) (* a a)))) ;=> 4.066024
  18.  
  19. ;; angle opposite side b
  20. (setq ang-b (kdub:acos (/ a c) )) ;-> 1.50393
  21. (kdub:rtd ang-b )                 ;-> 86.1686
  22.  
  23. ;; angle opposite side a
  24. (setq ang-a (kdub:asin (/ a c))) ;-> 0.0668698
  25. (kdub:rtd ang-a )                ;-> 3.83136
  26.  
  27.  

revised: change the length of short side
Do you know how the polar function works ?
« Last Edit: December 07, 2015, 03:26:58 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Pick two points and draw rectangular box
« Reply #12 on: December 07, 2015, 02:28:22 AM »
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (setq pt1a (polar pt1 (+ ang ang-b) a))   ;-> (27.876 9.36225 0.0)
  3. (setq pt2a (polar pt2 (+ ang ang-b) (- a)))  ;-> (30.9437 12.0448 0.0)
  4.  
  5.  

revised: minus dim a

Then do you know how to draw 2 lines ?
from
pt1 to pt1a

from pt2 to pt2a


Note. All the dimensions and angles are taken from your drawing, so they are easily checked.
There is a slight discrepancy because of the actual length of the short side
« Last Edit: December 07, 2015, 03:24:45 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Coder

  • Swamp Rat
  • Posts: 827
Re: Pick two points and draw rectangular box
« Reply #13 on: December 07, 2015, 02:43:23 AM »
Thank you Kerry for all of this inputs.

I think pt2a is not accurate and its angle is not 90 degree. can you please have a look?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Pick two points and draw rectangular box
« Reply #14 on: December 07, 2015, 03:27:49 AM »
Points adjusted in previous post.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.