/** @return the nearest of equidistant middle points of the line. */ RS_Vector RS_Line::getNearestMiddle(const RS_Vector& coord, double* dist, int middlePoints )const { // RS_DEBUG->print("RS_Line::getNearestMiddle(): begin\n"); RS_Vector dvp(getEndpoint() - getStartpoint()); double l=dvp.magnitude(); if( l<= RS_TOLERANCE) { //line too short return const_cast<RS_Line*>(this)->getNearestCenter(coord, dist); /* ?????? */ } RS_Vector vp0(getNearestPointOnEntity(coord,true,dist)); int counts=middlePoints+1; int i( static_cast<int>(vp0.distanceTo(getStartpoint())/l*counts+0.5)); if(!i) i++; // remove end points if(i==counts) i--; vp0=getStartpoint() + dvp*(double(i)/double(counts)); if(dist != NULL) { *dist=vp0.distanceTo(coord); } //std::cout << "rs_line.cpp Dist " << *dist << "\n"; // RS_DEBUG->print("RS_Line::getNearestMiddle(): end\n"); return vp0; }
/** @return the nearest of equidistant middle points of the line. */ RS_Vector RS_Line::getNearestMiddle(const RS_Vector& coord, double* dist, int middlePoints ) { RS_DEBUG->print("RS_Line::getNearestMiddle(): begin\n"); RS_Vector dvp(getEndpoint() - getStartpoint()); double l=dvp.magnitude(); if( l<= RS_TOLERANCE) { //line too short RS_Vector vp(getStartpoint() + dvp*0.5); if (dist != NULL) { *dist=vp.distanceTo(coord); } return vp; } RS_Vector vp0(getNearestPointOnEntity(coord,true,dist)); int counts=middlePoints+1; int i( static_cast<int>(vp0.distanceTo(getStartpoint())/l*counts+0.5)); if(!i) i++; // remove end points if(i==counts) i--; vp0=getStartpoint() + dvp*(double(i)/double(counts)); if(dist != NULL) { *dist=vp0.distanceTo(coord); } RS_DEBUG->print("RS_Line::getNearestMiddle(): end\n"); return vp0; }
/** *create circle inscribled in a triangle * *Author: Dongxu Li */ bool RS_Circle::createInscribe(const RS_Vector& coord, const std::vector<RS_Line*>& lines){ if(lines.size()<3) return false; std::vector<RS_Line*> tri(lines); RS_VectorSolutions sol=RS_Information::getIntersectionLineLine(tri[0],tri[1]); if(sol.getNumber() == 0 ) {//move parallel to opposite std::swap(tri[1],tri[2]); sol=RS_Information::getIntersectionLineLine(tri[0],tri[1]); } if(sol.getNumber() == 0 ) return false; RS_Vector vp0(sol.get(0)); sol=RS_Information::getIntersectionLineLine(tri[2],tri[1]); if(sol.getNumber() == 0 ) return false; RS_Vector vp1(sol.get(0)); RS_Vector dvp(vp1-vp0); double a(dvp.squared()); if( a< RS_TOLERANCE2) return false; //three lines share a common intersecting point RS_Vector vp(coord - vp0); vp -= dvp*(RS_Vector::dotP(dvp,vp)/a); //normal component RS_Vector vl0(tri[0]->getEndpoint() - tri[0]->getStartpoint()); a=dvp.angle(); double angle0(0.5*(vl0.angle() + a)); if( RS_Vector::dotP(vp,vl0) <0.) { angle0 += 0.5*M_PI; } RS_Line line0(vp0, vp0+RS_Vector(angle0));//first bisecting line vl0=(tri[2]->getEndpoint() - tri[2]->getStartpoint()); angle0=0.5*(vl0.angle() + a+M_PI); if( RS_Vector::dotP(vp,vl0) <0.) { angle0 += 0.5*M_PI; } RS_Line line1(vp1, vp1+RS_Vector(angle0));//second bisection line sol=RS_Information::getIntersectionLineLine(&line0,&line1); if(sol.getNumber() == 0 ) return false; bool ret=createFromCR(sol.get(0),tri[1]->getDistanceToPoint(sol.get(0))); if(!ret) return false; for(auto p: lines){ if(! p->isTangent(data)) return false; } return true; }
void test() { unsigned int s = 3; double* a = (double*)malloc(sizeof(double)*s); double* b = (double*)malloc(sizeof(double)*s); // Vector - Vector register unsigned int i, j; for (i = 0; i < s; i++) { a[i] = i; b[i] = i * i; } double dc = dvp(a, b, s); if (equal(9, dc)) printf("Vector - Vector dot product ok\n"); //openMp double oc = odvp(a, b, s); if (equal(oc, dc)) printf("OpenMp: Vector - Vector dot product ok\n"); free(a); free(b); // Matrix - Vector a = (double*)malloc(sizeof(double)*s); b = (double*)malloc(sizeof(double)*s*s); for (i = 0; i < s; i++){ a[i] = 1.0; for (j = 0; j < s; j++){ b[i + j*s] = 1.0; } } double* c = (double*)malloc(sizeof(double)*s); c = (double*)mvp(b, a, s, s); double* d = (double*)malloc(sizeof(double)*s); d[0] = 3.0; d[1] = 3.0; d[2] = 3.0; if (assert((void*)c, (void*)d, s)) printf("Matrix - Vector product ok\n"); //openMp double* cc = (double*)malloc(sizeof(double)*s); cc = omvp(b, a, s, s); if (assert(cc, d, s)) printf("OpenMp: Matrix - Vector product ok\n"); free(a); free(b); free(c); free(cc); free(d); // Matrix - Matrix a = (double*)malloc(sizeof(double)*s*s); b = (double*)malloc(sizeof(double)*s*s); d = (double*)malloc(sizeof(double)*s*s); d[0] = 30.0; d[3] = 66.0; d[6] = 102.0; d[1] = 36.0; d[4] = 81.0; d[7] = 126.0; d[2] = 42.0; d[5] = 96.0; d[8] = 150.0; for (i = 1; i < (s*s) + 1; i++) { a[i - 1] = i; b[i - 1] = i; } c = mmp(a, b, s); if (assert(c, d, s*s)) printf("Matrix - Matrix product ok\n"); //openMp cc = ommp(a, b, s); if (assert(cc, d, s*s)) printf("OpenMp: Matrix - Matrix product ok\n"); free(a); free(b); free(c); free(cc); free(d); }