# How to determine if two geometry objects intersect

8 messages
Open this post in threaded view
|

## How to determine if two geometry objects intersect

 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 () after each plot. Execute it expecting the return of two variables: ```[fea, geo] = buildAndSliceTest; ```buildAndSliceTest.mTo 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.mSince in the GUI, this condition is caught and an error window raised, I am encouraged that there is a solution. Kind regards, Randal
Open this post in threaded view
|

## Re: How to determine if two geometry objects intersect

 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).
Open this post in threaded view
|

## Re: How to determine if two geometry objects intersect

 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
Open this post in threaded view
|

## Re: How to determine if two geometry objects intersect

 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.mI 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
Open this post in threaded view
|

## Re: How to determine if two geometry objects intersect

Open this post in threaded view
|

## Re: How to determine if two geometry objects intersect

 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.mHere 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