How to determine if two geometry objects intersect

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to determine if two geometry objects intersect

randress
This post was updated on .
Before combining objects from/in a script, e.g.:
g = geom_apply_formula( g, 'S1-B5' );
... I'd like to determine that the objects (S1, and B5 in the example) do not intersect (nor that one wholly contains the other), so that the operation would be expected to succeed.
 
Is there a function which determines whether two geometry objects intersect? Such as:

"objects_intersect (GOBJ1, GOBJ2)" returning true or false.

More specifically, is there a function that determines whether a block object, B1, intersects another object  O1 (or wholly contains it), so that O1-B1 is a valid operation?

If not, how could this be determined? Or how could the subtraction be done and then checked for success without disturbing/modifying the objects or crashing ?

Background:
As noted before I need to be able to create a planar boundary through part(s) of a model so that I may integrate the current density over it.

When the model contains more than one or two objects/subdomains, for some reason, I am finding this a tedious and error prone task. So I and am trying to build a script(s) that will assist me.

The idea is that once you specify an axis-perpendicular plane and location, each object in the model is duplicated in-place, and a pair of blocks - which together enclose the entire model and that share a face which is coincident with the desired 'cut plane'. Then one block is subtracted from each object and its mate from the object's copy.  

However, since you can't subtract objects which do not overlap (or where one object contains another?), it is necessary to detect any objects which do not overlap (or which are completely subsumed by) one of the the enclosing 'half-blocks'.

It seems best to check before the attempt to subtract, but so long as a detectable and recoverable error is produced when the convention is violated, it could be checked after the fact.

Here is a script that builds and attempts to split (at x=0.5) a model consisting of a Block (B1) whose corner is at (0,0,0) and two spheres S1 and S2, one at B1's center and another smaller one that is very near the B1 x=0 face. It seems to work as desired until it encounters S2 which does not intersect one of the splitting blocks and is wholly contained in the other.  Neither subtraction works, and one of them causes a crash in GEOMTool. The script pauses for user input (<Enter>) after each plot.
Execute it expecting the return of two variables:

[fea, geo] = buildAndSliceTest;

buildAndSliceTest.m

To in investigate this issue (non intersection and wholly contained) further, I created another script which constructs two blocks, first with them not intersecting and then with one inside the other. In both cases a subtraction is attempted.  Neither works, and surprisingly (based on the first script's behavior - it crashes GEOMTool), in neither case is an error raised or crash encountered.

test_non_intersecting.m

Since in the GUI, this condition is caught and an error window raised, I am encouraged that there is a solution.

Kind regards,
Randal

Reply | Threaded
Open this post in threaded view
|

Re: How to determine if two geometry objects intersect

Precise Simulation
Administrator
It is in general more or less as costly to check for intersections as to actually perform them, at least with a moderate degree of accuracy, so there is therefore no stand-alone intersection check functionality. You can of course completely exclude intersecting objects by using bounding boxes (but a negative does not necesarily mean they actually do intersect).

In your case you might be better served with a dedicated/professional CAD tool which in most cases would include cut plane tooling (you can import/export CAD geometries from FEATool in several formats).
Reply | Threaded
Open this post in threaded view
|

Re: How to determine if two geometry objects intersect

Precise Simulation
Administrator
In reply to this post by randress
Regarding your script, I can't observe any crashes only that the last operation

    [g,stat] = geom_apply_formula( g, 'S4-B8' );

fails, which is to be exected since S4 is completely contained withing B8. Note that you can use the optional stat output variable to see if the operation succeeded or not

https://www.featool.com/doc/geom__apply__formula_8m.html
Reply | Threaded
Open this post in threaded view
|

Re: How to determine if two geometry objects intersect

randress
Precise Simulation wrote
Regarding your script, I can't observe any crashes only that the last operation
Hmmm... Here is what I get.  



I apologize for the awkward use of "pause;".  You might comment out the occurrences of pause and see if that makes any difference.  I have made that change in this version:

buildAndSliceTest_nopause.m

I will investigate this more and attempt to isolate the crash (or find my error:-)

Precise Simulation wrote
Note that you can use the optional stat output variable to see if the operation succeeded or not

https://www.featool.com/doc/geom__apply__formula_8m.html

    [g,stat] = geom_apply_formula( g, 'S4-B8' );
Thanks for pointing out the stat return variable. I completely missed that. I don't see why that would not do nicely.  I will give it at try.

Kind regards,
Randal



Reply | Threaded
Open this post in threaded view
|

Re: How to determine if two geometry objects intersect

randress
This post was updated on .
In reply to this post by Precise Simulation
[Please accept my apologies for the mistake in this post.  I have just edited it to include the second script instead of the duplication of the first one.  I do not believe it changes anything as far as your responses but I wanted to correct it.-Randal]

Precise Simulation wrote
It is in general more or less as costly to check for intersections as to actually perform them, at least with a moderate degree of accuracy, so there is therefore no stand-alone intersection check functionality.
Ok. That works for me. So long as a failed subtraction does not alter the geometry object.

Precise Simulation wrote
You can of course completely exclude intersecting objects by using bounding boxes (but a negative does not necesarily mean they actually do intersect).
Can you please explain this more? I am not quite sure how to ask for a specific clarification.  I fear that I have missed something very important.  Speaking of "bounding boxes" I have wondered if there is a way to determine what "box" would completely enclose a model. Is there a script/function that will generate this "bounding box"? But in any case, how would they be used to help me here? Sorry to be so dense :-(

Precise Simulation wrote
In your case you might be better served with a dedicated/professional CAD tool which in most cases would include cut plane tooling (you can import/export CAD geometries from FEATool in several formats).
I have considered and attempted this approach without much success. I am learning to use Autodesk Fusion 360 and exporting STEP files.  Would you recommend a different format?  a different CAD tool? I will take another look at building the model elsewhere...

But I am curious as to why you would recommend against the use of a script which duplicates the model and subtracts enclosing block-pairs that share the cut-plane.  Is the approach not a sound one?  Or perhaps it might turn out to be beyond my novice MATLAB script's-manship, needing more than your occasional helpful nudges :-)

With thanks for you help and suggestions ...

Kind regards,
-Randal
Reply | Threaded
Open this post in threaded view
|

Re: How to determine if two geometry objects intersect

randress
In reply to this post by randress
The GEOMTool crash persists for me (Windows 7).  

I have trimmed it down to the creation of a sphere and a block and the S1-B1 operation.  If this executes for you without error, I will continue to investigate.

GEOMToolCrash.m

Here is the error window I get:



... with the details:

Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	geomtool.exe
  Application Version:	0.0.0.0
  Application Timestamp:	5f02c6b2
  Fault Module Name:	geomtool.exe
  Fault Module Version:	0.0.0.0
  Fault Module Timestamp:	5f02c6b2
  Exception Code:	c0000005
  Exception Offset:	000000000053e8b5
  OS Version:	6.1.7601.2.1.0.256.48
  Locale ID:	1033
  Additional Information 1:	6000
  Additional Information 2:	6000db3d2ddbe6447296a230b630da2b
  Additional Information 3:	575a
  Additional Information 4:	575a59206b7fc181923e53d62d7bc413

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt

... and in the Command Window:
>> GEOMToolCrash
stat: 3

I do hope we are not into some configuration problem on my end....

As always, thanks and ...

Kind regards,
Randal

Reply | Threaded
Open this post in threaded view
|

Re: How to determine if two geometry objects intersect

Precise Simulation
Administrator
Thank you for reporting, it seems it was an issue with older versions of Windows. I have pushed an update that should address it (build 20.07.203).
Reply | Threaded
Open this post in threaded view
|

Re: How to determine if two geometry objects intersect

randress
And thank you very much for the fix!
-Randal