Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ARC & LINE intersection

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
dmachuga
801 Views, 12 Replies

ARC & LINE intersection

I am trying to make a function in AutoLISP that can find a point of intersection on a line and arc without having entity data.

How to find ARC & LINE intersection with the following data:
Line: Start point / End point
Arc: Center point / Radius / Angles

Any help would be appreciated.

Thank you, Dan

12 REPLIES 12
Message 2 of 13
dbroad
in reply to: dmachuga

Try a google search "arc line intersection". Should be easy to find an algorithm.

Architect, Registered NC, VA, SC, & GA.
Message 3 of 13
Kent1Cooper
in reply to: dmachuga

A start on an approach:

Kent1Cooper_0-1666962048297.png

Red is the given stuff.  Yellow is what needs to be calculated from red to find green.  White is for illustration -- it does not need to be drawn to do this.  If it were, you could use the VLA (intersectwith) method, and that is another approach -- just draw the Arc and Line from the information given.  But assuming you don't want to do that:

 

B is (inters L1 L2 CTR (polar CTR (+ (angle L1 L2) (/ pi 2)) 1) nil)

  [The 1 can be any number.  B may or may not be on the Line.  CTR to B is perpendicular to the Line.]

X is (distance CTR B)

Y is (sqrt (- (expt R 2) (expt X 2)))

C is (polar B (angle L1 L2) Y)

 

BUT L1 and L2 could be in the reverse direction, and the general configuration could vary in assorted ways, so it would need some checking of results --

Is X less than R?  [If it's more, the Line can't intersect the Arc.]

Is C between L1 and L2? [Compare (angle)s or (distance)s between.]

Is C at an angle about CTR within the range from A1 to A2?

Is C in the opposite direction from B [use negative Y or add pi to the angle in calculating C]?

Are there two intersections?

Do you want an apparent intersection, beyond the end of one or the other or both, if that exists but there isn't an actual one?

Etc.

Kent Cooper, AIA
Message 4 of 13
dmachuga
in reply to: Kent1Cooper

I am looking for the apparent intersection.

Message 5 of 13
Kent1Cooper
in reply to: dmachuga


@dmachuga wrote:

I am looking for the apparent intersection.


Then you don't need the Arc's start and end angles A1 & A2.  There will be: no intersection if the Line bypasses the Arc [X is greater than R], one if the Line is tangent to the Arc [X = R, Y = 0], or always two otherwise [use both positive & negative Y, or both opposite angles, in calculating two C locations].

Kent Cooper, AIA
Message 6 of 13
Sea-Haven
in reply to: dmachuga

Why not use, 

(setq intpt1 (vlax-invoke obj2 'intersectWith obj1 acExtendnone))

But you will need to draw the arc and line, they become the VL objects obj1 and obj2.

Be careful if say line passes through arc twice the 2 points will be returned using above. There are also other tests like acExtendThisEntity 4 in total helping to solve the "Apparent intersection"

 

You just draw them calc then delete you will be lucky to see the flash as the objects are drawn and erased. This method has worked succesfully on random objects. 2 lines plines and so on.

Message 7 of 13
dmachuga
in reply to: Kent1Cooper

Thank you Kent1Cooper, That is what I was looking for.

Message 8 of 13
dmachuga
in reply to: Kent1Cooper

Here is the ARC & LINE.

Message 9 of 13
Kent1Cooper
in reply to: dmachuga


@dmachuga wrote:

Here is the ARC & LINE.


[For those who are wondering, @dmachuga sent me a private message asking whether the virtual intersection could be calculated for two Arcs if their centers and radii and start/end angles are known, expecting some similarly-(inters)-related solution to the above about a Line & and an Arc.  I asked them to remind me what the Line-&-Arc approach was, so they revived this Topic.]

I suspect it's not going to involve (inters), but here's the beginning of a solution:

Kent1Cooper_0-1676929117411.png

A (polar) function based around A, with Ang added to the direction from A to B, and the b length, would give the location of C.

 

The problem is that AutoLisp doesn't have an arc-cosine [cosine-to-the-minus-1] function, so I'd have to think about how to calculate that angle.  I'm pretty sure there are routines out there defining such other trig functions, but I'd have to find them -- maybe tomorrow, or you can Search for them.

Kent Cooper, AIA
Message 10 of 13
dmachuga
in reply to: dmachuga

I have been trying to use the following to make a routine. https://lucidar.me/en/mathematics/how-to-calculate-the-intersection-points-of-two-circles/ 

I am currently up to finding X5 and Y5, having trouble getting the correct results.

Message 11 of 13
dmachuga
in reply to: Kent1Cooper

here is what I have so far.

 

(defun ArcArcInt ()
;;;P1 = -90.200,-110.937
;;;P1X = -90.200
;;;P1Y = -110.937

;;;P2 = -88.222,-116.193
;;;P2X = -88.222
;;;P2Y = -116.193

;;;R1 = 3.575
;;;R2 = 3.581

(setq P1 (list P1X P1Y))
(setq P2 (list P2X P2Y))

(setq P1X -90.200)
(setq P1Y -110.937)
(setq P2X -88.222)
(setq P2Y -116.193)
(setq R1 3.575)
(setq R2 3.581)

;;;;;Distance between centers
(setq d (distance P1 P2))

(princ "\nd {5.616} =")
(princ d)

;;;;;Calculating a and b
(setq a (/ (+ (- (expt R2 2) (expt R1 2)) (expt d 2)) (* d 2)))
(setq b (/ (+ (- (expt R1 2) (expt R2 2)) (expt d 2)) (* d 2)))

(princ "\na {2.812} =")
(princ a)
(princ "\nb {2.804} =")
(princ b)

;;;;;Calculation of h
(setq h (sqrt (- (expt R2 2) (expt a 2))))

(princ "\nh {2.217} =")
(princ h)

;;;;;Coordinates of P5
(setq X5 (+ P2X (* (/ a d) (- P1X P2X))))
(setq Y5 (+ P2Y (* (/ a d) (- P1Y P2Y))))

(princ "\nX5 {-89.212} =")
(princ X5)
(princ "\nY5 {-113.561} =")
(princ Y5)

;;;;Vectors P5P3 and P5P4

(princ)
)

Message 12 of 13
dmachuga
in reply to: Kent1Cooper

I have been trying to use the following to make a routine. https://lucidar.me/en/mathematics/how-to-calculate-the-intersection-points-of-two-circles/ 

I am currently up to finding Vectors P5P3 and P5P4.

.

Message 13 of 13
dmachuga
in reply to: dmachuga

I think I have it figure out. Here is my version.

 

(defun ArcArcInt ()
;;;P1 = -90.200,-110.937
;;;P1X = -90.200
;;;P1Y = -110.937

;;;P2 = -88.222,-116.193
;;;P2X = -88.222
;;;P2Y = -116.193

;;;R1 = 3.575
;;;R2 = 3.581

(setq P1 (list P1X P1Y))
(setq P2 (list P2X P2Y))

(setq P1X -90.200)
(setq P1Y -110.937)
(setq P2X -88.222)
(setq P2Y -116.193)
(setq R1 3.575)
(setq R2 3.581)

(princ "\nP1X {-90.200} =")
(princ P1X)
(princ "\nP1Y {-110.937} =")
(princ P1Y)
(princ "\nP2X {-88.222} =")
(princ P2X)
(princ "\nP2Y {-116.193} =")
(princ P2Y)
(princ "\nR1 {3.575} =")
(princ R1)
(princ "\nR2 {3.581} =")
(princ R2)

;;;;;Distance between centers
(setq d (distance P1 P2))

(princ "\nd {5.616} =")
(princ d)

;;;;;Calculating a and b
(setq a (/ (+ (- (expt R1 2) (expt R2 2)) (expt d 2)) (* d 2)))
(setq b (/ (+ (- (expt R2 2) (expt R1 2)) (expt d 2)) (* d 2)))

(princ "\na {2.804} =")
(princ a)
(princ "\nb {2.812} =")
(princ b)

;;;;;Calculation of h
(setq h (sqrt (- (expt R1 2) (expt a 2))))

(princ "\nh {2.217} =")
(princ h)

 

 


;;;;;Coordinates of P5
(setq X5 (+ P2X (* (/ a d) (- P1X P2X))))
(setq Y5 (+ P2Y (* (/ a d) (- P1Y P2Y))))

(princ "\nX5 {-89.212} =")
(princ X5)
(princ "\nY5 {-113.561} =")
(princ Y5)

 

;;;;Vectors P5P3 and P5P4
(setq P5 (list X5 Y5))

(princ "\nP5 {-89.212,-113.561} =")
(princ P5)


(setq BASEangle (angle P1 P2))
(setq BASEangleDEG (atof (angtos BASEangle 0 4)) )

(princ "\nBASEangleDEG {290.625} =")
(princ BASEangleDEG)

 

(setq I1 (polar P5 (* pi (/ (+ BASEangleDEG 90.0) 180.0)) h ))
(setq I2 (polar P5 (* pi (/ (- BASEangleDEG 90.0) 180.0)) h ))

(princ "\nI1 {-87.137,-112.780} =")
(princ I1)
(princ "\nI2 {-91.287,-114.342} =")
(princ I2)

 

(princ)
)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report