Jump to content

Polyline bulge convertions?


Aftertouch

Recommended Posts

Hello all,

 

Im having some problems with calculating a bulge factor...

 

I have the following situation:

bulge.png

 

I manage to get a list with all coordinates, and the bulge factor in the right place.

Altho... it seems my bulgefactor is calculated wrong...

 

I manage to get all lengths of the magenta lines with the matching coordinates.

So my formula is:

 

Where arcbulge is the length of the 'vertical' line to the centerpoint of the desired circle.

(setq bulge (/ (tan arcbulge) 4))

But this results in a bulge of 0.0571689,

while im looking for a value of: 0.71248.

 

Here are the coords of the points:

106357.129 507429.816 startpoint

106362.918 507433.010 random point on the arc.

106366.580 507429.816 endpoint

 

Where am i going wrong?

Link to comment
Share on other sites

Thanks for your Reply Marko.

This leads me into another question....

 

How can i get the angle?

Since there are cases, where i just got 3 points.

Start, Arcpoint, End.

Then i dont have any reference to get the angle?

Link to comment
Share on other sites

I foudn this on the webs after a long search.

(DEFUN WIKI-3PTTOBULGE (PNT1 PNT2 PNT3 / ANG1 ANG2 ANG3 BULGE CHORD DELTA DELTA1 R)
(COND
	((NOT PNT2)
		0
	)
	(T
		(SETQ CHORD (DISTANCE PNT1 PNT3))
		(setq ANG2 (- (ANGLE PNT2 PNT1) (ANGLE PNT2 PNT3)))
		(setq R (/ CHORD (* 2 (SIN ANG2))))
		(setq DELTA1 (* 2 (WIKI-ASIN (/ CHORD (* 2 R)))))
		(setq ANG1 (ABS (- (ANGLE PNT1 PNT3) (ANGLE PNT1 PNT2))))
		(setq ANG1 (ABS (IF (> ANG1 PI)(- ANG1 (* 2 PI)) ANG1)))
		(setq ANG3 (ABS (- (ANGLE PNT3 PNT1) (ANGLE PNT3 PNT2))))
		(setq ANG3 (ABS (IF (> ANG3 PI)(- ANG3 (* 2 PI)) ANG3)))
		(setq DELTA (* 2 (+ ANG1 ANG3)))
		(setq BULGE (* (IF (MINUSP R) -1 1)(WIKI-TAN (/ DELTA 4.0))))
	)
)
)

(DEFUN WIKI-TAN (X)
(/ (SIN X) (COS X))
)

(DEFUN WIKI-ASIN (X)
(ATAN X (SQRT (- 1 (* X X))))
)

 

Seems to do the trick. :-)

Link to comment
Share on other sites

I think this is sufficient:

;; 3-Points to Bulge  -  Lee Mac
(defun LM:3p->bulge ( p1 p2 p3 )
   ((lambda ( a ) (/ (sin a) (cos a))) (/ (+ (- pi (angle p2 p1)) (angle p2 p3)) 2))
)

WCS Example:

(defun c:test ( / p1 p2 p3 )
   (if (and (setq p1 (getpoint "\nSpecify 1st Point: "))
            (setq p2 (getpoint "\nSpecify 2nd Point: " p1))
            (setq p3 (getpoint "\nSpecify 3rd Point: " p2))
       )
       (entmake
           (list
              '(000 . "LWPOLYLINE")
              '(100 . "AcDbEntity")
              '(100 . "AcDbPolyline")
              '(090 . 2)
              '(070 . 0)
               (cons 10 p1)
               (cons 42 (LM:3p->bulge p1 p2 p3))
               (cons 10 p3)
           )
       )
   )
   (princ)
)

Link to comment
Share on other sites

Not sure if SetBulge and GetBulge methods are holding the same value as the 42 group code, but along with LM:3p->bulge the task becomes even easier:

 

(vla-SetBulge plineObj vtx (LM:3p->bulge p1 p2 p3))

Link to comment
Share on other sites

;; 3-Points to Bulge  -  M.R.
(defun MR:3p->bulge ( p1 p2 p3 / mid asin clockwise m12 m23 c r )
   (defun mid ( p1 p2 )
       (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) p1 p2)
   )
   (defun asin ( x )
       (cond
           ((equal x 1.0 1e- (/ pi 2.0))
           ((equal x -1.0 1e- (* 3.0 (/ pi 2.0)))
           ((equal x 0.0 1e- 0.0)
           ((equal x -0.0 1e- pi)
           ((atan (/ x (sqrt (- 1.0 (* x x))))))
       )
   )
   (defun clockwise ( p1 p2 p3 )
       (minusp (- (* (- (car p2) (car p1)) (- (cadr p3) (cadr p1))) (* (- (car p3) (car p1)) (- (cadr p2) (cadr p1)))))
   )
   (setq m12 (mid p1 p2))
   (setq m23 (mid p2 p3))
   (setq c (inters m12 (polar m12 (+ (angle p1 p2) (* 0.5 pi)) 1.0) m23 (polar m23 (+ (angle p2 p3) (* 0.5 pi)) 1.0) nil))
   (setq r (distance c p1))
   (if (not (clockwise p1 p2 p3))
       (if (<= (rem (+ pi pi (- (angle c p3) (angle c p1))) (+ pi pi)) pi)
           ((lambda ( a ) (/ (sin a) (cos a))) (/ (asin (/ (distance p1 p3) r 2.0)) 2.0))
           ((lambda ( b ) (/ 1.0 b)) ((lambda ( a ) (/ (sin a) (cos a))) (/ (asin (/ (distance p1 p3) r 2.0)) 2.0)))
       )
       (if (<= (rem (+ pi pi (- (angle c p1) (angle c p3))) (+ pi pi)) pi)
           ((lambda ( a ) (- (/ (sin a) (cos a)))) (/ (asin (/ (distance p1 p3) r 2.0)) 2.0))
           ((lambda ( b ) (- (/ 1.0 b))) ((lambda ( a ) (/ (sin a) (cos a))) (/ (asin (/ (distance p1 p3) r 2.0)) 2.0)))
       )
   )
)

Link to comment
Share on other sites

Good idea to check clockwise-p, although I'm not sure if thats important.

 

Marko, I don't understand such math codes, but I think you could shorten a bit:

(setq plst (list p1 p2 p3))
(if (clockwise plst)
 (apply 'fun plst)
 (apply 'fun (reverse plst))
)

Link to comment
Share on other sites

What would be the bulge formula be if p2 is a cp and the bulge is calculated between p1 and p3 (both p1 and p3 are on cp circle)?

 

I think this is sufficient:
;; 3-Points to Bulge  -  Lee Mac
(defun LM:3p->bulge ( p1 p2 p3 )
   ((lambda ( a ) (/ (sin a) (cos a))) (/ (+ (- pi (angle p2 p1)) (angle p2 p3)) 2))
)

WCS Example:

(defun c:test ( / p1 p2 p3 )
   (if (and (setq p1 (getpoint "\nSpecify 1st Point: "))
            (setq p2 (getpoint "\nSpecify 2nd Point: " p1))
            (setq p3 (getpoint "\nSpecify 3rd Point: " p2))
       )
       (entmake
           (list
              '(000 . "LWPOLYLINE")
              '(100 . "AcDbEntity")
              '(100 . "AcDbPolyline")
              '(090 . 2)
              '(070 . 0)
               (cons 10 p1)
               (cons 42 (LM:3p->bulge p1 p2 p3))
               (cons 10 p3)
           )
       )
   )
   (princ)
)

Edited by gsc
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...