Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Determine where 2 extruded lines intersect

Determine where 2 extruded lines intersect

kenc
Advocate Advocate
3,450 Views
36 Replies
Message 1 of 37

Determine where 2 extruded lines intersect

kenc
Advocate
Advocate

If I have 2 walls(lines) crossing over or one of them is just touching the other, how do I determine at what point they intersect.

 

TIA

Ken

0 Likes
Accepted solutions (1)
3,451 Views
36 Replies
Replies (36)
Message 21 of 37

MartinBeh
Advisor
Advisor

@kenc  schrieb:

@MartinBeh What I'm saying is if script can determine an intersection occurring, then why not determine the point of intersection.


All the intersects command does is: check whether the bounding boxes of the two objects overlap.

That is all. 

Try this: Create two spheres and place them such that one is at the origin, the other at 45 degrees to the top-left such that they almost touch each other but leave a little gap. Then ask the intersects command -> it will return true, although the two spheres do not overlap (because their bounding boxes overlap).

 

As already mentioned, you either have make an assumption that one of your objects is planar, then you can use Slice modifier or the code Denis posted. Or you will have to use sort kind of mesh booleans which will work most of the time for any polygonal object.

 

I think you will have to rethink (or tell us more about) your ultimate goal for all this - why do you need the intersection, and in what form (a spline shape?) do you need it?

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 22 of 37

kenc
Advocate
Advocate

@MartinBeh I understand what the intersect command does. What I'm saying is they should have another command to determine the point of intersection.

The slice modifier only works on objects with volume, not extruded lines converted to edit poly.

0 Likes
Message 23 of 37

kenc
Advocate
Advocate

@denisT.MaxDoctor thank you. I have not had the chance to look at your code. I am state side the coming week, so I will have a go when I am back,

Thanks again.

0 Likes
Message 24 of 37

MartinBeh
Advisor
Advisor

@kenc  schrieb:

@MartinBeh I understand what the intersect command does. What I'm saying is they should have another command to determine the point of intersection.

The slice modifier only works on objects with volume, not extruded lines converted to edit poly.


  1. As explained "intersect" does not compute intersection of objects, only whether their bounding boxes overlap.
  2. The Slice modifier works for everything made up of triangles. It will compute the intersection of a plane (the Slide gizmo) and the target geometry.
  3. If you don't want the result as edges in the target geometry (Slice modifier), you could use the "Section" shape which will intersect the target geometry with a perfect plane and generate a spline along the intersection. Just create a Section shape and align it to the first plane, then hide everything but the second plane and hit "Create shape"
Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 25 of 37

MartinBeh
Advisor
Advisor

@denisT.MaxDoctor - do you maybe know a way to change the "Sections Extents" parameter of a Section shape using MAXScript? 

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 26 of 37

denisT.MaxDoctor
Advisor
Advisor

the finding of the intersection of two planes needs only a simple math

0 Likes
Message 27 of 37

MartinBeh
Advisor
Advisor

@denisT.MaxDoctor  schrieb:

the finding of the intersection of two planes needs only a simple math


For infinite planes that is simple but for 3ds Max Planes (with width and length) that might get more complicated?

Either way, I would still be very interested in any ideas to adjust the Section shape options...

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 28 of 37

denisT.MaxDoctor
Advisor
Advisor

Section is an older class. Some parameters are not exposed for MaxScript and can only be modified from the user interface. Something like that:

 

fn setSectionExtents type:1 = 
(
	if iskindof (obj = modpanel.getcurrentobject()) Section do
	(
		h = windows.getchildhwnd #max "Section Extents"
		if type > 0 do  
		-- Infinite:
		b = uiaccessor.getnextwindow h[1]

		if type > 1 do  
		-- Section Boundary:
		b = uiaccessor.getnextwindow b

		if type > 2 do  
		-- Off:
		b = uiaccessor.getnextwindow b

		uiaccessor.pressbutton b
		modpanel.setcurrentobject obj -- to update UI if you need
	)
)

 

 

Message 29 of 37

MartinBeh
Advisor
Advisor

Very nice, thanks a bunch for taking a look at this! I never got terribly friendly with UIAccessor...

 

Out of curiosity:  Would this...

windows.getchildhwnd #max "Section Extents" 

... still work in a non-English 3ds Max? Or would one need to find the proper string to replace "Section Extents"?

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 30 of 37

denisT.MaxDoctor
Advisor
Advisor

@MartinBeh wrote:

 

Out of curiosity:  Would this...

 

 

windows.getchildhwnd #max "Section Extents" 

 

 

... still work in a non-English 3ds Max? Or would one need to find the proper string to replace "Section Extents"?


it searches for window child by caption (title, text) ... so it needs the exact spelling as it is in the localization.

 

But as I mentioned earlier, this has not been changed for more than 20 years. I think we can try to locate it by surrounding the "ColorSwatch dude" and his ID:

  

denisTMaxDoctor_0-1722116513708.png

 

 

 

csw = for c in windows.getchildrenhwnd #max where c[4] == "ColorSwatch" and (uiaccessor.getwindowresourceid c[1] == 0x03F4) do exit with c
h = csw[1] 
for k = 1 to 7 do h = uiaccessor.getnextwindow h
uiaccessor.getwindowtext h

 

 

😁 

 

"ColorSwatch" is a window class name which is always in English

 

Message 31 of 37

MartinBeh
Advisor
Advisor

  
csw = for c in windows.getchildrenhwnd #max where c[4] == "ColorSwatch" and (uiaccessor.getwindowresourceid c[1] == 0x03F4) do exit with c
h = csw[1] 
for k = 1 to 7 do h = uiaccessor.getnextwindow h
uiaccessor.getwindowtext h

 

😁 

 

"ColorSwatch" is a window class name which is always in English

 


Nice! Thanks a bunch!

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 32 of 37

kenc
Advocate
Advocate

@denisT.MaxDoctor I am back to work and I am trying your code from above

kenc_0-1722962641206.png

I drew 2 lines in top view, where the second was drawn from the midpoint of the first. I then extruded both and converted to edit poly

kenc_1-1722962948663.png

You can see in the listener that both p21 and cross have the same position but do not equate the same. But the intersect command says they do intersect.

0 Likes
Message 33 of 37

denisT.MaxDoctor
Advisor
Advisor

If two lines are not equal or parallel and lie in the same plane, they always intersect (at least in Euclidean geometry 😁).

However, line segments can intersect between side points or outside side points.
Continue the math and find the place of intersection: IN or OUT

0 Likes
Message 34 of 37

kenc
Advocate
Advocate

@denisT.MaxDoctor the higher up here has decided that he no longer wants this 'feature'. What a waste of time.

I will continue on this on my own time just out of curiosity.

I thank you for your effort once again.

I will accept your solution.

0 Likes
Message 35 of 37

inquestudios
Enthusiast
Enthusiast

Just align the slice plane to the first face and slice the second one with it.
And leave all matrix math to the eggheads 😁

macroScript alignSlicePlane category:"IN_tools"
 (
  if (classOf $) == Editable_Poly and subobjectLevel==4 do
   (
	selFaceArr = (polyOp.getFaceSelection $) as array
	if selFaceArr.count == 1 do
	 (
	  faceNum = selFaceArr[1]
	  nv = polyOp.getFaceNormal $ faceNum
	  nvp = polyOp.getSafeFaceCenter $ faceNum
	  polyOp.setSlicePlane $ (ray nvp nv) 100
	 )
   )
 )
0 Likes
Message 36 of 37

denisT.MaxDoctor
Advisor
Advisor

@inquestudios wrote:

Just align the slice plane to the first face and slice the second one with it.
And leave all matrix math to the eggheads 😁

 

macroScript alignSlicePlane category:"IN_tools"
 (
  if (classOf $) == Editable_Poly and subobjectLevel==4 do
   (
	selFaceArr = (polyOp.getFaceSelection $) as array
	if selFaceArr.count == 1 do
	 (
	  faceNum = selFaceArr[1]
	  nv = polyOp.getFaceNormal $ faceNum
	  nvp = polyOp.getSafeFaceCenter $ faceNum
	  polyOp.setSlicePlane $ (ray nvp nv) 100
	 )
   )
 )

 


it's like measuring the length of a tail - cut it off and check.

0 Likes
Message 37 of 37

inquestudios
Enthusiast
Enthusiast

@denisT.MaxDoctor wrote:


it's like measuring the length of a tail - cut it off and check.


If you can attach it back without any consequences, why not? 😁
And usually modeler needs face intersection exactly for cutting off chunks and welding along the intersection edge.

0 Likes