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

0 Members and 1 Guest are viewing this topic.

Peter2

  • Swamp Rat
  • Posts: 653
[Solved] MID of a given arc
« on: February 18, 2014, 04:56:13 PM »
EDIT: At the moment I pressed "Post" I got the idea ... Solution see below.

I have an arc, given with startpoint, endpoint, radius and centre. Should be easy, but at the moment I have no idea how to calculate the MID of the arc (I'm confused about direction of rotation, angles > 2pi  :embarrassed: ...)

Any hints?
Thanks.

EDIT: Solution:
Code: [Select]
(polar zen (angle zen (mapcar '(lambda (x) (* 0.5 x))(mapcar '+ start end))) rad)which means ..
- calculate the middle of START and END (helppoint)
- calculate the point with Polar from centre with direction to helppoint and with length of radius
Should do it ...

Peter

« Last Edit: February 18, 2014, 05:08:20 PM by Peter2 »
Peter

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
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.

Peter2

  • Swamp Rat
  • Posts: 653
Re: [Solved] MID of a given arc
« Reply #2 on: February 18, 2014, 05:11:10 PM »
Hi Kerry

thanks - you were to quick for my edit above. I'm sorry. But nevertheless, I have to learn a lot about the "vlax-curve" functions.
Peter

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

ronjonp

  • Needs a day job
  • Posts: 7529
Re: [Solved] MID of a given arc
« Reply #3 on: February 18, 2014, 05:13:09 PM »
Hi Kerry

thanks - you were to quick for my edit above. I'm sorry. But nevertheless, I have to learn a lot about the "vlax-curve" functions.

See if you can dissect this:
Code: [Select]
(defun _mid (ename / ep)
  (if (not (vl-catch-all-error-p (setq ep (vl-catch-all-apply 'vlax-curve-getendparam (list ename)))))
    (vlax-curve-getpointatdist ename (/ (vlax-curve-getdistatparam ename ep) 2.))
  )
)
;; (_mid (car (entsel)))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: [Solved] MID of a given arc
« Reply #4 on: February 18, 2014, 05:30:31 PM »
ronjonp,

Mine is similar ; except I multiply by 0.5 instead of dividing by 2.0
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.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: [Solved] MID of a given arc
« Reply #5 on: February 18, 2014, 07:53:27 PM »
ronjonp,

Mine is similar ; except I multiply by 0.5 instead of dividing by 2.0


:)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: [Solved] MID of a given arc
« Reply #6 on: February 18, 2014, 08:11:17 PM »
I've had a little think about the multiply/divide issue.
Popular belief WAS that multiplying by a value was more economical than dividing by a value.
I haven't done any research on this so I'm not sure is this was ever or is still true.
It's one of those geeky habits one develops I s'pose.

I imagine the efficiency difference would depend on the language and compilation.

added:
And perhaps efficiency is affected if the value or it's reciprocal is an integer.

« Last Edit: February 18, 2014, 08:21:00 PM 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.

owenwengerd

  • Bull Frog
  • Posts: 451
Re: [Solved] MID of a given arc
« Reply #7 on: February 18, 2014, 09:13:34 PM »
And perhaps efficiency is affected if the value or it's reciprocal is an integer.

On binary hardware, a multiply or divide by two is a simple shift-by-one, which is as easy as it gets.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: [Solved] MID of a given arc
« Reply #8 on: February 19, 2014, 01:12:45 AM »
In general I do think * is faster than /. See some writeup here: http://stackoverflow.com/questions/4125033/floating-point-division-vs-floating-point-multiplication
On binary hardware, a multiply or divide by two is a simple shift-by-one, which is as easy as it gets.
Usually if you're compiling your code and the compiler actually optimizes for that yes. If AutoLisp does it in FAS or even in its interpreted state I'm not sure. Also these are floating point numbers, so a simple shifting of bits isn't exactly how it happens: rather an increment/decrement of the exponent (might even be faster). So if ALisp's interpreter and/or compiler recognises multiplication / division by 2, then yes it should perform faster, else it'll use the longwinded way - in which case multiplication will always be faster.

Actually from tests the AutoLisp interpreter actually seems to have no effective difference in speed between / and *, not even between integer and real numbers. And not even between 2 or 3 as divisor:
Code: [Select]
_$ (quickbench '((/ 123456 2) (* 123456 2) (* 123456 0.5) (/ 123456 2.0) (/ 123456. 2) (* 123456. 2) (* 123456. 0.5) (/ 123456. 2.0) (/ 123456 3) (* 123456 3) (* 123456 0.3333333333333333) (/ 123456 3.0) (/ 123456. 3) (* 123456. 3) (* 123456. 0.33333333333333333333333333333333) (/ 123456. 3.0)))
Benchmarking ................ done for 32768 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(/ 123456 3)                                 32768      1137      1137      1.08
(* 123456 2)                                 32768      1170      1170      1.05
(/ 123456.0 3.0)                             32768      1171      1171      1.05
(* 123456 3)                                 32768      1185      1185      1.04
(* 123456.0 0.333333)                        32768      1185      1185      1.04
(/ 123456 2)                                 32768      1186      1186      1.04
(/ 123456.0 2)                               32768      1186      1186      1.04
(/ 123456 3.0)                               32768      1187      1187      1.04
(* 123456 0.5)                               32768      1201      1201      1.03
(/ 123456.0 3)                               32768      1201      1201      1.03
(* 123456.0 3)                               32768      1202      1202      1.02
(/ 123456 2.0)                               32768      1216      1216      1.01
(* 123456.0 2)                               32768      1217      1217      1.01
(* 123456.0 0.5)                             32768      1217      1217      1.01
(* 123456 0.333333)                          32768      1218      1218      1.01
(/ 123456.0 2.0)                             32768      1232      1232      1.00
--------------------------------------------------------------------------------

As for the OP: If you want to find all sorts of other calcs on arcs, I've found this to be a great resource.
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 #9 on: February 19, 2014, 01:17:53 AM »
< .. >

As for the OP: If you want to find all sorts of other calcs on arcs, I've found this to be a great resource.

I miss Stig. Hope he is well.
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: [Solved] MID of a given arc
« Reply #10 on: February 19, 2014, 03:47:07 AM »
Hi

interesting discussions here. The "vlax-curve"-functions are great, but how to handle it with an basic algorithm for pocket calculators?

But, back to the roots...

I saw that my "solution" I posted above has some lacks - especially if the "included angle > pi".

Example: I have two following red lines with points A - B - C. With A - B - C I can create an arc, and with 3P-arc-calculation I can calculate CEN and RAD. But how to calculate the included angle, if the arc is > PI or if the arc runs over the "0 PI"? How to calculate the MID?

We know the following points
A
B
C

So we know the distance from A->B, B->C, A->C.
We know the radius.
So we can calculate the angles A, Cen, B and B, Cen, C
The sum of these will be the enclosed angle.

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.

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: [Solved] MID of a given arc
« Reply #11 on: February 19, 2014, 05:51:38 AM »
EDIT: Solution:
Code: [Select]
(polar zen (angle zen (mapcar '(lambda (x) (* 0.5 x))(mapcar '+ start end))) rad)which means ..
- calculate the middle of START and END (helppoint)
- calculate the point with Polar from centre with direction to helppoint and with length of radius
Should do it ...

You can use angles instead points.
This vanilla solution should work for any arc.
Code - Auto/Visual Lisp: [Select]
  1. (defun C:MIDARC (/ mid_arc ss i)
  2.   (defun mid_arc (e / c s f a n r)
  3.     (setq e (entget e)
  4.           c (cdr (assoc  10 e))         ; center point [OCS]
  5.           s (cdr (assoc  50 e))         ; start angle
  6.           f (cdr (assoc  51 e))         ; end angle
  7.           n (cdr (assoc 210 e))         ; normal vector
  8.           r (cdr (assoc  40 e))         ; radius
  9.           a (-                          ; angle center -> mid point
  10.               (/ (+ s f) 2.0)
  11.               (if (> s f) pi 0)         ; subtract pi, if start angle > end angle
  12.             )
  13.     )
  14.     (trans (polar c a r) n 0)           ; arc midpoint [WCS]
  15.   )
  16.  
  17.   (if
  18.     (setq ss (ssget '((0 . "ARC"))))
  19.     (repeat (setq i (sslength ss))
  20.       (entmake
  21.         (list
  22.          '(0 . "POINT")
  23.           (cons 10 (mid_arc (ssname ss (setq i (1- i)))))
  24.         )
  25.       )
  26.     )
  27.   )
  28.   (princ)
  29. )

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: [Solved] MID of a given arc
« Reply #12 on: February 19, 2014, 06:13:02 AM »
Stefan,
I think Peter wants a solution that is purely mathematical , not object/entity based.
ie:
Quote
< .. > but how to handle it with an basic algorithm for pocket calculators?
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.

Peter2

  • Swamp Rat
  • Posts: 653
Re: [Solved] MID of a given arc
« Reply #13 on: February 19, 2014, 06:37:25 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)
Peter

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

fixo

  • Guest
Re: [Solved] MID of a given arc
« Reply #14 on: February 19, 2014, 07:47:50 AM »
And perhaps efficiency is affected if the value or it's reciprocal is an integer.

On binary hardware, a multiply or divide by two is a simple shift-by-one, which is as easy as it gets.
Thanks Owen, I like it:
http://otb.manusoft.com/2013/01/quirkypolyline-exposing-foolish-programmers.htm
Probably. it may helps to thread starter  :)

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 ! :-)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: [Solved] MID of a given arc
« Reply #30 on: February 25, 2014, 04:03:39 PM »
No worries - it was fun to write!  :-)