PlannerRoad
Guest
su through the interface c# code is available for the compilation of a utility that allows you to simultaneously create a polyhedral mesh from a set of 3d points.
the code, reported qui, is the following:
the command of the utility is Home.
how to fill out the code: in this debate visual c#: fill out the code for autocad I explained the procedure and indicated the software for compiling c#.
after uploading the utility with the netload command, giving the triang command you can select a set of 3d points and, from the triangulation of these, get the polyhedra mesh.
I attach the code I compiled.
the code, reported qui, is the following:
PHP:
using autodesk.autocad.applicationservices;
using autodesk.autocad.databaseservices;
using autodesk.autocad.runtime;
using autodesk.autocad.editorinput;
using autodesk.autocad.geometry;
using system;
public class triangulate
{
public bool circum(
double x1, double y1, double x2,
double y2, double x3, double y3,
ref double xc, ref double yc, ref double r)
{
// calculation of circumscribed circle coordinates and
// squared radius
const double eps = 1e-6;
const double big = 1e12;
bool result = true;
double m1, m2, mx1, mx2, my1, my2, dx, dy;
if ((math.abs(y1 - y2) < eps) && (math.abs(y2 - y3) < eps))
{
result = false;
xc = x1; yc = y1; r = big;
}
else
{
if (math.abs(y2 - y1) < eps)
{
m2 = -(x3 - x2) / (y3 - y2);
mx2 = (x2 + x3) / 2;
my2 = (y2 + y3) / 2;
xc = (x2 + x1) / 2;
yc = m2 * (xc - mx2) + my2;
}
else if (math.abs(y3 - y2) < eps)
{
m1 = -(x2 - x1) / (y2 - y1);
mx1 = (x1 + x2) / 2;
my1 = (y1 + y2) / 2;
xc = (x3 + x2) / 2;
yc = m1 * (xc - mx1) + my1;
}
else
{
m1 = -(x2 - x1) / (y2 - y1);
m2 = -(x3 - x2) / (y3 - y2);
if (math.abs(m1 - m2) < eps)
{
result = false;
xc = x1;
yc = y1;
r = big;
}
else
{
mx1 = (x1 + x2) / 2;
mx2 = (x2 + x3) / 2;
my1 = (y1 + y2) / 2;
my2 = (y2 + y3) / 2;
xc = (m1 * mx1 - m2 * mx2 + my2 - my1) / (m1 - m2);
yc = m1 * (xc - mx1) + my1;
}
}
}
dx = x2 - xc;
dy = y2 - yc;
r = dx * dx + dy * dy;
return result;
}
[CommandMethod("TRIANG")]
public void triangulatecommand()
{
const int maxpoints = 32767;
document doc =
application.documentmanager.mdiactivedocument;
database db = doc.database;
editor ed = doc.editor;
typedvalue[] tvs = { new typedvalue(0, "point") };
selectionfilter sf =
new selectionfilter(tvs);
promptselectionoptions pso = new promptselectionoptions();
pso.messageforadding = "select points:";
pso.allowduplicates = false;
promptselectionresult psr = ed.getselection(pso, sf);
if (psr.status == promptstatus.error) return;
if (psr.status == promptstatus.cancel) return;
selectionset ss = psr.value;
int npts = ss.count;
if (npts < 3)
{
ed.writemessage("minimum 3 points must be selected!");
return;
}
if (npts > maxpoints)
{
ed.writemessage("maximum nuber of points exceeded!");
return;
}
int i, j, k, ntri, ned, status1 = 0, status2 = 0;
bool status;
// point coordinates
double[] ptx = new double[maxpoints + 3];
double[] pty = new double[maxpoints + 3];
double[] ptz = new double[maxpoints + 3];
// triangle definitions
int[] pt1 = new int[maxpoints * 2 + 1];
int[] pt2 = new int[maxpoints * 2 + 1];
int[] pt3 = new int[maxpoints * 2 + 1];
// circumscribed circle
Double[] cex = new double[maxpoints * 2 + 1];
double[] cey = new double[maxpoints * 2 + 1];
double[] rad = new double[maxpoints * 2 + 1];
double xmin, ymin, xmax, ymax, dx, dy, xmid, ymid;
int[] ed1 = new int[maxpoints * 2 + 1];
int[] ed2 = new int[maxpoints * 2 + 1];
objectid[] idarray = ss.getobjectids();
transaction tr =
db.transactionmanager.starttransaction();
using (tr)
{
dbpoint ent;
k = 0;
for (i = 0; i < npts; i++)
{
ent =
(dbpoint)tr.getobject(idarray[k], openmode.forread, folded);
ptx[i] = depreciation[0];
pty[i] = depreciation[1];
ptz[i] = depreciation[2];
For (j = 0; m <; j+)
if[i] == ptx[j]) & (pty[i] == pty[j]))
{
i--; npts--; status2++;
}
k++;
}
tr.commit();
}
if (status2 > 0)
ed.writemessage(
"\nignored {0} point(s) with same coordinates.",
status2
);
// supertriangle
xmin = ptx[0]xmax = xmin;
= Pty[0]; ymax = ymin;
for (i = 0; i < npts; i++)
{
if (ptx[i] < xmin = ptx[i];
if (ptx[i] > xmax = ptx[i];
if (pty[i] < xmin) ymin = pty[i];
if (pty[i] > xmin) ymax = pty[i];
}
dx = xmax - xmin; dy = ymax - ymin;
xmid = (xmin + xmax) / 2; ymid = (ymin + ymax) / 2;
i = npts;
ptx[i] = xmid - (90 * (dx + dy)) - 100;
pty[i] = ymid - (50 * (dx + dy)) - 100;
ptz[i] = 0;
pt1[0] = i;
i++;
ptx[i] = xmid + (90 * (dx + dy)) + 100;
pty[i] = ymid - (50 * (dx + dy)) - 100;
ptz[i] = 0;
pt2[0] = i;
i++;
ptx[i] = xmid;
pty[i] = ymid + 100 * (dx + dy + 1);
ptz[i] = 0;
pt3[0] = i;
tri = 1;
circum (
ptx[pt1[0]], pty[pt1[0]], ptx[pt2[0]],
pty[pt2[0]], ptx[pt3[0]], pty[pt3[0]],
ref cex[0], ref cey[0], ref rad[0]
);
// main loop
for (i = 0; i < npts; i++)
{
ned = 0;
xmin = ptx[i]; ymin = pty[i];
j = 0;
(j < tri)
{
dx = cex[j] - xmin; dy = cey[j] - ymin;
if (((dx * dx) + (dy * dy)) < rad[j])
{
ed1[ned] = pt1[j]; ed2[ned] = pt2[j];
ned++;
ed1[ned] = pt2[j]; ed2[ned] = pt3[j];
ned++;
ed1[ned] = pt3[j]; ed2[ned] = pt1[j];
ned++;
_
pt[j] = pt1[ntri];
pt2[j] = pt2[ntri];
pt3[j] = pt3[ntri];
cex[j] = cex[ntri];
cey[j] = cey[ntri];
rad[j] = wheel[ntri];
j--;
}
j++;
}
for (j = 0; j < down - 1; j++)
for (k = j + 1; k < down; k++)
((ed1[j] == ed2[k]) && (ed2[j] == ed1[k]))
{
ed1[j] = -1; ed2[j] = -1; ed1[k] = -1; ed2[k] = -1;
}
for (j = 0; j < down; j++)
((ed1[j] >= 0) && (ed2[j] > = 0))
{
pt1[ntri] = ed1[j]; pt2[ntri] = ed2[j]; pt3[ntri] = i;
status =
circum(
ptx[pt1[ntri]], pty[pt1[ntri]], ptx[pt2[ntri]],
pty[pt2[ntri]], ptx[pt3[ntri]], pty[pt3[ntri]],
ref cex[ntri], ref cey[ntri], ref rad[ntri]
);
if (!status)
{
status1++;
}
ntri++;
}
}
// removal of outer triangles
i = 0;
while (i < ntri)
{
if ((pt1[i] > npts)[i] > npts)[i] >= npts)
{
ntri--;
pt1[i] = pt1[ntri];
pt2[i] = pt2[ntri];
pt3[i] = pt3[ntri];
cex[i] = cex[ntri];
cey[i] = cey[ntri];
rad[i] = wheel[ntri];
i--;
}
i++;
}
tr = db.transactionmanager.starttransaction();
using (tr)
{
blocktable bt =
(blocktable)tr.getobject(
db.blocktableid,
openmode.forread,
false
);
blocktablerecord btr =
(blocktablerecord)tr.getobject(
bt[BlockTableRecord.ModelSpace],
openmode.forwrite,
false
);
polyfacemesh pfm = new polyfacemesh();
btr.appendentity(pfm);
tr.addnewlycreateddbobject(pfm, true);
for (i = 0; i < npts; i++)
{
polyfacemeshvertex vert =
new polyfacemeshvertex(
new point3d(ptx[i], pty[i], pt[i])
);
pfm.appendvertex(vert);
tr.addnewlycreateddbobject(vert, true);
}
for (i = 0; i < ntri; i++)
{
facerecord face =
new facerecord(
(short)(pt1[i] + 1,
(Applause)[i] + 1,
(Applause)[i] + 1),
0
);
pfm.appendfacerecord(face);
tr.addnewlycreateddbobject(face, true);
}
tr.commit();
}
if (status1 > 0)
ed.writemessage(
"\nwarning! {0} thin triangle(s) found!" +
" wrong result possible!",
status1
);
application.updatescreen();
}
}
how to fill out the code: in this debate visual c#: fill out the code for autocad I explained the procedure and indicated the software for compiling c#.
after uploading the utility with the netload command, giving the triang command you can select a set of 3d points and, from the triangulation of these, get the polyhedra mesh.
I attach the code I compiled.