Projecting circle on torus

Technical discussions
Post Reply
Anthony Dubois
Posts: 2
Joined: Mon Sep 21, 2020 4:46 am

Projecting circle on torus

Post by Anthony Dubois »

Hello.
Anybody knows how to use IUVSurface_DG.GetCurveProjection()? The documentation has no comments. I need to construct a face by projecting a curve on a torus. A circle for a start would be good.
I would greatly appreciate few hints or few lines of code
Thank you

Prashant Kande
Posts: 121
Joined: Mon Apr 04, 2016 4:55 am

Re: Projecting circle on torus

Post by Prashant Kande »

Hi Anthony

This seems to be working:

Code: Select all

	public void TestCurveToTorusProjection3()
        {
            IStdShape_DG iStdShape = m_iGener.Create("StdShape_DG") as IStdShape_DG;
            double R = 10;
            double r = 3;
            IEntity_DG iEnt = iStdShape.Torus(R, r);
            m_iModel.AddEntity(iEnt);
            IBRepGeometry_DG iGeomBRep = iEnt as IBRepGeometry_DG;
            IBRepShape_DG iShape = iGeomBRep.GetShape();
            ShapeType_DG type = iShape.GetShapeType();
            Debug.Assert(type == ShapeType_DG.eShTypeSolidDG);
            IShapeArray_DG faces = iShape.GetSubShapes(ShapeType_DG.eShTypeFaceDG);
            IBRepFace_DG iFace = faces.GetAt(0) as IBRepFace_DG;
            IUVSurface_DG iSurface = iFace.GetSurface();
            ESurfaceType_DG typeSurf = iSurface.GetSurfaceType();
            Debug.Assert(typeSurf == ESurfaceType_DG.eSurfTypeTorus);

            // Circle at the origing with z axis as its axis
            IEntity_DG iEntCircle = iStdShape.Circle(r);
            IBRepGeometry_DG iGeomBRepCircle = iEntCircle as IBRepGeometry_DG;
            IBRepShape_DG iShapeCircle = iGeomBRepCircle.GetShape();
            ShapeType_DG type2 = iShapeCircle.GetShapeType();
            Debug.Assert(type2 == ShapeType_DG.eShTypeEdgeDG);
            IBRepEdge_DG edge = iShapeCircle as IBRepEdge_DG;
            ICurve_DG iCurve = edge.GetCurve();

            // Translate the circle forward by sphere radius and up (y) byt R+r
            // The circle is defined in the local frame of iEntCircle and does not have a frame by itself
            // So we have to change the geometry
            // The iEntCircle.GetLocation().Translate1(0, 0, R); above translated the entity, but not the curve 
            // inside WRT the local frame. iEntCircle was translated to show the location of the translated curve in 3D
            IGeometricObject_DG iCircleGeomObj = iCurve as IGeometricObject_DG;
            iCircleGeomObj.Translate1(0, R + r, R);

            ICurve_DG iCurveProjected = iSurface.GetCurveProjection(iCurve);

            IView iView = m_kernCAD.GetView();
            IScene_DG iScene = iView as IScene_DG;
            iScene.CreatePresentationEntity(iCurveProjected as IObject_DG, true, null);

            iView.Reset(true);      // Refit
        }
Result:
TorusTop.png
TorusTop.png (88.12 KiB) Viewed 4140 times
But the same with the initial circle shifted to the right ( change iCircleGeomObj.Translate1(0, R + r, R); to iCircleGeomObj.Translate1(R + r, 0, R);) has a problem:
TorusRight.png
TorusRight.png (95.17 KiB) Viewed 4140 times
We are looking at it. It seems to be OCCT problem. We will see what we can do about it.

Meanwhile try rotating the torus before the operation

Regards

Anthony Dubois
Posts: 2
Joined: Mon Sep 21, 2020 4:46 am

Re: Projecting circle on torus

Post by Anthony Dubois »

Thank you, Prashant
It works in my case
Regards

Post Reply