如何判断一个点是否在一条直线上?
如何判断一个点是否在一条直线上?
已知点、线,
有无函数可以判断该点是否在这条线段上,
或者求出点到这条线段的距离的函数或者方法
acad::errorstatus
asdkpoly::intersectwith(
const acdbentity* ent,
acdb::intersect inttype,
const acgeplane& projplane,
acgepoint3darray& points,
int /*thisgsmarker*/,
int /*othergsmarker*/) const
{
assertreadenabled();
acad::errorstatus es = acad::eok;
if (ent == null)
return acad::enullentitypointer;
// the idea is to intersect each side of the polygon
// with the given entity and return all the points.
//
// for non-r12-entities, with intersection methods defined,
// we call that method for each of the sides of the polygon.
// for r12-entities, we use the locally defined intersectors,
// since their protocols are not implemented.
//
if (ent->iskindof(acdbline::desc())) {
if ((es = intline(this, acdbline::cast(ent),
inttype, &projplane, points)) != acad::eok)
{
return es;
}
} else if (ent->iskindof(acdbarc::desc())) {
if ((es = intarc(this, acdbarc::cast(ent), inttype,
&projplane, points)) != acad::eok)
{
return es;
}
} else if (ent->iskindof(acdbcircle::desc())) {
if ((es = intcircle(this, acdbcircle::cast(ent),
inttype, &projplane, points)) != acad::eok)
{
return es;
}
} else if (ent->iskindof(acdb2dpolyline::desc())) {
if ((es = intpline(this, acdb2dpolyline::cast(ent),
inttype, &projplane, points)) != acad::eok)
{
return es;
}
} else if (ent->iskindof(acdb3dpolyline::desc())) {
if ((es = intpline(this, acdb3dpolyline::cast(ent),
inttype, &projplane, points)) != acad::eok)
{
return es;
}
} else {
acgepoint3darray vertexarray;
if ((es = getvertices3d(vertexarray))
!= acad::eok)
{
return es;
}
if (inttype == acdb::kextendarg
|| inttype == acdb::kextendboth)
{
inttype = acdb::kextendthis;
}
acdbline *pacadline;
for (int i = 0; i < vertexarray.length() - 1; i++) {
pacadline = new acdbline();
pacadline->setstartpoint(vertexarray[i]);
pacadline->setendpoint(vertexarray[i + 1]);
pacadline->setnormal(normal());
if ((es = ent->intersectwith(pacadline, inttype,
projplane, points)) != acad::eok)
{
delete pacadline;
return es;
}
delete pacadline;
}
// all the points that we selected in this process are on
// the other curve; we are dealing with apparent
// intersection. if the other curve is 3d or is not
// on the same plane as poly, the points are not on
// poly.
//
// in this case, we need to do some more work. project the
// points back onto the plane. they should lie on
// the projected poly. find points on real poly
// corresponding to the projected points.
//
acgepoint3d projpt, planept;
acgepoint3darray pts;
acgeline3d line;
acgeplane polyplane;
acdb:

lanarity plnrty;
getplane(polyplane,plnrty);
for (i = 0; i < points.length(); i++) {
// define a line starting from the projpt and
// along the normal. intersect the polygon with
// that line. find all the points and pick the
// one closest to the given point.
//
projpt = points[i].orthoproject(projplane);
line.set(projpt, projplane.normal());
if ((es = intline(this, line, pts))
!= acad::eok)
{
return es;
}
planept = projpt.project(polyplane,
projplane.normal());
points[i] = pts[0];
double length = (planept - pts[0]).length();
double length2;
for (int j = 1; j < pts.length(); j++) {
if ((length2 = (planept - pts[j]).length())
< length)
{
points[i] = pts[j];
length = length2;
}
}
}
}
return es;
}
已知点、线求距离
double length;
acgepoint2d pt;
acgecurve2d *ent2d;
length = ent2d->distanceto(pt,acgecontext::gtol);
我想用distanceto(pt,acgecontext::gtol);来计算距离
可是我的线,点都是acdb类型的不能用
如何才能将acdb类型的线,点转化为acge类型呢?