小明同学喜欢体育锻炼,他常常去操场上跑步。跑道是一个圆形,在本题中,我们认为跑道是一个半径为R的圆形,设圆心的坐标原点(0,0)。小明跑步的起点坐标为(R,0),他沿着圆形跑道跑步,而且一直沿着一个方...

本文提供了一段C++代码,用于根据输入的距离L和半径R,计算圆周上两点的坐标。通过判断这两点与圆心连线所形成的夹角大小,选择不同的三角函数计算公式来得出坐标值,并输出保留三位小数的坐标结果。

include "stdafx.h"

#include<iostream>  
#include<vector>  
#include<string>
#include<math.h>
#include<iomanip>
using namespace std;


int main()
{
    float L, R;
    while (cin>>L>>R)
    {
        float len = 2 * 3.1415926*R;
        int nums = L / len;
    //  cout << "nums:" << nums << endl;
        float distance = L - nums*len;
        float jiaodu = distance / R;
    //  cout << "jiaodu" << jiaodu << endl;
        if (jiaodu <= 90)
        {
            float x1 = R*cos(jiaodu);
        //  cout << "cos(90):" << acos(90) << endl;
            float y1 = R*sin(jiaodu);
    //      cout << "x1:" << x1 << endl;
    //      cout << "y1:" << y1 << endl;

            float x2 = x1;
            float y2 = -y1;

    //      cout << "x2:" << x2 << endl;
    //      cout << "y2:" << y2 << endl;

            cout << setiosflags(ios::fixed) << setprecision(3);
            cout << x2 << " " << y2 << endl;
            cout << x1 << " " << y1 << endl;
            
        }
        else if (jiaodu > 90 && jiaodu <= 180)
        {
            float x1 = R*sin(jiaodu-90);
            float y1 = R*cos(jiaodu-90);

            float x2 = x1;
            float y2 = -y1;
            cout << setiosflags(ios::fixed) << setprecision(3);
            cout << x2 << " " << y2 << endl;
            cout << x1 << " " << y1 << endl;
        
        }
        else if (jiaodu > 180 && jiaodu <= 270)
        {
            float x1 = R*cos(jiaodu - 180);
            float y1 = R*sin(jiaodu-180);

            float x2 = x1;
            float y2 = -y1;
            cout << setiosflags(ios::fixed) << setprecision(3);
            cout << x2 << " " << y2 << endl;
            cout << x1 << " " << y1 << endl;
            

        }
        else
        {
            float x1 = R*sin(jiaodu - 270);
            float y1 = R*cos(jiaodu - 270);

            float x2 = x1;
            float y2 = -y1;
            cout << setiosflags(ios::fixed) << setprecision(3);
            cout << x2 << " " << y2 << endl;
            cout << x1 << " " << y1 << endl;
            
        }
        
        

    }

    return 0;
}

转载于:https://www.cnblogs.com/wdan2016/p/6581177.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值