Author Topic: [Solved] MID of a given arc  (Read 10760 times)

0 Members and 1 Guest are viewing this topic.

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: [Solved] MID of a given arc
« Reply #15 on: February 19, 2014, 07:53:37 AM »
...I think Peter wants a solution that is purely mathematical , not object/entity based....
Yes, this was my original target. But in the meantime I see that the "cost/efficiency ratio" of the pure mathematical solution is very bad; I hoped it could be a "two liner".

But it is not, and I'm very happy with the entity-based solution you showed me. So I don't want to waste your time any longer, for me it is solved.

(But if somebody has a solution and wants to share it - it would be appreciated)
Ok. This is the mathematical solution in WCS, assuming valid points. Return mid point of arc drawn in trigonometric direction.
It can be adapted for points contained in current UCS, but not for an arbitrary 3D rotation of plane defined by these 3points, relative to current UCS.
Code - Auto/Visual Lisp: [Select]
  1. ;ps - strat point
  2. ;pf - end point
  3. ;pc - center point
  4. (defun mid_3p_arc (ps pf pc / r s f a pm)
  5.   (if
  6.     (equal (setq r (distance pc ps)) (distance pc pf) 1e-8)
  7.     (setq s (angle pc ps)
  8.           f (angle pc pf)
  9.           a (-                          
  10.               (/ (+ s f) 2.0)
  11.               (if (> s f) pi 0)        
  12.             )
  13.           pm (mapcar '+ pc (list (* r (cos a)) (* r (sin a)) 0))
  14.           )
  15.     )
  16.   )

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: [Solved] MID of a given arc
« Reply #16 on: February 19, 2014, 06:47:34 PM »
Here is my version:
Code - Auto/Visual Lisp: [Select]
  1. (defun amid ( c s e / v x )
  2.     (setq v (mapcar '- e s)
  3.           x (trans c 0 v)
  4.     )
  5.     (trans (cons (- (car x) (distance c s)) (cdr x)) v 0)
  6. )
c = WCS center point
s = WCS start point
e = WCS end point


Compatible with WCS points in planes parallel to WCS plane.

Q1241274614

  • Guest
Re: [Solved] MID of a given arc
« Reply #17 on: February 19, 2014, 07:30:25 PM »
Arc a few points?
(defun 3p-arc-nlst (pc ps pf n / r s f a pm lst i)
    (setq s (angle pc ps) i 0 r (distance pc ps)
     b (/ (rem (+ pi pi (- (angle p2 p1) (angle p2 p3))) (+ pi pi)) n)
     )
   (repeat (- n 1) (setq lst (cons (+ s (* b (setq i (1+ i)))) lst)))
        (mapcar'(lambda (x) (polar pc x r))lst)
)
« Last Edit: February 19, 2014, 10:08:11 PM by Q1241274614 »

Peter2

  • Swamp Rat
  • Posts: 653
Re: [Solved] MID of a given arc
« Reply #18 on: February 20, 2014, 05:51:58 AM »
Thanks guys

now we (no: you!) reached the "mathematical two line solution" I mentioned above.

Peter
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Peter2

  • Swamp Rat
  • Posts: 653
Re: [Solved] MID of a given arc
« Reply #19 on: February 20, 2014, 06:20:36 AM »
...Compatible with WCS points in planes parallel to WCS plane.
And based on an arc which turns counter-clockwise. And now I see (sorry again, the last days were a little bit stressing) that my first posting was not precise as it should be ...

The starting position of the problem was:

- there are three given points A, B, C
-> I can create an arc from A - B - C
-> A is startpoint, B is somewhere on the arc, C is endpoint
- The solution should be mathematical, not using entities.

Question A (can be answered with the existing 3P-Arc functions)
- How to calculate centre and radius?

Question B:
- How to find if the arc turns left or right (clockwise or counter-clockwise)?
- How to find the included angle?
- How to find the middle of the arc?

Please consider:
- For me, I find the solution based on entities above.
- Any further solution are interesting and maybe can be helpful in other cases, but are additional work and not necessary at the moment.
- If someone wants to find a solution for this, he (or she or me) should start a new thread where the question is newly defined.

Thanks a lot!
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: [Solved] MID of a given arc
« Reply #20 on: February 20, 2014, 03:29:45 PM »
...Compatible with WCS points in planes parallel to WCS plane.
And based on an arc which turns counter-clockwise.

Yes - given only a start point, end point & center, one must have a convention for arc direction, otherwise the question is ambiguous. AutoCAD's convention is counter-clockwise, which I followed with my function.


snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: [Solved] MID of a given arc
« Reply #21 on: February 20, 2014, 06:40:46 PM »
Peter2,

If you require a mathematical solution only, then why are you looking for an answer on a AutoLISP based forum ?

One of the many benefits of AutoLISP is the ability to utilize entities etc. as part of the solution to problems, these benefits where met with great skepticism when civil/survey software really started to take advantage of this in the late 80's.   Many worried the accuracy would be lost, when in reality the exact opposite happened.

There are plenty of mathematical / engineering websites that could possibly provide either an answer or assistance.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: [Solved] MID of a given arc
« Reply #22 on: February 21, 2014, 12:51:07 AM »
snownut2,
I can imagine cases where the mathematics is required and the entitys don't exist.
I'm sure if you put your mind to it you could also envision this requirement.





« Last Edit: February 21, 2014, 01:09:02 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.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: [Solved] MID of a given arc
« Reply #23 on: February 21, 2014, 12:54:57 AM »
One of the many benefits of AutoLISP is the ability to utilize entities etc. as part of the solution to problems, these benefits where met with great skepticism when civil/survey software really started to take advantage of this in the late 80's.   Many worried the accuracy would be lost, when in reality the exact opposite happened.
And by doing so you are actually using ACad as if it's a Math library where someone's already written all the needed calculation functions for you. It's nothing dissimilar from someone using the Math library in DotNet to calculate stuff like GCD instead of rolling their own function(s).

You'll learn in all programming (no matter what language) the trend is to try and find re-usable code first, and preferably a tried and proven library. Chances are you'd need to be a seriously awesome programmer to get even close to most of those performance / accuracy. "Re-inventing the wheel" is mostly frowned upon when in production, because it takes a whole lot longer and (9 times out of 10) means the code is worse than simply using an existing Lib.

That's definitely not to discourage anyone from trying. These libs were created by people who tried to make something better than existed. So if it wasn't for people "re-inventing the wheel" we'd not have libs with high performance and rock-solid quality.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: [Solved] MID of a given arc
« Reply #24 on: February 21, 2014, 12:58:23 AM »
Peter2,
I have a recollection that you posted some piccy's with your first post.

It seems to me that you may have changed the nature of the query (in your first post) during the life of this thread.

In future , please don't change the content of the original post in any significant manner because it makes following the thread very difficult for anyone attempting to follow along later.
Asking supplementary questions is fine if they are noted as such.

added:
The piccys comprised points A B C on an anc with A and C being the Start and End and B being located on the arc to define construction points for a 3 point arc.
With these pictures removed and the associated description deleted it makes posts like my Reply #10 orphaned and seemingly unrelated to the topic ... which is confusing.

It is also a waste of the time of anyone who is attempting to help you.
« Last Edit: February 21, 2014, 01:09:18 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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: [Solved] MID of a given arc
« Reply #25 on: February 22, 2014, 11:25:19 AM »
In future , please don't change the content of the original post in any significant manner because it makes following the thread very difficult for anyone attempting to follow along later.

<...>

It is also a waste of the time of anyone who is attempting to help you.

Agreed - I thought we were answering this:

I have an arc, given with startpoint, endpoint, radius and centre <...> I have no idea how to calculate the MID of the arc

Q1241274614

  • Guest
Re: [Solved] MID of a given arc
« Reply #26 on: February 22, 2014, 11:57:11 AM »

Change the topic:


Known:
the center of the circle of C,     (setq c  (getpoint))
                       Startpoint S,     (setq s  (getpoint))
                         Endpoint E,     (setq e  (getpoint))
                    Side length L1,     (setq L1 40)
                    Side length L2,     (< 10  L2  20)
                  Hole spacing L3,    Only select (list 80 75 70 65 60)

Problem: the minimum number of holes.

chlh_jd

  • Guest
Re: [Solved] MID of a given arc
« Reply #27 on: February 22, 2014, 11:46:58 PM »
Nice code Lee ! :-)
Time to continue , now just post pic.
And Stefan's also good .
To get 3P-ARC midpoint , I write some one method , but too long . I hope it can be simplified .
Code: [Select]
;; For 3D ARC
(defun defl  (a b c / d)
 ;_Get 3 point inter angle
 ;_by Ymg
  (abs (- (setq d (- (angle b a) (angle b c)))
  (* (fix (/ d pi)) (+ pi pi)))))
;; Product
(defun v^v  (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)))))
;; Unit
(defun v2u  (v / d)
  (setq d (sqrt (apply (function +) (mapcar (function *) v v))))
  (if (/= d 0)
    (mapcar (function (lambda (x) (/ x d))) v)))
;;
(defun amid  (a b c / n s d e f p)
  ;; a -- the Start Point of Arc in WCS
  ;; b -- the point on Arc in WCS
  ;; c -- the End Point of Arc in WCS
  (setq n (v2u (v^v (mapcar '- b a) (mapcar '- c a)))
a (trans a 0 n)
b (trans b 0 n)
c (trans c 0 n));_trans wcs points into ocs
  ;; main routine
  (setq s (car
    (trans (mapcar (function -) b c) 0 (mapcar (function -) a c))) ;_check B side of AC
s (/ s (abs s)) ;_sign
d (defl C A B) ;_ang α
e (defl A C B) ;_ang β
f (/ (+ d e) 2.) ;_ang γ
d (- (angle a c) (* s f)) ;_new direction of AM
e (+ (angle c a) (* s f)) ;_new direction of CM
)
  (setq p (inters a
  (mapcar '+ a (list (cos d) (sin d)))
  c
  (mapcar '+ c (list (cos e) (sin e)))
  nil)) ;_intersect with v1 v2 based on A C 
  (trans p n 0);_trans result
  )
;; For test in WCS
(defun c:test  (/ a b c m)
  (if (and
(setq a (getpoint "\nSelect Start Point of Arc :"))
(setq b
       (getpoint
a
"\nSelect One Point on the Arc (Not Start or End Point) :"))
(setq c (getpoint b "Select End Point of Arc :"))
(not (vl-some 'equal (list a b c) (list b c a))))
    (progn
      (setq m (amid a b c))
      (entmake (list (cons 0 "LINE")
     (cons 10 a)
     (cons 11 m)))
      )
    )
  (princ)
  )
« Last Edit: February 23, 2014, 08:32:28 AM by chlh_jd »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: [Solved] MID of a given arc
« Reply #28 on: February 23, 2014, 10:28:59 AM »
Nice code Lee ! :-)

Thanks!  :-)

To get 3P-ARC midpoint , I write some one method , but too long . I hope it can be simplified .

Here is my version:
Code - Auto/Visual Lisp: [Select]
  1. (defun 3p-arc-mid ( p1 p2 p3 / m1 m2 m3 v1 v2 v3 )
  2.     (setq v1 (mapcar '- p2 p1)
  3.           v2 (mapcar '- p3 p2)
  4.           v3 (mapcar '- p3 p1)
  5.           m1 (mapcar '+ (trans p1 0 v1) (list 0 0 (/ (distance p1 p2) 2.0)))
  6.           m2 (mapcar '+ (trans p2 0 v2) (list 0 0 (/ (distance p2 p3) 2.0)))
  7.           m3 (inters
  8.                  (trans m1 v1 1)
  9.                  (trans (mapcar '+ m1 '(1 0 0)) v1 1)
  10.                  (trans m2 v2 1)
  11.                  (trans (mapcar '+ m2 '(1 0 0)) v2 1)
  12.                  nil
  13.              )
  14.     )
  15.     (if m3
  16.         (trans
  17.             (cons
  18.                 (   (if (minusp (car (mapcar '- (trans p2 0 v3) (trans p1 0 v3)))) - +)
  19.                     (car (trans m3 1 v3))
  20.                     (distance (trans m3 1 0) p1)
  21.                 )
  22.                 (cdr (trans m3 1 v3))
  23.             )
  24.             v3 0
  25.         )
  26.     )
  27. )

To test:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / p1 p2 p3 p4 )
  2.     (if (and (setq p1 (getpoint "\nPoint 1: "))
  3.              (setq p2 (getpoint "\nPoint 2: "))
  4.              (setq p3 (getpoint "\nPoint 3: "))
  5.         )
  6.         (if (setq p4 (3p-arc-mid (trans p1 1 0) (trans p2 1 0) (trans p3 1 0)))
  7.             (entmake (list '(0 . "POINT") (cons 10 p4)))
  8.             (princ "\nPoints are collinear.")
  9.         )
  10.     )
  11.     (princ)
  12. )

chlh_jd

  • Guest
Re: [Solved] MID of a given arc
« Reply #29 on: February 25, 2014, 12:56:23 AM »
Nice code Lee ! :-)

Thanks!  :-)

To get 3P-ARC midpoint , I write some one method , but too long . I hope it can be simplified .

Here is my version:
Code - Auto/Visual Lisp: [Select]
  1. (defun 3p-arc-mid ( p1 p2 p3 / m1 m2 m3 v1 v2 v3 )
  2.     (setq v1 (mapcar '- p2 p1)
  3.           v2 (mapcar '- p3 p2)
  4.           v3 (mapcar '- p3 p1)
  5.           m1 (mapcar '+ (trans p1 0 v1) (list 0 0 (/ (distance p1 p2) 2.0)))
  6.           m2 (mapcar '+ (trans p2 0 v2) (list 0 0 (/ (distance p2 p3) 2.0)))
  7.           m3 (inters
  8.                  (trans m1 v1 1)
  9.                  (trans (mapcar '+ m1 '(1 0 0)) v1 1)
  10.                  (trans m2 v2 1)
  11.                  (trans (mapcar '+ m2 '(1 0 0)) v2 1)
  12.                  nil
  13.              )
  14.     )
  15.     (if m3
  16.         (trans
  17.             (cons
  18.                 (   (if (minusp (car (mapcar '- (trans p2 0 v3) (trans p1 0 v3)))) - +)
  19.                     (car (trans m3 1 v3))
  20.                     (distance (trans m3 1 0) p1)
  21.                 )
  22.                 (cdr (trans m3 1 v3))
  23.             )
  24.             v3 0
  25.         )
  26.     )
  27. )

To test:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / p1 p2 p3 p4 )
  2.     (if (and (setq p1 (getpoint "\nPoint 1: "))
  3.              (setq p2 (getpoint "\nPoint 2: "))
  4.              (setq p3 (getpoint "\nPoint 3: "))
  5.         )
  6.         (if (setq p4 (3p-arc-mid (trans p1 1 0) (trans p2 1 0) (trans p3 1 0)))
  7.             (entmake (list '(0 . "POINT") (cons 10 p4)))
  8.             (princ "\nPoints are collinear.")
  9.         )
  10.     )
  11.     (princ)
  12. )

Thanks a lot , Lee ! :-)