ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem using intersectWith

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
cadproman
1450 Views, 6 Replies

Problem using intersectWith

I am having a problem using the intersectWith function to return an intersection between a circle and line, both of which are AcGe class objects. Can someone please point me in the right direction? The relevant code is below. Also, any pointers on anything else that is done incorrectly would be appreciated. I am trying to basically draw a circle, then draw a leader from the center to a chosen point, then finally draw two lines starting at the leader tip back to the circle, 90 degrees around to each side from where the leader intersects it. The problem is that it does not find any intersection points and draws instead to the origin.

 

TIA,

Ralph

 

		// Create the circle
		double const Pi = 3.14159265358979;
		AcGePoint3d centerPt;				// center point of brace circle
		AcDbCircle* pBraceCircle;			// pointer to brace circle
		if(acedGetPoint(NULL, _T("\nSpecify brace point on roof: "), asDblArray(centerPt)))
		{
			float radius(4.5);				// circle radius
			pBraceCircle = new AcDbCircle(centerPt, AcGeVector3d::kZAxis, radius);
			// Add the circle to database and close it
			addToModelSpace(pBraceCircle);
			pBraceCircle->close();
		}

		// Create the leader
		AcGePoint3d supportPt;				// point on wall or beam
		if(acedGetPoint(asDblArray(centerPt), _T("\nSpecify support point for brace: "), asDblArray(supportPt)))
		{
			AcDbLeader* pLeader = new AcDbLeader();
			// add the leader to database and then close it
			addToModelSpace(pLeader);
			pLeader->appendVertex(supportPt);
			pLeader->appendVertex(centerPt);
			pLeader->close();
		}

		// Create the lines connecting the leader tip to the circle sides
		// convert the 3d points at brace and support points to 2d
		AcGePoint2d supportPt2d(supportPt.x, supportPt.y);
		AcGePoint2d centerPt2d(centerPt.x, centerPt.y);
		
		// get a construction line in direction of leader and rotate 90 degrees
		AcGeLineSeg2d geBraceLine(supportPt2d, centerPt2d);
		AcGeLine2d gePerpLine;
		geBraceLine.getPerpLine(supportPt2d, gePerpLine);
		gePerpLine.rotateBy(Pi/2, centerPt2d);
		

		// get a construction circle over brace circle
		// find intersections with construction circle and line
		AcGeCircArc2d geBraceCircle(centerPt2d, 4.5);
		int intN;									// number of intersections
		AcGePoint2d intersPt1, intersPt2;			// intersecting points
		geBraceCircle.intersectWith(gePerpLine, intN, intersPt1, intersPt2);
		
		// create the first line, add to database and close
		AcGePoint3d StartPt1( intersPt1.x, intersPt1.y, 0);
		AcDbLine* pBraceLine1 = new AcDbLine(StartPt1, supportPt);
		addToModelSpace(pBraceLine1);
		pBraceLine1->close();
		
		// create the second line, add to database and close
		AcGePoint3d StartPt2( intersPt2.x, intersPt2.y, 0);
		AcDbLine* pBraceLine2 = new AcDbLine(StartPt2, supportPt);
		addToModelSpace(pBraceLine2);
		pBraceLine2->close();

 

6 REPLIES 6
Message 2 of 7
3wood
in reply to: cadproman

Sorry I didn't read your code but just a thought: ensure the line and the circle has the same extrusion direction. You can set the UCS to line ECS before drawing the circle.

 

3wood

CAD KITS

Message 3 of 7
Anonymous
in reply to: cadproman

Is this line neccessary "geBraceLine.getPerpLine(supportPt2d, gePerpLine)"? Could it leave the line outside the circle?

 

Try some version of the following it may be easier to debug.

 

AcDbLine geBraceLine(AcGePoint3d(-2,0,0), AcGePoint3d(2,0,0));

 

AcGeMatrix3d xform1;

xform1.setToRotation(UtilsGe::kRad90, AcGeVector3d::kZAxis, AcGePoint3d(0,0,0));

geBraceLine.transformBy(xform1);

 

AcGePoint3d startPt = geBraceLine.startPoint();

AcGePoint3d endPt = geBraceLine.endPoint();

 

AcDbLine gePerpLine(startPt, endPt);

 

// get a construction circle over brace circle

// find intersections with construction circle and line

AcDbCircle geBraceCircle(AcGePoint3d(0,0,0),AcGeVector3d::kZAxis, 1);

AcGePoint3dArray points;

geBraceCircle.intersectWith(&gePerpLine, AcDb::kOnBothOperands, points);

 

for(int i=0; i<points.length(); i++)

{

      CString str;

      ptToStr(points[i], str);

      acutPrintf(L"\n %s", str);

}

 

Regards,

Shane.

Message 4 of 7
cadproman
in reply to: Anonymous

Thank you both for the replies. Shane, I used the AcDb lines instead of the AcGe ones and that seemed to correct the issue. I guess I'll have to play around with the AcGe objects for a while before I understand them. I can't seem to get anything useful out of the debugger - just hexadecimal information. I am interested in the ptToStr function you called, though. I don't seem to have that one. Is that something "new"? (I'm still on AutoCAD 2008 until I get all of my old VBA code updated.)

 

Thanks again,

Ralph

Message 5 of 7
Anonymous
in reply to: cadproman

Ralph, 

 

Have a look at the ARXDBG project in samples/database. You will find ptToStr in ArxDbgUtils.h along with a great deal other useful functions. If you import ArxDbgUtils into your project it will simplify many common tasks. Also I find the ArxDbgUiPr... classes very useful for simplifying user interaction. 

 

Regards,

Shane.

 

Message 6 of 7
Anonymous
in reply to: Anonymous

I use objectarx2012, cad 2012.  i've tesed intersectWith function. Here's code :
static void Test(void){
    AcDbObjectId oId;
    AcArray<AcGePoint3d> IntersectionPoints;
    ads_name name1, name2;        AcDbEntity *pEnt1,*pEnt2;
        ////<<<<<<<<<<<<<<<<<<////////////////////
    acedEntSel(L"\nSelect Ent1(line1 😞 ",name1,pt);    acdbGetObjectId(oId, name1);    acdbOpenAcDbEntity(pEnt1,oId,AcDb::kForRead);
    acedEntSel(L"\nSelect Ent2(line1 😞 ",name2,pt);    acdbGetObjectId(oId, name2);    acdbOpenAcDbEntity(pEnt2,oId,AcDb::kForRead);
    pEnt1->intersectWith(pEnt2,AcDb::kOnBothOperands ,AcGePlane::kXYPlane, IntersectionPoints,    0,0 );    //May be this line cause error!
    pEnt1->close(); pEnt2->close();
// //  Autocad crashed when go out this
}

Autocad crashed when Test ended.
Can AnyOne help me?
Thank advance.

Message 7 of 7
owenwengerd
in reply to: Anonymous

Please start a new thread, and include more information. "AutoCAD crashed" is not enough detail.

--
Owen Wengerd
ManuSoft

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost