zoukankan      html  css  js  c++  java
  • 线段的平移和旋转

    //github不会用,试了很久不知道怎么上传代码

    #include <iostream>
    using namespace std;
    #include <stdlib.h>
    #include <Eigen/Dense>
    #include <math.h>
    using namespace std;
    using Eigen::MatrixXd;
    int main()
    {
    int option;
    struct point {
    double px;
    double py;
    };
    struct point p1;
    struct point p2;
    cout<<"请输入线段的起点"<<endl;
    cin>>p1.px;
    cin>>p1.py;
    cout<<"请输入线段的终点"<<endl;
    cin>>p2.px;
    cin>>p2.py;
    cout<<"请输入线段的操作"<<endl<<"move:0"<<endl<<"rotation:1"<<endl;
    cin>>option;
    switch(option)
    {
    case 0:{
    double transp[2];

    cout<<"请输入平移向量"<<endl;
    cin>>transp[0];
    cin>>transp[1];
    p1.px+=transp[0];
    p1.py+=transp[1];
    p2.px+=transp[0];
    p2.py+=transp[1];
    cout<<"平移的结果"<<endl;
    cout<<"("<<p1.px<<","<<p1.py<<")"<<"("<<p2.px<<","<<p2.py<<")"<<endl;
    break;
    }

    case 1:{
    MatrixXd m(2,2);
    double alfa;
    cout<<"请输入旋转角度(0~360)"<<endl;
    cin>>alfa;
    double pi=3.141592654;
    alfa=alfa/180*pi;
    m(0,0)=cos(alfa);
    m(0,1)=sin(alfa);
    m(1,0)=-sin(alfa);
    m(1,1)=cos(alfa);
    double temp1=p1.px*m(0,0)+p1.py*m(1,0);
    double temp2=p1.px*m(0,1)+p1.py*m(1,1);
    double temp3=p2.px*m(0,0)+p2.py*m(1,0);
    double temp4=p2.px*m(0,1)+p2.py*m(1,1);
    p1.px=temp1;
    p1.py=temp2;
    p2.px=temp3;
    p2.px=temp4;
    cout<<"旋转的结果"<<endl;
    cout<<"("<<p1.px<<","<<p1.py<<")"<<"("<<p2.px<<","<<p2.py<<")"<<endl;
    }
    }
    return 0;
    }

  • 相关阅读:
    用nginx转发请求tomcat 如何配置访问日志获取真实ip
    jquery扩展方法(extend) 写法
    android binder机制
    rails nginx passenger postgre 在ubuntu部署
    ssh 免密码登陆
    佛山 开发者 程序员 ios 安卓 外包团队
    佛山程序猿交流群
    IOS开发 僵尸调试
    关于产品设计的功能
    android 视图(view)置顶
  • 原文地址:https://www.cnblogs.com/jessony/p/5015267.html
Copyright © 2011-2022 走看看