public void ComputeIntersection() { DmxVector AC = new DmxVector(mPointA, mPointC); DmxVector BD = new DmxVector(mPointB, mPointD); mInterectionPoint = BD.GetIntersection(AC); }
public DmxPoint GetIntersection(DmxVector pVector) { DmxPoint InterectionPoint = new DmxPoint(); this.ComputeEquation(); pVector.ComputeEquation(); if (!mIsInversed) { InterectionPoint.fX = (this.B - pVector.B) / (pVector.A - this.A); InterectionPoint.fY = this.A * InterectionPoint.fX + this.B; } else { InterectionPoint.fY = (this.B - pVector.B) / (pVector.A - this.A); InterectionPoint.fX = this.A * InterectionPoint.fY + this.B; } return(InterectionPoint); }
public DmxPoint GetProjectionPoint(DmxPoint pCommun, DmxVector pProjection) { DmxPoint pt = new DmxPoint(); if (pProjection.Point1.fY == pProjection.Point2.fY) { pt.fY = pProjection.Point1.fY; if (this.Point2.fY == this.Point1.fY) { pt.fX = this.Point2.fY; } else { pt.fX = (pt.fY - pCommun.fY) * (this.Point2.fX - this.Point1.fX) / (this.Point2.fY - this.Point1.fY) + pCommun.fX; } } else if (pProjection.Point1.fX == pProjection.Point2.fX) { pt.fX = pProjection.Point1.fX; if (this.Point2.fX - this.Point1.fX == 0) { pt.fY = this.Point2.fX; } else { pt.fY = (pt.fX - pCommun.fX) * (this.Point2.fY - this.Point1.fY) / (this.Point2.fX - this.Point1.fX) + pCommun.fY; } } else { throw new Exception("Unexpected"); } return(pt); }
public DmxPoint GetRelativePosition() { DmxPoint pt_O = new DmxPoint(128, 128); DmxPoint pt_P = mCurrentPoint; DmxPoint pt_R; //RESULT POINT; DmxPoint pt_I = mInterectionPoint; DmxPoint pt_A; DmxPoint pt_B; DmxPoint pt_C; DmxPoint pt_D; DmxPoint pt_F; DmxPoint pt_G; DmxVector v_OP; DmxVector v_AB; DmxVector v_CD; DmxVector v_AF; DmxVector v_OF; DmxVector v_CG; DmxVector v_IG; DmxVector v_IR; if (mCurrentPoint.fY == 128 && mCurrentPoint.fX == 128) { return(mInterectionPoint); } else if (mCurrentPoint.fX >= mCurrentPoint.fY && mCurrentPoint.fY < (255 - mCurrentPoint.fX)) { pt_A = new DmxPoint(0, 0); pt_B = new DmxPoint(255, 0); pt_C = mPointA; pt_D = mPointB; Console.WriteLine("haut"); } else if (mCurrentPoint.fX >= mCurrentPoint.fY && mCurrentPoint.fY >= (255 - mCurrentPoint.fX)) { pt_A = new DmxPoint(255, 0); pt_B = new DmxPoint(255, 255); pt_C = mPointB; pt_D = mPointC; Console.WriteLine("droite"); } else if (mCurrentPoint.fX < mCurrentPoint.fY && mCurrentPoint.fY >= (255 - mCurrentPoint.fX)) { pt_A = new DmxPoint(255, 255); pt_B = new DmxPoint(0, 255); pt_C = mPointC; pt_D = mPointD; Console.WriteLine("bas"); } else { pt_A = new DmxPoint(0, 255); pt_B = new DmxPoint(0, 0); pt_C = mPointD; pt_D = mPointA; Console.WriteLine("gauche"); } v_OP = new DmxVector(pt_O, pt_P); v_AB = new DmxVector(pt_A, pt_B); v_CD = new DmxVector(pt_C, pt_D); pt_F = v_OP.GetProjectionPoint(pt_O, v_AB); v_AF = new DmxVector(pt_A, pt_F); v_OF = new DmxVector(pt_O, pt_F); float Rapport = v_AF / v_AB; v_CG = v_CD * Rapport; pt_G = v_CG.Point2; v_IG = new DmxVector(pt_I, pt_G); Rapport = v_OP / v_OF; v_IR = v_IG * Rapport; pt_R = v_IR.Point2; return(pt_R); }