Home > other >  Please recognize a center for algorithm design
Please recognize a center for algorithm design

Time:11-02

Two intersecting line AI, BI, the intersection of I
Round O R, radius and two tangent line, tangent point for M, N, M, N, respectively in AI, BI,
The minor arc between two points is at C M, N the midpoint of the
Now known: A (x0, y0), B (x1, y1), C (x2, y2) three coordinates, and the coordinates of the center of the circle O y


Now I write an algorithm that is the way calculus, finding the solution of analytical solutions, feeling should be CSDN the great god, please help have a look

CodePudding user response:

My calculus algorithm code, only for the use of testing, not perfect place, please correct me,
 
//PPPL. CPP: defines the entry point of the console application,
//
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright (C);
* FileName: PPPL. CPP
* the Author: lizhq;
* the Date: 2019-1-18
* Description: known intersecting line of two divergent side endpoint and intersection side chamfer the halfway point of the arc and the arc radius,
The curve (two line + arc),
Into center, center coordinates are calculated, and curve is very simple,
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "math. H"
#include
# define min (a, b) (((a) & lt; (b))? (a) : (b))
# define Max (a, b) (((a) & gt; (b))? (a) : (b))
# define eps (1 e - 12)
# define PI (3.1415926535897932384626)
# define R2D (rad) (rad/PI * 180.0)
# define D2R (ang) (ang/180.0 * PI)
The class CLPoit
{
Public:
Double x;
Double y;
CLPoit ()
{
Y=0.
X=0.
}
CLPoit (double xx, double yy)
{
Y=yy.
X=xx;
}
};
The class CLArc
{
Public:
Double x;
Double y;
Double r;
Double staRadian;
Double sweepRadian;
CLArc ()
{
Y=0.
X=0.
R=0.
StaRadian=0.
SweepRadian=0.
}
CLArc (const CLPoit& C, double rr, double the sta, double SWP)
{
X=c.x;
Y=c.y;
R=rr.
StaRadian=sta;
SweepRadian=SWP;
}
Xx, CLArc (double double yy, double rr, double the sta, double SWP)
{
X=xx;
Y=yy.
R=rr.
StaRadian=sta;
SweepRadian=SWP;
}
Void the set (const CLPoit& C, double rr, double the sta, double SWP)
{
X=c.x;
Y=c.y;
R=rr.
StaRadian=sta;
SweepRadian=SWP;
}
Void the set (double xx, double yy, double rr, double the sta, double SWP)
{
X=xx;
Y=yy.
R=rr.
StaRadian=sta;
SweepRadian=SWP;
}

Void getLinePts (STD: : vector & PTS, int count)
{
PTS. The clear ();
If (count & lt; 2)
return;

CLPoit pt;
Double argRad=sweepRadian/(count - 1);
for (int i=0; I & lt; The count. I++)
{
Pt. X=r * cos ((staRadian + argRad * double (I))) + x;
Pt. Y=r * sin (double (staRadian + argRad * (I))) + y;
PTS. Push_back (pt);
}
}
};

Double dis (const CLPoit& A, const CLPoit& B)
{
Return SQRT ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
Bool getQieDian (CLPoit& TangPt, const CLPoit& P, const CLPoit& O, double r, bool NSZ)
{
Double m=p.x, n=p.y;
=o.x double a, b=o.y;
//points to the square of the distance
Double d2=(m - a) * (m - a) + (n - b) * (n - b);
//points to the center distance
Double d=SQRT (d2);

If (d & lt; R - eps)
return false;

If (d & lt; R + eps)
{
TangPt=p;
return true;
}

//the square of the radius of the
Double r2=r * r;
//points to the tangent point distance
Double l=SQRT (d2 - r2);
//points - & gt; Circle the unit vector
Double x0=(a - m)/d;
Double y0=(b - n)/d;
//calculate tangent Angle with dim sum attachment
Double f=asin (r/d);
//rotate the unit vector in the direction of positive and negative two
if (! F=NSZ) - f;
Double x1=x0 * cos (f) - y0 * sin (f);
Double y1=x0 + y0 * * sin (f), cos (f);
//get the new coordinates
TangPt. X=x1 * l + m;
TangPt. Y=y1 * l + n;
return true;
}
Double getRadian (const CLPoit& P1, const CLPoit& P2)
{
Double radian_temp;
Double xx, yy.
Xx=p2. X-ray p1. X;
Yy=p2. Y - p1. Y;
If (xx==0.0)
Radian_temp=PI/2.0;
The else
Radian_temp=atan (fabs (yy/xx));

If ((xx & lt; 0.0) & amp; & (yy & gt;=0.0))
Radian_temp=PI - radian_temp;
Else if ((xx & lt; 0.0) & amp; & (yy & lt; 0.0))
Radian_temp=PI + radian_temp;
Else if ((xx & gt;=0.0) & amp; & (yy & lt; 0.0))
2.0 radian_temp radian_temp=PI *;

Return (radian_temp);
}
Int getMinValIdx (double& MinVal, const STD: : vector & PTS, const CLPoit& PtL, const CLPoit& PtM, const CLPoit& PtR, double r, bool NSZXZ)
{
Int independence idx=1;
MinVal=DBL_MAX;
For (size_t I=0; I & lt; PTS. The size (); I++)
{
Auto& Ori=PTS [I];
CLPoit qd1, qd2;
if (! GetQieDian (qd1, ptL, ori, r, NSZXZ) | |! GetQieDian (qd2, ptR, ori, r,! NSZXZ))
continue;

Double l1=dis (qd1, ptM);
Double l2=dis (qd2, ptM);
Double dLen=fabs (l1 and l2);
If (dLen & lt; MinVal)
{
MinVal=dLen;
Independence idx=I;
}
}
Return independence idx;
}

Void getAllLen (CLPoit& Ori, const CLPoit& PtL, const CLPoit& PtM, const CLPoit& PtR, double r)
{
STD: : vector Lens; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related