坐标旋转主要要找到参考系,对于一个坐标,我们需要维护它与参考系之间的角度及长度比。
坐标旋转公式
对于任意两个不同点A和B,A绕B旋转ang角度的坐标为:
(Δx∗cos(ang)−Δy∗sin(ang)+xB,Δy∗cos(ang)+Δx∗sin(ang)+yB) ( Δ x ∗ c o s ( a n g ) − Δ y ∗ s i n ( a n g ) + x B , Δ y ∗ c o s ( a n g ) + Δ x ∗ s i n ( a n g ) + y B )
B - Fractal
题意:操作一次就将该图中的所有线段按照比例变成所给的折线,这样操作d次,问从起点到一个点的长度为总长度的f倍,这个点的坐标是多少。
我们可以以折线的起点到终点的这条线段作为参考系,因为将一条线段变成需要的折线时,我们已知的就是起点和终点的坐标。再维护出每条折线段与参考系的角度及长度比。
计算时我们从后往前计算,维护一个剩余的长度即可。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<math.h>
using namespace std;
const double eps=1e-8;
const int maxn=105;
int sgn(double x)
{
if(fabs(x)<eps)return 0;
if(x>0)return 1;
return -1;
}
struct Point
{
double x,y;
double ratio,ang;
Point(double sx,double sy){x=sx;y=sy;}
Point(){}
Point operator-(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
Point operator+(const Point &b)const
{
return Point(x+b.x,y+b.y);
}
Point operator/(const double b)const
{
return Point(x/b,y/b);
}
Point operator*(const double b)const
{
return Point(x*b,y*b);