void CttView::SuoFang(const int &x, const int &y){ int i; int sz = m_last_point.size(); vector<CPoint> mlp = m_last_point; if (sz < 2)return; int x0 = mlp[0].x; int y0 = mlp[0].y; int dx = x - mlp[0].x; int dy = y - mlp[0].y; int dx2 = mlp[1].x - mlp[0].x; int dy2 = mlp[1].y - mlp[0].y; double dxy = sqrt(dx*dx + dy*dy); double dxy2 = sqrt(dx2*dx2 + dy2*dy2); double rate = dxy / dxy2; for (i = 0; i < sz; i++){ int fx = m_last_point[i].x; int fy = m_last_point[i].y; mlp[i].x = (fx - x0)*rate + x0; mlp[i].y = (fy - y0)*rate + y0; } for (i = 0; i<sz - 1; i++){ LineLine(mlp[i], mlp[i + 1]); } LineLine(mlp[sz - 1], mlp[0]); }
void CttView::DuiChengXY(const int &x, const int &y){ int i; int sz = m_last_point.size(); vector<CPoint> mlp = m_last_point; if (sz == 0)return; for (i = 0; i<sz - 1; i++){ CPoint st, ed, fs, fe; fs = mlp[i]; fe = mlp[i + 1]; st.x = -(fs.x - x) + x; st.y = -(fs.y - y) + y; ed.x = -(fe.x - x) + x; ed.y = -(fe.y - y) + y; LineLine(st, ed); } CPoint st, ed, fs, fe; fs = mlp[sz - 1]; fe = mlp[0]; st.x = -(fs.x - x) + x; st.y = -(fs.y - y) + y; ed.x = -(fe.x - x) + x; ed.y = -(fe.y - y) + y; LineLine(st, ed); }
void CttView::drawLine(CPoint st, CPoint ed) { switch(m_graphtype){ case 0:LineLine(st,ed);break; case 1:MidLine(st,ed);break; case 2:BsmLine(st,ed);break; default:LineLine(st,ed); } }
//****************************************** void LineToLine(double Line1StartX,double Line1StartY,double Line1EndX,double Line1EndY, double Line2StartX,double Line2StartY,double Line2EndX,double Line2EndY) { double dLine1X,dLine1Y; double dLine2X,dLine2Y; int Line1Number; int Line2Number; int Number; double ArcLine1,ArcLine2; double Line1Length,Line2Length; double dLine1Length,dLine2Length; Line1Length=sqrt((Line1EndX-Line1StartX)*(Line1EndX-Line1StartX)+(Line1EndY-Line1StartY)*(Line1EndY-Line1StartY)); Line2Length=sqrt((Line2EndX-Line2StartX)*(Line2EndX-Line2StartX)+(Line2EndY-Line2StartY)*(Line2EndY-Line2StartY)); ////直线与X轴夹角 ArcLine1=calculateLineArc(Line1EndX-Line1StartX,Line1EndY-Line1StartX); ArcLine2=calculateLineArc(Line2EndX-Line2StartX,Line2EndY-Line2StartX); Line1Number=(int)(Line1Length/(cutlerRadius*2)); Line2Number=(int)(Line2Length/(cutlerRadius*2)); if(Line1Number>Line2Number)Number=Line1Number; else Number=Line2Number; dLine1Length=Line1Length/Number; dLine2Length=Line2Length/Number; dLine1X=dLine1Length*cos(ArcLine1); dLine1Y=dLine1Length*sin(ArcLine1); dLine2X=dLine2Length*cos(ArcLine2); dLine2Y=dLine2Length*sin(ArcLine2); LineLine(dLine1X,dLine1Y,dLine2X,dLine2Y,Number); }
void CttView::GraphMove(const int &x, const int &y){ int i; int sz = m_last_point.size(); vector<CPoint> mlp = m_last_point; if (sz == 0)return; int dx = x - mlp[0].x; int dy = y - mlp[0].y; for (i = 0; i < sz; i++){ mlp[i].x += dx; mlp[i].y += dy; } for (i = 0; i<sz - 1; i++){ LineLine(mlp[i], mlp[i + 1]); } LineLine(mlp[sz - 1], mlp[0]); }
void CttView::XuanZhuan(const int &x, const int &y){ int i; int sz = m_last_point.size(); vector<CPoint> mlp = m_last_point; if (sz == 0)return; int dx = x - mlp[0].x; int dy = y - mlp[0].y; int x0 = mlp[0].x; int y0 = mlp[0].y; double dxy = sqrt(dx*dx + dy*dy); double sin = ((double)dx)/(dxy); double cos = ((double)dy)/(dxy); for (i = 0; i < sz; i++){ int fx = m_last_point[i].x; int fy = m_last_point[i].y; mlp[i].x = (fx-x0)*cos - (fy-y0)*sin + x0; mlp[i].y = (fx-x0)*sin + (fy-y0)*cos + y0; } for (i = 0; i<sz - 1; i++){ LineLine(mlp[i], mlp[i + 1]); } LineLine(mlp[sz - 1], mlp[0]); }
float3 Ray::ClosestPoint(const LineSegment &other, float *d, float *d2) const { ///\todo Properly cap d2. return LineLine(pos, pos + dir, other.a, other.b, d, d2); }
float3 Ray::ClosestPoint(const Line &other, float *d, float *d2) const { return LineLine(pos, pos + dir, other.pos, other.pos + other.dir, d, d2); }
float3 Ray::ClosestPoint(const Ray &other, float *d, float *d2) const { ///\todo Properly cap d2. return LineLine(pos, pos + dir, other.pos, other.pos + other.dir, d, d2); }
bool csIntersect2::PlanePlane ( const csPlane2 &p1, const csPlane2 &p2, csVector2 &isect) { // p1: A1x+B1y+C1 = 0 // p2: A2x+B2y+C2 = 0 csVector2 start1, end1; csVector2 start2, end2; if (ABS (p1.A ()) < SMALL_EPSILON) { // Horizontal line. start1.Set (0, -p1.C () / p1.B ()); end1.Set (1, -p1.C () / p1.B ()); } else if (ABS (p1.B ()) < SMALL_EPSILON) { // Vertical line. start1.Set (-p1.C () / p1.A (), 0); end1.Set (-p1.C () / p1.A (), 1); } else { start1.Set (0, -p1.C () / p1.B ()); end1.Set (1, (-p1.C () - p1.A ()) / p1.B ()); } if (ABS (p2.A ()) < SMALL_EPSILON) { // Horizontal line. start2.Set (0, -p2.C () / p2.B ()); end2.Set (1, -p2.C () / p2.B ()); } else if (ABS (p2.B ()) < SMALL_EPSILON) { // Vertical line. start2.Set (-p2.C () / p2.A (), 0); end2.Set (-p2.C () / p2.A (), 1); } else { start2.Set (0, -p2.C () / p2.B ()); end2.Set (1, (-p2.C () - p2.A ()) / p2.B ()); } return LineLine (csSegment2 (start1, end1), csSegment2 (start2, end2), isect); #if 0 //@@@NOT SURE THAT THIS ROUTINE IS RIGHT AND OPTIMAL if (ABS (p1.B ()) < SMALL_EPSILON && ABS (p2.B ()) < SMALL_EPSILON) return false; if (ABS (p1.A ()) > ABS (p2.A ())) { isect.y = (p2.A () * p1.C () / p1.A () - p2.C ()) / (p2.B () - p2.A () * p1.B () / p1.A ()); isect.x = -(p1.B () * isect.y + p1.C ()) / p1.A (); } else if (ABS (p2.A ()) > SMALL_EPSILON) { isect.y = (p1.A () * p2.C () / p2.A () - p1.C ()) / (p1.B () - p1.A () * p2.B () / p2.A ()); isect.x = -(p2.B () * isect.y + p2.C ()) / p2.A (); } else return false; // parallel return true; #endif }