Sphere/Radius Check

Sphere/Radius Check

allan.moraes
Contributor Contributor
669 Views
4 Replies
Message 1 of 5

Sphere/Radius Check

allan.moraes
Contributor
Contributor

Hey guys,

I'm trying to make a sphere check/circle check using a given object transform position and the radius of the sphere/circle. Does Revit API has anything to help me with that?

 

I was first looking for something close to what Unity has: https://docs.unity3d.com/ScriptReference/Physics.CheckSphere.html, however I'm open for other possibilities.

 

Thanks,

0 Likes
Accepted solutions (1)
670 Views
4 Replies
Replies (4)
Message 2 of 5

RPTHOMAS108
Mentor
Mentor

From the attached link the description reads:

"Returns true if there are any colliders overlapping the sphere defined by position and radius in world coordinates."

 

My suggestion is therefore:

https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-detect-an-object-on-some-specific-d...

 

Message 3 of 5

Omar_Amen
Advocate
Advocate
Accepted solution

Hi @allan.moraes,
Revit API doesn't have a powerful physics engine like the Unity Phisx,
but at least it can detect collision/clashing between 3D elements,
so you can make a parametric sphere Revit family .rfa, then you can specify the placement point and the sphere diameter parameter then check the collision between the sphere family element and the other elements using ElementIntersectsElementFilter
then delete the sphere after the check.

0 Likes
Message 4 of 5

allan.moraes
Contributor
Contributor

Hi guys,

 

I tried to implement both ways on the code. One using ElementIntersectsElementFilter and ElementIntersectsSolidFilter. Only ElementIntersectsElementFilter worked for me while using a pre-created sphere family and instancing it on the point desired. However I feel that not having to work with Transactions might improve performance a bit.

 

Thank you @Omar_Amen for the idea.

 

@RPTHOMAS108 I think that there's something missing to get ElementIntersectsSolidFilter working.

Here's my code:

private Solid Sphere(XYZ center, double radius)
        {
            List<Curve> profile = new List<Curve>();
            XYZ profilePlus = center + new XYZ(0, radius, 0);
            XYZ profileMinus = center - new XYZ(0, radius, 0);

            profile.Add(Line.CreateBound(profilePlus, profileMinus));
            profile.Add(Arc.Create(profileMinus, profilePlus, center + new XYZ(radius, 0, 0)));

            CurveLoop curveLoop = CurveLoop.Create(profile);
            SolidOptions options = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);

            Frame frame = new Frame(center, XYZ.BasisX, -XYZ.BasisZ, XYZ.BasisY);
            if (Frame.CanDefineRevitGeometry(frame) == true)
            {
                Solid sphere = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curveLoop }, 0, 2 * Math.PI, options);
                return sphere;
            }
            return null;
        }
        private bool SphereCheck(Solid sphere, FamilyInstance fi)
        {
            ElementIntersectsSolidFilter intersect = new ElementIntersectsSolidFilter(sphere);
            bool result = intersect.PassesFilter(fi);
            return result;
        }

 I run first Sphere to get the solid using a LocationPoint from a FamilyInstance, then pass another FamilyInstance with the sphere Solid to check it's intersection.

 

Thanks guys

Message 5 of 5

RPTHOMAS108
Mentor
Mentor

Your code looks ok and works ok for me.

 

Perhaps you need to provide more details about the type of family instances you are using. If you include a sample file then I can check against that. Does your family instance contain nested shared components etc? It may help to plot the sphere as a direct shape in order to determine if the location point being used is as you expect.

 

I've conducted a simple check on a structural column using an adjacent detail arc on a central level to provide centre and radius of the sphere. I see no reason to need transactions for this task.

 

0 Likes