Vector Rotation of computational geometry

Source: Internet
Author: User

In the actual problem, we may encounter a lot of problems related to the calculation of geometry, one of the problems is the rotation of the vector problem, let us discuss in detail about the rotation of the problem.

First of all, let's simplify the problem, and we'll start by studying a point that rotates a certain angle around another point. Known A point coordinates (x1,y1) b point coordinates (x2,y2) We need to find a dot around b point the position after the degree of rotation of the θ.

The point at which a point rotates the θ angle around the B Point , the question is how we can get the coordinates of the a ' point . (Counterclockwise rotation angle positive, inverse negative) to study a point around another point of rotation, we can first simplify the rotation of a point around the origin of the problem, so it is more convenient for our research. Then we can generalize the conclusion to the general form.

MakeBis the origin, we firstApoint counterclockwise rotation For example, we haveA 'doABthe vertical line, the intersectionABinC, overCdoxthe parallel lines of the shafts have been handedA 'doxaxis perpendicular to theD. Over DotCdoxvertical intersection of axesxPivot at pointE.

MakeAthe coordinates(x, y),A 'coordinates(x1,y1),Bthe coordinates(0,0). We can easily getABthe length, and obviouslyA ' Blength equalsAB. Assuming we know the size of the theta angle, we can quickly find outBCand theA ' Cthe length. bc=a ' B x cosθ,A ' c=a ' B x sinTheta.

because ∠a"  CB and ∠ dce a '  cd + ∠ dcb = ∠ ecd + ∠ dcb=90 degrees.

∠a"  cd= ∠ ecd ,∠ a '  dc= ∠ ceb=90 ca " D  ∽⊿ CBE

bc/be=a '  c/a '  d and bc/ce=a '  c/cd

Of course DC and a '  d are all unknown quantities, We need to solve, but we can find out the c e point coordinates indirectly obtained Span style= "margin:0px; padding:0px ">a '  c and CD c point coordinates.

c Point horizontal axis equals: ( (| Ab| x cos θ )  / | ab|)  * x = x*cos θ

The C- point ordinate equals:(| ab| x cosθ)/| ab|) * y = y*cosθ

The length of the CE and be can be determined.

We can derive from the phase ⊿CA ' D ∽⊿CBE :

AD = x * sinθ DC = y * sinθ

Then it's easy to come up with the following:

X1 = X*cosθ-y * sinθ y1 = y*cosθ + x * sinθ

a "  (x*cos θ Span style= "margin:0px; padding:0px ">- y * sin θ , y*cos Θ  + x * sin θ )

We can think of this: for any point a (x, y),a non-origin, the coordinates of the point after the rotation of θ around the origin are:(x*cosθ-y * Sinθ, y*cosθ + x * sinθ)

Next, let's make a simple generalization of this conclusion, for any two different pointsAand theB(for coordinates that are rotated after the point is revolved around another point,A Boverlap Obviously does not make much sense), askAPoint aroundBPoint rotates the coordinates of the θ angle, we can allBPoint as the origin, theAand theBafter the translation transformation, the calculated point coordinates, respectively, on its horizontal axis, plus the originalBThe horizontal ordinate of the point, this coordinate isA ''s coordinates.


Promotion conclusion: For any two different points a and B a around b The coordinates after rotating the θ angle are:

Δ Span style= "margin:0px; padding:0px ">x*cos θ - &NBSP, δ y *  sin θ + xB, &NBSP, δ y*cos Span style= "margin:0px; padding:0px ">Θ  +  δ x * sin θ + yb )  

Note:xB,YB is the B Point coordinate.


Further generalization of the conclusion: for any non-zero vector ab (0 vector research is of little significance), for Point c a b for Point c rotate the coordinates of a certain angle to find the rotated vector a '  b '   because the vector is still a directed segment after it is rotated. Similarly, this is true for polygon rotation on any two-dimensional plane.


Here is a topic, Shandong province race a problem

Test instructions: In accordance with the counter-clockwise given a A, b coordinates, to find the coordinates of the C coordinate counterclockwise to make the a,b,c three points become equilateral triangle

Idea: the direct set of formula, is B, around a point rotation 60 degrees after the point

#include <iostream> #include <cstdio> #include <cmath>using namespace Std;int main () {    int T;    Double x1,x2,y1,y2;     scanf ("%d", &t);     while (t--)     {        cin>>x1>>y1>>x2>>y2;        Double tx = x2-x1;        Double ty = y2-y1;        Double x = tx* (1.0/2.0)-ty* (sqrt (3.0)/2.0) + x1;        Double y = ty* (1.0/2.0) + tx* (sqrt (3.0)/2.0) + y1;        printf ("(%.2LF,%.2LF) \ n", x, y);     }    return 0;}


Vector Rotation of computational geometry

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.