PDA

View Full Version : Stumped - Line & Circle - Possible No Intersection



Hudson
30th Oct 2009, 11:10 pm
Ok, the latest thing to stump me is this:

I have a circle and a line. They may intersect, which is easy to handle, but they might not.. if they don't I'd like to find the closest point on the line to the circle.

Any help would greatly be appreciated thanks!

SteveK
31st Oct 2009, 12:46 am
At least you are getting stuck on interesting things :)

I can help you out a bit. If the two objects are intersecting this will tell you the co-ordinates (let me know if you want any explaining):

(defun c:ints (/ obj1 obj2)

(setq obj1 (vlax-ename->vla-object (car(entsel)))
obj2 (vlax-ename->vla-object (car(entsel))))

(if (setq int (vlax-invoke obj1 'intersectWith obj2 acExtendNone))
(princ int)
(princ "Not Intersecting."))

(princ)
)

To get the closest point between the two have a look at vlax-curve-getClosestPointTo which will give you the closest point between a point and an object (whether it be a line or a circle). I've seen it used between two objects somewhere but I can't remember sorry, others will I'm sure.

Hudson
31st Oct 2009, 01:09 am
At least you are getting stuck on interesting things :)

I can help you out a bit. If the two objects are intersecting this will tell you the co-ordinates (let me know if you want any explaining):

(defun c:ints (/ obj1 obj2)

(setq obj1 (vlax-ename->vla-object (car(entsel)))
obj2 (vlax-ename->vla-object (car(entsel))))

(if (setq int (vlax-invoke obj1 'intersectWith obj2 acExtendNone))
(princ int)
(princ "Not Intersecting."))

(princ)
)To get the closest point between the two have a look at vlax-curve-getClosestPointTo which will give you the closest point between a point and an object (whether it be a line or a circle). I've seen it used between two objects somewhere but I can't remember sorry, others will I'm sure.

Yes, interesting is much better.. that entmake crash still has me.

At any rate.. that should solve my problem.. I was having difficulty composing working logic with a different vla method. That should get me there.

SteveK
31st Oct 2009, 01:33 am
Ok.

If you end up getting a function that calculates the closest point on one object in relation to another object can you post it? I'll probably find a use for it down the track.

devitg
31st Oct 2009, 05:28 am
At least you are getting stuck on interesting things :)

I can help you out a bit. If the two objects are intersecting this will tell you the co-ordinates (let me know if you want any explaining):

(defun c:ints (/ obj1 obj2)

(setq obj1 (vlax-ename->vla-object (car(entsel)))
obj2 (vlax-ename->vla-object (car(entsel))))

(if (setq int (vlax-invoke obj1 'intersectWith obj2 acExtendNone))
(princ int)
(princ "Not Intersecting."))

(princ)
)To get the closest point between the two have a look at vlax-curve-getClosestPointTo which will give you the closest point between a point and an object (whether it be a line or a circle). I've seen it used between two objects somewhere but I can't remember sorry, others will I'm sure.

Just do it so , by lisp

Select the line,and the circle.

get the closest point from circle center to line obj,



(vl-load-com)
(setq line (Car (entsel "LINE")))
(setq line-obj (vlax-ename->vla-object line))

(setq circle (car (entsel "circle")))

(setq circle-center (code 10 circle))

(setq line-point ( vlax-curve-getclosestpointto line-obj circle-center))

(setvar 'osmode 0)

(command "_line" circle-center line-point "")

Hudson
31st Oct 2009, 06:48 pm
Thank you both!

I'm now off to the next problem :P

devitg
31st Oct 2009, 06:52 pm
We are waiting for it.

alanjt
31st Oct 2009, 07:27 pm
I was bored this morning waiting on the wife to wake up, so I decided to throw this together. I didn't get a chance to post it earlier since we had to pick up a load of scrap iron for a huge art project we're doing at her school.

I got a little carried away, but enjoy. :)

15198

Oh yeah, you will need my AT:Entsel function: http://www.cadtutor.net/forum/showpost.php?p=271389&postcount=26

Randolph
1st Nov 2009, 10:43 am
Eeasy with geometry:

A line L is passing a circle C.

Make a helpline H (Point 1: Snap to the center of the circle. Point 2: Snap perpendicular to line L). Point 2 is the point on L closest to the circle.

Hudson
1st Nov 2009, 04:12 pm
Randolph, you are correct, it is a simple geometrical problem.. However, I've got it working just fine all with code. I'm trying to automate things :)

alanjt
1st Nov 2009, 04:47 pm
Randolph, you are correct, it is a simple geometrical problem.. However, I've got it working just fine all with code. I'm trying to automate things :)
I think my code solves any questions, regarding working with about any object type.

Randolph
1st Nov 2009, 05:20 pm
"I'm trying to automate things :)"

You're right, and that's why I'm so happy with Alan ...

alanjt
1st Nov 2009, 05:36 pm
"I'm trying to automate things :)"

You're right, and that's why I'm so happy with Alan ...
LoL

15217
.............