zoukankan      html  css  js  c++  java
  • 第一次编程

     1 #include <iostream>
     2 #include <stdlib.h>
     3 #include <Eigen/Dense>
     4 #include <math.h>
     5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     6 using namespace std;
     7 using namespace Eigen; 
     8 
     9 void find(char *strr,Vector2d &pt)
    10 {
    11     int i=1,j=0;
    12     char s1[5],s2[5];
    13     for(;i<10&&strr[i]!=',';i++)
    14     {
    15         s1[j]=strr[i];
    16         pt[0]=atof(s1);j++;
    17     }
    18     i++;
    19     for(j=0;i<20&&strr[i]!=')';i++)
    20     {
    21         s2[j]=strr[i];
    22         pt[1]=atof(s2);j++;    
    23     }
    24 }
    25 void tt(int n1,Vector2d &pt1,Vector2d &pt2,Vector2d &pt3)
    26 {
    27         char str1[20],str2[20],str3[20];
    28         switch(n1){
    29             case 3: {
    30                 cin>>str3;
    31                 find(str3,pt3);
    32             }
    33             case 2: {
    34                 cin>>str2;
    35                 find(str2,pt2);
    36             }    
    37             case 1: {
    38                 cin>>str1;
    39                 find(str1,pt1);
    40                 break;
    41         }
    42             default:cout<<"输入错误"<<endl;
    43         }
    44                         
    45 }
    46 
    47 
    48 int main(int argc, char** argv) {
    49     char name[60],trans[20],name1[60],str[20],s[20];
    50     int n;
    51     double deg;
    52     Vector2d move,v1,v2,v3;
    53     MatrixXd rot(2,2);
    54 
    55     cout<<"请输入 ";
    56     cin>>name;
    57     cin>>n;
    58     tt(n,v1,v2,v3);
    59     cout<<"请输入操作指令"<<endl;
    60     cin>>trans;
    61     cin>>name1;
    62     if(trans[0]=='m'&&trans[1]=='o'&&trans[2]=='v'&&trans[3]=='e'&&trans[4]==0)
    63     {
    64         cin>>str;
    65         find(str,move);
    66         switch(n)
    67         {
    68         case 3:v3+=move;cout<<"("<<v3[0]<<","<<v3[1]<<")"<<endl;
    69         case 2:v2+=move;cout<<"("<<v2[0]<<","<<v2[1]<<")"<<endl;
    70         case 1:v1+=move;cout<<"("<<v1[0]<<","<<v1[1]<<")"<<endl;break;
    71         default: cout<<"输入出错"<<endl;
    72          
    73         }
    74     }
    75     else if(trans[0]=='r'&&trans[1]=='o'&&trans[2]=='t'&&trans[3]=='a'&&trans[4]=='t'&&trans[5]=='e'&&trans[6]==0)
    76     {
    77         cin>>deg;
    78         deg=deg*3.14/180;
    79         rot(0,0)=cos(deg);
    80         rot(0,1)=-sin(deg);
    81         rot(1,0)=sin(deg);
    82         rot(1,1)=cos(deg);
    83         
    84          switch(n)
    85         {
    86         case 3:v3=v3.transpose()*rot;cout<<"("<<v3[0]<<","<<v3[1]<<")"<<endl;
    87         case 2:v2=v2.transpose()*rot;cout<<"("<<v2[0]<<","<<v2[1]<<")"<<endl;
    88         case 1:v1=v1.transpose()*rot;cout<<"("<<v1[0]<<","<<v1[1]<<")"<<endl;break;
    89         default: cout<<"输入出错"<<endl;  
    90         }  
    91     }  
    92     return 0;
    93 }
    code

    1.进行move平移指令

    2.进行rotate旋转指令

    小结:本次编程参照了张杭峰同学和杨春琦同学的编程思维。http://www.cnblogs.com/silentteen/p/5007509.html

    该程序即为对二维数组的加减运算以及旋转矩阵运算。难点在于对数组、坐标格式的读取,以及分类讨论分类处理上。

    解决措施:编写find函数进行字符串至数字的转化,利用tt函数,switch,case,break功能进行点数的分类讨论,分别赋值。

  • 相关阅读:
    [学习笔记] SSD代码笔记 + EifficientNet backbone 练习
    [论文理解] CornerNet: Detecting Objects as Paired Keypoints
    [torch] torch.contiguous
    [tensorflow] tf2.0 简单例子
    [大坑]Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
    本机Jenkins的使用
    安全工具acunetix使用
    cv2.matchTemplate()函数的应用,匹配图片后画出矩形
    python将PNG格式的图片转化成为jpg
    Python实现FTP文件的上传和下载
  • 原文地址:https://www.cnblogs.com/nxxmmz/p/5105968.html
Copyright © 2011-2022 走看看