Rotate
hdu4998:http://acm.hdu.edu.cn/showproblem.php?pid=4998
题意:给你n个点,以及绕每个点旋转的弧度。然后,问你经过这n次旋转,平面中的点总的效果是相当于哪个点旋转了多少弧度。
题解:我的第一道计算几何。可以选两个点,求出旋转之后的对应点,然后分别求出这两个点的中垂线,中垂线的交点就是要求的点,弧度就是所有弧度之和mod(2*pi)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
const double pi=3.14159265;
using namespace std;
int n;
struct Point{
double x;
double y;
double s;
}num[];
struct LINE{
double a,b,c;
Point s;
};
Point HHH(Point o,double alpha,Point p) {//点p绕着o旋转alpha弧度
Point tp;
p.x-=o.x;
p.y-=o.y;
tp.x=p.x*cos(alpha)-p.y*sin(alpha)+o.x;
tp.y=p.y*cos(alpha)+p.x*sin(alpha)+o.y;
return tp;
}
bool CCC(LINE l1,LINE l2,Point&p){//两条直线是否相交,如果相交,则交点为p
double d=l1.a*l2.b-l2.a*l1.b;
if(abs(d)<1e-) return false;
p.x = (l2.c*l1.b-l1.c*l2.b)/d;
p.y = (l2.a*l1.c-l1.a*l2.c)/d;
return true;
}
LINE DDD(const Point &_a, const Point &_b){//求两点之间垂直平分线
LINE ret;
ret.s.x = (_a.x + _b.x)/;
ret.s.y = (_a.y + _b.y)/;
ret.a = _b.x - _a.x;
ret.b = _b.y - _a.y;
ret.c = (_a.y - _b.y) * ret.s.y + (_a.x - _b.x) * ret.s.x;
return ret;
} LINE EEE(Point a,Point b){//求经过两点的中垂线
LINE ret;
if(abs(a.x-b.x)<1e-){
ret.a=;
ret.b=;
ret.c=-a.x;
return ret;
}
ret.a=a.y-b.y;
ret.b=b.x-a.x;
ret.c=a.x*b.y-a.y*b.x;
return ret;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
double sum=;
for(int i=;i<=n;i++){
scanf("%lf%lf%lf",&num[i].x,&num[i].y,&num[i].s);
sum+=num[i].s;
}
Point s1,s2;
s1.x=2.345,s1.y=4.123;
s2.x=11.345,s2.y=12.123;
Point t1=s1,t2=s2;
for(int i=;i<=n;i++){
Point temp=HHH(num[i],num[i].s,t1);
t1=temp;
}
for(int i=;i<=n;i++){
Point temp=HHH(num[i],num[i].s,t2);
t2=temp;
}
LINE one1=DDD(s1,t1);
LINE one2=DDD(s2,t2);
Point a;
if(CCC(one1,one2,a)){
if(sum>*pi)
sum-=*pi;
printf("%lf %lf %lf\n",a.x,a.y,sum);
}
else{
LINE ttt=EEE(s1,s2);
CCC(one1,ttt,a);
if(sum>*pi)
sum-=*pi;
printf("%lf %lf %lf\n",a.x,a.y,sum);
}
}
}
Rotate的更多相关文章
- Canvas绘图之平移translate、旋转rotate、缩放scale
画布操作介绍 画布绘图的环境通过translate(),scale(),rotate(), setTransform()和transform()来改变,它们会对画布的变换矩阵产生影响. 函数 方法 描 ...
- [LeetCode] Rotate Array 旋转数组
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- [LeetCode] Rotate List 旋转链表
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...
- [LeetCode] Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- jQuery.rotate.js参数
CSS3 提供了多种变形效果,比如矩阵变形.位移.缩放.旋转和倾斜等等,让页面更加生动活泼有趣,不再一动不动.然后 IE10 以下版本的浏览器不支持 CSS3 变形,虽然 IE 有私有属性滤镜(fil ...
- CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate)
CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate) 在CSS3中,可以利用transform功能来实现文字或图像的旋转.缩放.倾 ...
- 偏移:translate ,旋转:rotate,缩放 scale,不知道什么东东:lineCap 实例
<!DOCTYPE HTML> <head> <meta charset = "utf-8"> <title>canvas</ ...
- 记一道有意思的算法题Rotate Image(旋转图像)
题出自https://leetcode.com/problems/rotate-image/ 内容为: You are given an n x n 2D matrix representing an ...
- iOS 2D绘图 (Quartz2D)之Transform(CTM,Translate,Rotate,scale)
前言:Quartz默认采用设备无关的user space来进行绘图,当context(画板)建立之后,默认的坐标系原点以及方向也就确认了,可以通过CTM(current transformation ...
- Rotate Image
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
随机推荐
- AWS IAM (Identity and Access Management) 使用笔记
为 AWS 管理控制台登录页面 URL 创建别名 $ aws iam create-account-alias --account-alias <value> 创建用户 $ aws iam ...
- maven项目转换成dynamic项目
由于maven项目不能直接运行调试需要转换成danamic web后,才能方便进行调试测试.以下是maven项目进行转换的过程 第一步,选择project faces,设置dynamic web版本. ...
- 初见Javascript
1.HTML 中的脚本必须位于 <script> 与 </script> 标签之间. 脚本可被放置在 HTML 页面的 <body> 和 <head> ...
- 计算Android屏幕解锁组合数
晚饭时和同事聊到安卓屏幕解锁时会有多少种解锁方案,觉得很有趣,吃完饭开始想办法解题,花了大概2个小时解决.思路如下: 使用索引值0-9表示从左到右.从上到下的9个点,行.列号很容易从索引值得到: 使用 ...
- 访问权限PPP(public、private、protected、default)之成员变量、成员变量权限解析
首先,我们需要清楚一下方法是由哪些部分构成的: [权限修饰符列表][别的修饰符列表] 返回值类型 方法名(参数列表){ 方法体:} 然后我们需要知道成员变量和成员方法访问有几种情况:1.当前包同一 ...
- 关于Spring AOP和IOC的一些总结
Spring官方网站:https://spring.io/ 最早对象的创建是有new关键字,但是如果产生的类比较繁多或者复杂,就用工厂代替new关键字,但是工厂的控制能力有限,譬如对产生对象的生命周期 ...
- RIME输入法
RIME输入法 1.可以输入汉语拼音. (1) RIME内置的「地球拼音」可以在选择完字之后按下「Shift+Enter」键,直接输入汉语拼音,并且是带声调的. (2) 自己配置汉语拼音方案. 2.五 ...
- Codevs 1814 最长链
1814 最长链 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 现给出一棵N个结点二叉树,问这棵二叉树中最长链的长度为多少, ...
- 使用 Virtual Box 安装 android x86
1.安装 跟随别人的教程:http://www.maketecheasier.com/run-android-4-3-in-virtualbox/ 2.问题 安装过程出现以下问题:Kernel pan ...
- 绑定本地Service并与之通信
绑定Service需要调用 public boolean bindService (Intent service, ServiceConnection conn, int flags): 传入一个Se ...