I can in 2d, but in 3d not working (after setting ECS by 3dface)...
Any idea?
Thanks.
Pepa
Solved! Go to Solution.
Solved by PEPANOVAK. Go to Solution.
Solved by owenwengerd. Go to Solution.
Please don't use the phrase "not working" in a technical forum, as it is not helpful to those wanting to assist you. Best to show your code, describe what you did and the context you did it in, what you expected to happen, and what actually happened.
Owen, I have a 3D triangular network (TIN) and I need to hatch the individual triangles in 3D. I'm trying to use acdbhatch, but I'm doing it only in 2D.
The idea was to set the ECS by the triangle and then transform hatch.originPoint () to the ECS, but originPoint () returns zero coordinates...
It is strange that the editor 3d hatch manually creates (ECS set up by the object, run the command HATCH a show point inside)...
I would use acdbhatch due to the gradient. The lowest point of the network to differentiate from the highest.
@PEPANOVAK wrote:Owen, I have a 3D triangular network (TIN) and I need to hatch the individual triangles in 3D. I'm trying to use acdbhatch, but I'm doing it only in 2D.
The idea was to set the ECS by the triangle and then transform hatch.originPoint () to the ECS, but originPoint () returns zero coordinates...
It's difficult to guess what the problem is without seeing your code.
AcDbMpolygon also not drawn correctly in 3D...
// A,B,C is AcGePoint3d
for (Adesk::UInt32 i=0; i < numFaces; i++) {
trig=sezT[i];
A=trig.pointA;
B=trig.pointB;
C=trig.pointC;
Z1=min(min(A.z,B.z),min(B.z,C.z));
//Z3=max(max(A.z,B.z),max(B.z,C.z));
krok=(int) Z1 / elev;
AcGePlane plane(A,B,C);
// normal=plane.normal();
// normal.normalize();
// AcGeVector3d normalX(0,0,1);
AcDbMPolygon *pPol = new AcDbMPolygon();
AcGePoint2dArray parr;
AcGeDoubleArray bulges;
bulges.append(0.0);
bulges.append(0.0);
bulges.append(0.0);
bulges.append(0.0);
setECSasUCS(plane);
bod[0]=A.x; bod[1]=A.y; bod[2]=A.z;
acedTrans(bod,&fromrb,&torb,0,bodtrans);
A2.x=bodtrans[0];
A2.y=bodtrans[1];
bod[0]=B.x; bod[1]=B.y; bod[2]=B.z;
acedTrans(bod,&fromrb,&torb,0,bodtrans);
B2.x=bodtrans[0];
B2.y=bodtrans[1];
bod[0]=C.x; bod[1]=C.y; bod[2]=C.z;
acedTrans(bod,&fromrb,&torb,0,bodtrans);
C2.x=bodtrans[0];
C2.y=bodtrans[1];
parr.append(A2);
parr.append(B2);
parr.append(C2);
parr.append(A2);
pPol->appendMPolygonLoop(parr,bulges,FALSE);
//pPol->setNormal(normal);
pPol->setPattern(AcDbHatch::kPreDefined, _T("SOLID"));
pPol->evaluateHatch();
addToModelSpace(eId,pPol);
}
You will need to call setNormal() and setElevation() at minimum, and those are best set *before* adding vertices. It's difficult to determine just from looking at the code, but I think there are flaws in your math. Also, I'm not sure what setECSasUCS(plane) is for.
Owen: If I set the setNormal() of values of triangle plane, so my hatch draw completely outside...If I set the setNormal(0,0,1), so my hatch draw in 2d...
Here is code...
for (Adesk::UInt32 i=0; i < numFaces; i++) {
trig=sezT[i];
A=trig.pointA;
B=trig.pointB;
C=trig.pointC;
AcGePlane plane(A,B,C);
normal=plane.normal();
//normal.normalize();
AcGeVector3d normalX(0,0,1);
AcDbMPolygon *pPol = new AcDbMPolygon();
AcGePoint2dArray parr;
AcGeDoubleArray bulges;
bulges.append(0.0);
bulges.append(0.0);
bulges.append(0.0);
bulges.append(0.0);
//AcGeMatrix3d mat=SetECSasUCS(plane);
parr.append(AcGePoint2d(A.x,A.y));
parr.append(AcGePoint2d(B.x,B.y));
parr.append(AcGePoint2d(C.x,C.y));
parr.append(AcGePoint2d(A.x,A.y));
pPol->setNormal(normal);
pPol->setElevation(0.0);
pPol->appendMPolygonLoop(parr,bulges,FALSE);
pPol->setPattern(AcDbHatch::kPreDefined, _T("SOLID"));
pPol->evaluateHatch();
addToModelSpace(eId,pPol);
}
Here is code that works correctly for AcDbHatch in AutoCAD 2010 and AutoCAD 2015. When I tested in AutoCAD 2010, AcDbMPolygon returned an incorrect matrix from getEcs(). AcDbMPolygon::getEcs() works correctly in AutoCAD 2015, so apparently the bug has since been fixed.
AcGePoint3d ptA(3,4,5); AcGePoint3d ptB(4,5,6); AcGePoint3d ptC(2,2,2); AcGePlane planeTarget(ptA, ptB, ptC); AcGeVector3d vecNormal = planeTarget.normal(); double dElevation = AcGePoint3d::kOrigin.distanceTo(AcGePoint3d::kOrigin.orthoProject(planeTarget)); AcDbHatch* pHatch = new AcDbHatch(); Acad::ErrorStatus es = pHatch->setElevation(dElevation); assert(es==Acad::eOk); es = pHatch->setNormal(vecNormal); assert(es==Acad::eOk); AcGeMatrix3d mxECS; pHatch->getEcs(mxECS); mxECS.invert(); AcGePoint2d pt2A = ptA.transformBy(mxECS).convert2d(AcGePlane::kXYPlane); AcGePoint2d pt2B = ptB.transformBy(mxECS).convert2d(AcGePlane::kXYPlane); AcGePoint2d pt2C = ptC.transformBy(mxECS).convert2d(AcGePlane::kXYPlane); AcGePoint2dArray rpt2Loop; rpt2Loop.append(pt2A); rpt2Loop.append(pt2B); rpt2Loop.append(pt2C); rpt2Loop.append(pt2A); es = pHatch->appendLoop(AcDbHatch::kExternal, rpt2Loop, AcGeDoubleArray()); assert(es==Acad::eOk); es = pHatch->setPattern(AcDbHatch::kPreDefined, ACRX_T("SOLID")); assert(es==Acad::eOk); es = pHatch->evaluateHatch(); assert(es==Acad::eOk); AcDbBlockTableRecord* pSpace = NULL; if (Acad::eOk == acdbOpenObject(pSpace, acdbCurDwg()->currentSpaceId(), AcDb::kForWrite)) { es = pSpace->appendAcDbEntity(pHatch); assert(es==Acad::eOk); pSpace->close(); pHatch->close(); } else delete pHatch;
I ran into a problem with some triangles (like this one). Draw somewhere outside.
-56.36 44.44 87.11
-74.20 33.40 86.03
-56.34 22.83 101.75
All triangles is CCW...
Do you have any idea Owen?
Thanks.
Pepa
What exactly is the problem? Error status returned? Wrong location?
Wrong location. Picture is attached...
I've found that it depends on the order of vertex of a triangle, but I could not find the logic.
Thanks.
In the pictures are triangles with vertices CW and CCW...
Sorry, but I'm not going to debug your code for you. Show us some test code that demonstrates where and how it is failing with CW and CCW triangles. I'd start with the normal vector.
So I found a mistake 🙂
double dElevation = AcGePoint3d::kOrigin.distanceTo(AcGePoint3d::kOrigin.orthoProject(planeTarget));
It is wrong, only returns a positive value.
I wrote a custom function to calculate the distance from the plane and already it works...