Author Topic: Find Bi-Sect angle on side with greatest angle  (Read 2673 times)

0 Members and 1 Guest are viewing this topic.

SteveK

  • Guest
Find Bi-Sect angle on side with greatest angle
« on: November 04, 2009, 12:31:13 AM »
Hi,

Sorry it's my second new thread in one day. I'm sure this problem is staring me in the face but I've spent enough hours trying to work it out. It's mathematics.
I'm trying to get to bi-sect angle between two lines so that I can rotate a line (later a block) to always appear on the greater angle (see attached image - the green lines are what I'm trying to achieve).
Here's the code I am working with:
Code: [Select]
(defun c:try (/ doc pt1 pt2 pt3 ang1 ang2 angCombined ln)
  (vl-load-com)
  (setq mspc (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))

  (setq pt1 (getpoint "\nGet Point 1:")
pt2 (getpoint "\nGet Point 2:")
pt3 (getpoint "\nGet Point 3:")
)

  (setq ang1 (angle pt1 pt2)
ang2 (angle pt2 pt3))

  (setq angCombined (/ (angle pt1 pt2)
      2.))  

  (setq ln (vla-addline mspc
    (vlax-3d-point pt2)
    (vlax-3d-point (list
     (+ (car pt2) 40.)
     (cadr pt2)
     (caddr pt2)
     )
      )
    )
)

  (vla-rotate
    ln
    (vlax-3d-point pt2)
    angCombined
    )

  (princ)
  )

Thankyou

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Find Bi-Sect angle on side with greatest angle
« Reply #1 on: November 04, 2009, 03:16:50 AM »
Hi,

You can inspire this:

Code: [Select]
(defun GreatestBissect (p1 p2 p3 / a1 a2 bis)
  (setq a1  (angle p1 p2)
        a2  (angle p1 p3)
        a3  (- a2 a1)
        bis (+ a1
               (if (< (abs a3) pi)
                 (+ (/ a3 2.0) pi)
                 (/ a3 2.0)
               )
            )
  )
)

(defun c:test (/ p1 p2 p3 pt)
  (and
    (setq p1 (getpoint "\nSummit: "))
    (setq p2 (getpoint "\nFirst end: "))
    (setq p3 (getpoint "\nSecond end: "))
    (setq pt (polar p1 (GreatestBissect p1 p2 p3) 40.0))
    (entmake
      (list
        '(0 . "LINE")
        (cons 10 p1)
        (cons 11 pt)
      )
    )
  )
  (princ)
)
« Last Edit: November 04, 2009, 07:52:31 AM by gile »
Speaking English as a French Frog

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Find Bi-Sect angle on side with greatest angle
« Reply #2 on: November 04, 2009, 06:16:03 AM »

very economical gile ... nice !
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find Bi-Sect angle on side with greatest angle
« Reply #3 on: November 04, 2009, 08:34:44 AM »
I like it!
Slight variation:
Code: [Select]
(defun GreatestBissect (vr p2 p3 / a1 a2 a3 bis)
  (setq a1  (angle vr p2)
        a2  (angle vr p3)
        a3  (- a2 a1)
        bis (+ a1 (/ a3 2.0) (if (< (abs a3) pi) pi 0))
  )
)
« Last Edit: November 04, 2009, 08:47:07 AM by CAB »
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.

SteveK

  • Guest
Re: Find Bi-Sect angle on side with greatest angle
« Reply #4 on: November 04, 2009, 04:12:37 PM »
Thanks Gile & Alan :-D No more hours wasted  :oops:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find Bi-Sect angle on side with greatest angle
« Reply #5 on: November 04, 2009, 05:36:02 PM »
Steve,
This will save you from picking points if you can select the lines or segments.
Needs more testing.
Code: [Select]
(defun c:test (/ ENT1 ENT2 PAR1 PAR2 PSEL1 PSEL2 PT PT1 PT2 VERT)
  (defun GreatestBissect (a1 a2 / a3)
    (setq a3  (- a2 a1))
    (+ a1 (/ a3 2.0) (if (< (abs a3) pi) pi 0))
  )

  (while (not (setq ent1 (entsel "\nSelect first entity."))))
  (while (not (setq ent2 (entsel "\nSelect second entity."))))
  (setq pSel1 (cadr ent1)
        ent1  (car ent1)
  )
  (setq pSel2 (cadr ent2)
        ent2  (car ent2)
  )
  (setq pSel1 (vlax-curve-getclosestpointto ent1 pSel1)
        par1  (vlax-curve-getparamatpoint ent1 pSel1)
        pt1   (vlax-curve-getpointatparam ent1 (fix par1))
  )
  (setq pSel2 (vlax-curve-getclosestpointto ent2 pSel2)
        par2  (vlax-curve-getparamatpoint ent2 pSel2)
        pt2   (vlax-curve-getpointatparam ent2 (fix par2))
  )
  (if (setq vert (inters pSel1 pt1 pSel2 pt2 nil))
    (progn
      (setq pt (polar vert (GreatestBissect (angle vert pSel1) (angle vert pSel2)) 40.0))
      (entmake (list '(0 . "LINE") (cons 10 vert) (cons 11 pt)))
    )
    (princ "\nERROR - objects do not intersect.")
  )

  (princ)
)
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.

SteveK

  • Guest
Re: Find Bi-Sect angle on side with greatest angle
« Reply #6 on: November 04, 2009, 06:29:29 PM »
Yes you're right it does need more testing :-) That's ok though I've added a couple of vlax-ename->vla-objects.

However it brings up another question I have about vlax-curve-getparamatpoint, if I have:
Code: [Select]
(setq obj (vlax-ename->vla-object (car (Setq en (entsel))))
pt (cadr en))
(vlax-curve-getparamatpoint obj pt)
This should return the distance from the start point to the clicked point yet this will occasionally return nil. I thought it might be because the point is not exactly on the object I select but even if I use (getpoint) with a near osnap I still sometimes get nil. Do you know why that is? (I've just been trying this on lines)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find Bi-Sect angle on side with greatest angle
« Reply #7 on: November 04, 2009, 07:29:42 PM »
That is one of the idiosyncrasies of the vlax-curve functions, that is why I used
(setq pSel1 (vlax-curve-getclosestpointto ent1 pSel1) to assure it point is on the object.
BTW the vlax-curve functions work with entities as well as vla-objects and entities are faster.

One caution here: (setq obj (vlax-ename->vla-object (car (Setq en (entsel))))
If you pick nothing the (vlax-ename->vla-object  will error.

Quote
Yes you're right it does need more testing
Did you find an error? If so what was it?
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.

SteveK

  • Guest
Re: Find Bi-Sect angle on side with greatest angle
« Reply #8 on: November 04, 2009, 07:36:26 PM »
BTW the vlax-curve functions work with entities as well as vla-objects and entities are faster.

Did you find an error? If so what was it?
Sorry the program crashed and I automatically assumed it was cause I hadn't converted it from an entity to an object. As for the crash, it occurs because par2 returns nil. I've tried it a few more times and it doesn't happen always...  :|

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find Bi-Sect angle on side with greatest angle
« Reply #9 on: November 04, 2009, 07:47:07 PM »
Thanks, I'll see if I can fix that! 8-)
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find Bi-Sect angle on side with greatest angle
« Reply #10 on: November 04, 2009, 08:00:37 PM »
I haven't been able to recreate the error, so try this version.
Code: [Select]
(defun c:test (/ ENT1 ENT2 PAR1 PAR2 PSEL1 PSEL2 PT PT1 PT2 VERT)
  (defun GreatestBissect (a1 a2 / a3)
    (setq a3  (- a2 a1))
    (+ a1 (/ a3 2.0) (if (< (abs a3) pi) pi 0))
  )

  (while
    (cond
      ((not (setq ent1 (entsel "\nSelect first entity.")))
          (princ "\nMissed!  Try again."))
      ((not (setq pSel1 (vlax-curve-getclosestpointto (car ent1)(cadr ent1))))
          (princ "\nCurve Failed!  Try again."))
      ))
  (while
    (cond
      ((not (setq ent2 (entsel "\nSelect second entity.")))
          (princ "\nMissed!  Try again."))
      ((not (setq pSel2 (vlax-curve-getclosestpointto (car ent2)(cadr ent2))))
          (princ "\nCurve Failed!  Try again."))
      ))

  (setq ent1  (car ent1)
        par1  (vlax-curve-getparamatpoint ent1 pSel1)
        pt1   (vlax-curve-getpointatparam ent1 (fix par1))
  )
  (setq ent2  (car ent2)
        par2  (vlax-curve-getparamatpoint ent2 pSel2)
        pt2   (vlax-curve-getpointatparam ent2 (fix par2))
  )
  (if (setq vert (inters pSel1 pt1 pSel2 pt2 nil))
    (progn
      (setq pt (polar vert (GreatestBissect (angle vert pSel1) (angle vert pSel2)) 40.0))
      (entmake (list '(0 . "LINE") (cons 10 vert) (cons 11 pt)))
    )
    (princ "\nERROR - objects do not intersect.")
  )

  (princ)
)
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.

SteveK

  • Guest
Re: Find Bi-Sect angle on side with greatest angle
« Reply #11 on: November 04, 2009, 08:39:44 PM »
...I got the error twice in the last 10 trials. It could be something in the drawing because I copied the lines to another drawing and tried to reproduce the error but it was all good. Oh well, might just include another error trap for strange output.  :? thanks.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find Bi-Sect angle on side with greatest angle
« Reply #12 on: November 04, 2009, 10:10:51 PM »
There was another problem like this with vlax-curve some time back. Not sure if it was resolved.
I will see if I can research it tomorrow.
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find Bi-Sect angle on side with greatest angle
« Reply #13 on: November 04, 2009, 11:53:14 PM »
How about another test:
Code: [Select]
(defun c:test (/ ENT1 ENT2 PAR1 PAR2 PSEL1 PSEL2 PT PT1 PT2 VERT)
  (defun GreatestBissect (a1 a2 / a3)
    (setq a3  (- a2 a1))
    (+ a1 (/ a3 2.0) (if (< (abs a3) pi) pi 0))
  )

  (while
    (cond
      ((not (setq ent1 (entsel "\nSelect first entity.")))
          (princ "\nMissed!  Try again."))
      ((not (setq pSel1 (vlax-curve-getclosestpointto (car ent1)(cadr ent1))))
          (princ "\nCurve Failed!  Try again."))
      ))
  (while
    (cond
      ((not (setq ent2 (entsel "\nSelect second entity.")))
          (princ "\nMissed!  Try again."))
      ((not (setq pSel2 (vlax-curve-getclosestpointto (car ent2)(cadr ent2))))
          (princ "\nCurve Failed!  Try again."))
      ))

  (setq ent1  (car ent1)
        par1  (vlax-curve-getparamatpoint ent1
                (vlax-curve-getpointatdist ent1
                  (vlax-curve-getdistatpoint ent1 pSel1)))
        pt1   (vlax-curve-getpointatparam ent1 (fix par1))
  )
  (setq ent2  (car ent2)
        par2  (vlax-curve-getparamatpoint ent2
                (vlax-curve-getpointatdist ent2
                  (vlax-curve-getdistatpoint ent2 pSel2)))
        pt2   (vlax-curve-getpointatparam ent2 (fix par2))
  )
  (if (setq vert (inters pSel1 pt1 pSel2 pt2 nil))
    (progn
      (setq pt (polar vert (GreatestBissect (angle vert pSel1) (angle vert pSel2)) 40.0))
      (entmake (list '(0 . "LINE") (cons 10 vert) (cons 11 pt)))
    )
    (princ "\nERROR - objects do not intersect.")
  )

  (princ)
)
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.

SteveK

  • Guest
Re: Find Bi-Sect angle on side with greatest angle
« Reply #14 on: November 05, 2009, 12:09:59 AM »
I thought you were gonna continue tomorrow!  :-) Well, it's tomorrow now your time so I guess that's true.

And you wouldn't be surprised, it crashed first go. Maybe you will get the error if you try it on the drawing I was using. It worked occasionally but the 3 times I tried it selecting the lines within the circles it crashed.
And once again I tried it on a new drawing and works fine.