1254 Hansel and Grethel

Description

On a warm summer afternoon, Hansel and Grethel are walking together in the fields. It is getting late and, to be honest, they are lost. Grethel is a little scared, still vividly remembering the last time they got lost in the forest. That time, an evil witch had locked them inside a house built of gingerbread and sugar! But Hansel can reassure her: this time they are well prepared. Hansel has taken a map and a compass with him!
Hansel picks two clearly outstanding features in the landscape, and uses the compass to measure the direction towards both objects. Grethel locates the objects on the map, and writes down the corresponding map coordinates. Based on this information, they will be able to accurately determine their own position on the map.
这里写图片描述
The coordinates of two marker objects, and the direction (angle from the North) towards these objects are known. Write a program which uses this data to calculate the coordinates of Hansel and Grethel’s current location.

Input

The first line of the input contains one positive number: the number of situations in which a position must be determined. Following are two lines per situation, describing the two marker objects. Each marker object is described by a line containing three integer numbers:
the x-coordinate of the object on the map (0 <= x <= 100);
the x-axis runs West-to-East on the map, with increasing values towards the East.
the y-coordinate of the object on the map (0 <= y <= 100);
the y-axis runs South-to-North on the map, with increasing values towards the North.
the direction d of the object in degrees (0 <= d <= 360);
with 0 degree = North, 90 degree = East, 180 degree = South, and so on.
To keep the position calculations accurate, Hansel makes sure that the directions of the two
objects are not exactly equal, and do not differ by exactly 180 degree.

Output

One line per situation, containing the result of the position calculation: two numbers, separated by a space, each having exactly 4 digits after the decimal point. These numbers represent the x and y coordinates of the position of Hansel and Grethel (0 <= x,y <= 100). Round the numbers as usual: up if the next digit would be >= 5, down otherwise.

Sample Input

2
30 50 90
20 40 180
30 40 96
20 20 150

Sample Output

20.0000 50.0000
7.0610 42.4110

Source

Northwestern Europe 2002


/*给出两个相对于一点的方向以及坐标,求此点坐标。

求出两直线交点即可*/
#include<iostream>
#include<math.h>

using namespace std;

#define PI 3.1415926535898

int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        int x1, y1, d1, x2, y2, d2;
        double x, y;
        cin >> x1 >> y1 >> d1 >> x2 >> y2 >> d2;
        /*斜率不存在*/
        if (d1 == 0 || d1 == 180)
        {
            x = x1;
            y = y2 + tan((90.0 - d2)*PI / 180)*(x1 - x2);
        }
        else if (d2 == 0 || d2 == 180)
        {
            x = x2;
            y = y1 + tan((90.0-d1)*PI/180)*(x2 - x1);
        }
        /*斜率存在*/
        else {
            x = (double)(y1 - y2 + x2*tan((90.0 - d2)*PI / 180) - x1*tan((90.0 - d1)*PI / 180)) / (tan((90.0 - d2)*PI / 180) - tan((90.0 - d1)*PI / 180));
            y = y1 + tan((90.0 - d1)*PI / 180)*(x - x1);
        }
        printf("%.4f %.4f\n", x, y);
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值