Light Oj 1211 计算多个立方体重叠部分体积

Intersection of Cubes
Time Limit:500MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit

Status

Practice

LightOJ 1211
Description
You are given n cubes, each cube is described by two points in 3D space: (x1, y1, z1) being one corner of the cube and (x2, y2, z2) being the opposite corner. Assume that the sides of each of the cubes are parallel to the axis. Your task is to find the volume of their intersection.

Input
Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 100). Each of the next n lines contains six integers x1 y1 z1 x2 y2 z2 (1 ≤ x1, y1, z1, x2, y2, z2 ≤ 1000, x1 < x2, y1 < y2, z1 < z2) where (x1, y1, z1) is the co-ordinate of one corner and (x2, y2, z2) is the co-ordinate of the opposite corner.

Output
For each case, print the case number and volume of their intersection.

Sample Input
2

2

1 1 1 3 3 3

1 1 1 2 2 2

3

7 8 9 20 20 30

2 2 2 50 50 50

13 14 15 18 30 40

Sample Output
Case 1: 1

Case 2: 450

<span style="color:#000099;">/*********************************************

     author   :    Grant Yuan
     time     :    2014.8.7
     algorithm:    计算几何
     source   :    Light Oj 1211
     explain  :    求几个正方体重叠部分的体积
     
***********************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define INF 0x3fffffff
using namespace std;

int t,n,a[7];
int ans;

int main()
{
    scanf("%d",&t);int c;
    for(int i=1;i<=t;i++)
    {
        scanf("%d",&n);
        a[1]=a[2]=a[3]=0;
        a[4]=a[5]=a[6]=INF;
        for(int j=1;j<=n;j++)
        {
           for(int k=1;k<=3;k++)
           {
               scanf("%d",&c);
               if(c>a[k]) a[k]=c;
           }
           for(int k=4;k<=6;k++)
           {
               scanf("%d",&c);
               if(c<a[k]) a[k]=c;
           }

        }
        if(a[4]>a[1]&&a[5]>a[2]&&a[6]>a[3])
        {
            ans=(a[4]-a[1])*(a[5]-a[2])*(a[6]-a[3]);
           printf("Case %d: %d\n",i,ans);}
        else printf("Case %d: 0\n",i);
    }
    return 0;
}
</span>


 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要通过两个三维坐标计算欧拉角,你需要使用适当的数学公式。假设你有两个三维坐标分别为 `p1 = (x1, y1, z1)` 和 `p2 = (x2, y2, z2)`。以下是计算欧拉角的一种方法: 1. 首先,计算两个坐标的差值:`d = (x2 - x1, y2 - y1, z2 - z1)`。 2. 计算 yaw 角(绕垂直轴旋转角度):`yaw = atan2(d[1], d[0])`。 3. 计算 pitch 角(绕横轴旋转角度):`pitch = atan2(d[2], sqrt(d[0]**2 + d[1]**2))`。 4. 计算 roll 角(绕纵轴旋转角度):`roll = atan2(sin(pitch)*d[0] - cos(pitch)*d[1], cos(pitch)*d[0] + sin(pitch)*d[1])`。 在这个方法中,我们使用了 `atan2` 函数来计算角度值。请注意,结果的单位是弧度。如果你需要将结果转换为度数,可以使用 `math.degrees()` 函数来进行转换。 下面是一个示例代码,展示了如何计算两个三维坐标的欧拉角: ```python import math p1 = (1, 2, 3) p2 = (4, 5, 6) d = (p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]) yaw = math.atan2(d[1], d[0]) pitch = math.atan2(d[2], math.sqrt(d[0]**2 + d[1]**2)) roll = math.atan2(math.sin(pitch)*d[0] - math.cos(pitch)*d[1], math.cos(pitch)*d[0] + math.sin(pitch)*d[1]) yaw_degrees = math.degrees(yaw) pitch_degrees = math.degrees(pitch) roll_degrees = math.degrees(roll) print("Yaw:", yaw_degrees) print("Pitch:", pitch_degrees) print("Roll:", roll_degrees) ``` 在这个示例中,我们计算两个三维坐标的欧拉角,并将结果以度数的形式打印出来。你可以将 `p1` 和 `p2` 替换为你自己的坐标点。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值