"c# Learning Note" Three-point location algorithm

Source: Internet
Author: User

Write their own, there may be a lot of shortcomings, looking at where the wrong to ask, I change ~

Code First, then explain what I think.

1 namespacethreepointorientation2 {3     class Program4     {5         struct Point6         {7              Public intx;8              Public inty;9         }Ten         StaticPoint Threepointorientation (Point A, point B, point C,intLenaz,intLENBZ,intLencz) One         { A Point A1, B1, C1, Min, B2, Z2, Z1, ZZ1, ina1b1; -             //1 the             if(a.x <= b.x && a.x <=c.x) -{A1 = A; B1 = B; C1 =C;} -             Else if(b.x <= a.x && b.x <=c.x) -{A1 = B; B1 = C; C1 =A;} +             Else -{A1 = C; B1 = A; C1 =B;} +Min =A1; A             //2 ata1.x =0; A1.Y =0; -b1.x-= min.x; B1.Y-=MIN.Y; -c1.x-= min.x; C1.Y-=MIN.Y; -             //3 -             intLenab = (int) System.Math.Sqrt (b1.x*b1.x + b1.y*b1.y); +b2.x = Lenab; B2.Y =0; -             //4 thez2.x = (Lenaz * Lenaz + Lenab * LENAB-LENBZ * lenbz)/(2*Lenab); *Z2.y = (int) System.Math.Sqrt (lenaz*lenaz-z2.x*z2.x); $             //5Panax Notoginseng             floatTanbab = (float) B1.y/(float) b1.x; -             floatTANCAC = (float) Z2.y/(float) z2.x; the             floattanCAB2; +             if(b1.y >= 0) ATanCAB2 = (TANBAB+TANCAC)/(1-tanbab*TANCAC); the             Else +TanCAB2 = (tancac-tanbab)/(1+tancac*tanbab); -             //6 $z1.x = (int)((float) Lenaz/(System.Math.Sqrt (tanCAB2 * tanCAB2 +1))); $Z1.y = (int) (TANCAB2 *z1.x); -             //7 -ina1b1.x = (a1.x + b1.x)/2; theIna1b1.y = (a1.y + b1.y)/2; -             //8Wuyizz1.x = ina1b1.x *2-z1.x; theZZ1.Y = Ina1b1.y *2-z1.y; -             //9 Wu             intLENZZ1C1 = (int) System.Math.Sqrt (System.Math.Pow (zz1.x-c1.x,2) + System.Math.Pow (ZZ1.Y-C1.Y,2)); -             intLENZ1C1 = (int) System.Math.Sqrt (System.Math.Pow (z1.x-c1.x,2) + System.Math.Pow (Z1.Y-C1.Y,2)); About             if((Lenzz1c1-lencz) < (lenz1c1-Lencz)) $Z1 =ZZ1; -             //Ten -z1.x + =min.x; -Z1.y + =MIN.Y; A  +             returnZ1; the         } -         Static voidMain (string[] args) $         { the Point A, B, C, Z; the             intaz, BZ, CZ; thea.x =-5; theA.Y =-5; -b.x = -; inB.Y = -; thec.x =-5; theC.Y = -; AboutAZ = the; theBZ = the; theCZ = the; thez =Threepointorientation (A, B, C, AZ, BZ, cz); +Console.WriteLine ("x = {0}, y = {1}\n", z.x, z.y); - Console.readkey (); the         }Bayi     } the}

The main function is Point threepointorientation (Point A, point B, point C, int lenaz, int lenbz, int lencz);

A,b,c is known as three points, Lenaz,lenbz,lencz is three points to the required point distance, and the function returns the coordinates of the required point.

My idea ...

1. Assign the minimum x value in ABC three to A1, and the other two points to B1 and C1, and record the value of A1 to min

2. Pan the a1b1c1 triangle to A1 at the origin (i.e. three points minus min)

3. Calculate a1b1 distance Lenab, Kee B2 (Lenab, 0). (equivalent to rotating the edge a1b1 to coincide with the x-axis, get a1b2)

4. The coordinates of the Z2 can be easily calculated according to the a1b2 coordinates and the values of Lenaz and LENBZ (Z2 is the point after translation and rotation)

5.6. Using the formula to obtain Z1 (in fact, through A1, B1 two points and AZ, BZ Two side can be determined by two points, the Z1 and ZZ1)

7.8.9. Find another point ZZ1, Judge C1z1, C1ZZ1 which is more similar to the CZ, the similar points assigned to Z1

10. Translate the Z1 point back (plus min) to Z

"c# Learning Note" Three-point location algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.