Geometric Shapes - POJ 3449

Geometric Shapes
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 1537 Accepted: 647

Description

While creating a customer logo, ACM uses graphical utilities to draw a picture that can later be cut into special fluorescent materials. To ensure proper processing, the shapes in the picture cannot intersect. However, some logos contain such intersecting shapes. It is necessary to detect them and decide how to change the picture.

Given a set of geometric shapes, you are to determine all of their intersections. Only outlines are considered, if a shape is completely inside another one, it is not counted as an intersection.

Input

Input contains several pictures. Each picture describes at most 26 shapes, each specified on a separate line. The line begins with an uppercase letter that uniquely identifies the shape inside the corresponding picture. Then there is a kind of the shape and two or more points, everything separated by at least one space. Possible shape kinds are:

• square: Followed by two distinct points giving the opposite corners of the square.
• rectangle: Three points are given, there will always be a right angle between the lines connecting the first point with the second and the second with the third.
• line: Specifies a line segment, two distinct end points are given.
• triangle: Three points are given, they are guaranteed not to be co-linear.
• polygon: Followed by an integer number N (3 ≤ N ≤ 20) and N points specifying vertices of the polygon in either clockwise or anti-clockwise order. The polygon will never intersect itself and its sides will have non-zero length.

All points are always given as two integer coordinates X and Y separated with a comma and enclosed in parentheses. You may assume that |X|, |Y | ≤ 10000.

The picture description is terminated by a line containing a single dash (“-”). After the last picture, there is a line with one dot (“.”).

Output

For each picture, output one line for each of the shapes, sorted alphabetically by its identifier (X). The line must be one of the following:

• “X has no intersections”, if X does not intersect with any other shapes.
• “X intersects with A”, if X intersects with exactly 1 other shape.
• “X intersects with A and B”, if X intersects with exactly 2 other shapes.
• “X intersects with A, B, . . ., and Z”, if X intersects with more than 2 other shapes.

Please note that there is an additional comma for more than two intersections. A, B, etc. are all intersecting shapes, sorted alphabetically.

Print one empty line after each picture, including the last one.

Sample Input

A square (1,2) (3,2)
F line (1,3) (4,4)
W triangle (3,5) (5,5) (4,3)
X triangle (7,2) (7,4) (5,3)
S polygon 6 (9,3) (10,3) (10,4) (8,4) (8,1) (10,2)
B rectangle (3,3) (7,5) (8,3)
-
B square (1,1) (2,2)
A square (3,3) (4,4)
-
.

Sample Output

A has no intersections
B intersects with S, W, and X
F intersects with W
S intersects with B
W intersects with B and F
X intersects with B

A has no intersections
B has no intersections

题意:给你一些图形,让你判断哪些图形有交点。

思路:没啥思路,可以算是一个模拟题了。写的时候细心些,应该不难过。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
struct Point
{
    double x,y;
    Point(double x=0,double y=0):x(x),y(y){}
};
struct node
{
    string str;
    int num;
    Point p[30];
}arr[30];
bool cmp(node a,node b)
{
    return a.str<b.str;
}
double PI=acos(-1.0),eps=1e-8;
typedef Point Vector;
Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p);}
Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p);}
int dcmp(double x){return (x>eps)-(x<-eps);}
double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;}
double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}
double Length(Vector A){return sqrt(Dot(A,A));}
double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}
Vector Rotate(Vector A,double rad){return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)-A.y*cos(rad));}
int T,t,n,m;
vector<string> vc[30];
char s[20];
bool SegmentIntersection(Point a1,Point a2,Point b1,Point b2)
{
    double c1=Cross(a2-a1,b1-a1);
    double c2=Cross(a2-a1,b2-a1);
    double c3=Cross(b2-b1,a1-b1);
    double c4=Cross(b2-b1,a2-b1);
    return dcmp(c1)*dcmp(c2)<=0 && dcmp(c3)*dcmp(c4)<=0
    &&dcmp(min(a1.x,a2.x)-max(b1.x,b2.x))<=0
    &&dcmp(min(a1.y,a2.y)-max(b1.y,b2.y))<=0
    &&dcmp(min(b1.x,b2.x)-max(a1.x,a2.x))<=0
    &&dcmp(min(b1.y,b2.y)-max(a1.y,a2.y))<=0;
}
bool solve(int a,int b)
{
    int i,j,k;
    for(i=0;i<arr[a].num;i++)
       for(j=0;j<arr[b].num;j++)
          if(SegmentIntersection(arr[a].p[i],arr[a].p[i+1],arr[b].p[j],arr[b].p[j+1])>0)
            return 1;
    return 0;
}
void read(Point &a)
{
    scanf("%s",s);
    sscanf(s,"(%lf,%lf)",&a.x,&a.y);
}
int main()
{
    int i,j,k;
    double a1,a2,b1,b2;
    Point a,b,c,d;
    string str;
    while(true)
    {
        n=0;
        while(true)
        {
            n++;
            scanf("%s",s);
            if(s[0]=='.' || s[0]=='-')
            {
                n--;
                break;
            }
            arr[n].str=s;
            scanf("%s",s);

            if(s[0]=='s')
            {
                read(a);read(b);
                arr[n].num=4;
                arr[n].p[1]=a;
                arr[n].p[3]=b;
                c=Rotate((a-b)/2,PI/2);
                arr[n].p[2]=(a+b)/2+c;
                arr[n].p[0]=arr[n].p[4]=(a+b)/2-c;
            }
            else if(s[0]=='r')
            {
                read(a);read(b);read(c);
                arr[n].num=4;
                if(dcmp(Dot(a-c,b-c))==0)
                  swap(b,c);
                arr[n].p[1]=a;
                arr[n].p[2]=b;
                arr[n].p[3]=c;
                arr[n].p[0]=arr[n].p[4]=a-b+c;
            }
            else if(s[0]=='l')
            {
                read(arr[n].p[0]);read(arr[n].p[1]);
                arr[n].num=1;
            }
            else if(s[0]=='t')
            {
                read(a);read(b);read(c);
                arr[n].num=3;
                arr[n].p[1]=a;
                arr[n].p[2]=b;
                arr[n].p[0]=arr[n].p[3]=c;
            }
            else if(s[0]=='p')
            {
                scanf("%d",&arr[n].num);
                for(i=1;i<=arr[n].num;i++)
                   read(arr[n].p[i]);
                arr[n].p[0]=arr[n].p[arr[n].num];
            }
        }
        if(n==0)
          break;
        sort(arr+1,arr+1+n,cmp);
        for(i=1;i<=n;i++)
           vc[i].clear();
        for(i=1;i<=n;i++)
           for(j=i+1;j<=n;j++)
              if(solve(i,j))
              {
                  vc[i].push_back(arr[j].str);
                  vc[j].push_back(arr[i].str);
              }
        for(i=1;i<=n;i++)
        {
            m=vc[i].size();
            cout<<arr[i].str;
            if(m==0)
              cout<<" has no intersections"<<endl;
            else if(m==1)
              cout<<" intersects with "<<vc[i][0]<<endl;
            else if(m==2)
              cout<<" intersects with "<<vc[i][0]<<" and "<<vc[i][1]<<endl;
            else
            {
                cout<<" intersects with ";
                for(j=0;j<m-1;j++)
                   cout<<vc[i][j]<<", ";
                cout<<"and "<<vc[i][m-1]<<endl;
            }
        }
        printf("\n");
    }
}



<think>好的,用户现在想了解或修改ROS中的xacro宏定义,特别是base_xacro的参数和几何形状配置。让我仔细看看用户的问题和之前的对话历史。 首先,用户之前遇到了Xacro宏`base_link`未定义的问题,我给出了详细的解决方案,包括检查宏定义文件、调整包含顺序、验证路径等。现在用户的新问题集中在base_xacro的参数和几何形状配置上,可能是在构建机器人模型时需要自定义底盘部分。 用户提供的引用内容中,引用[2]和[3]提到了xacro宏的定义和使用方法,比如参数传递和宏的结构。用户可能希望了解如何正确编写和调整base_xacro宏的参数,比如radius和length,以及如何配置几何形状,比如圆柱体或长方体。 接下来,我需要确定用户的具体需求。用户可能是在创建或修改机器人的底盘部分,需要定义或调整底盘的尺寸参数,比如半径和长度,以及形状类型。他们可能需要示例代码来参考如何实现这些配置。 考虑到用户之前的错误是宏未定义,所以需要确保在回答中强调宏的正确定义和调用顺序,避免再次出现类似问题。此外,用户可能对如何传递参数、设置几何形状以及如何包含宏文件有疑问,需要提供具体的示例和步骤。 用户可能还需要了解如何根据不同的几何形状(如圆柱体或长方体)来调整参数和惯性矩阵的计算,这在机器人模型中非常重要,尤其是在物理仿真中。因此,我应该提供不同形状的配置示例,并解释每个参数的作用。 另外,用户提到的引用[1]关于ROS2参数设置,虽然与xacro宏没有直接关系,但可能用户对参数传递有更广泛的兴趣,需要确保在回答中涵盖参数的正确使用和验证方法。 最后,用户可能需要一些常见问题的解答,比如如何验证参数是否正确应用,如何处理多参数的情况,以及如何优化宏的结构。这些问题应该在相关问题中列出,帮助用户进一步探索和解决问题。 总结来说,我的回答需要包括以下几个部分: 1. base_xacro宏的基本结构,参数说明。 2. 不同几何形状的配置示例(圆柱体和长方体)。 3. 宏的调用方法和文件包含顺序。 4. 参数验证和调试技巧。 5. 常见问题解答和相关问题推荐。 需要确保所有示例代码符合xacro语法,参数正确传递,并且引用之前提到的解决方案中的要点,比如文件包含顺序和路径验证。同时,使用用户提供的引用内容中的宏定义格式,确保示例的准确性和可操作性。</think>### ROS Xacro宏定义详解:base_xacro参数与几何配置 #### 一、base_xacro宏定义核心参数 在机器人底盘建模中,`base_xacro`宏通常包含以下核心参数: - **几何参数**:$length$(底盘长度)、$radius$(圆柱体半径)或$width$(长方体宽度) - **物理参数**:$mass$(质量)、$material$(材质名称) - **参考系参数**:$xyz$(基准坐标系偏移量)、$rpy$(姿态角) 典型宏定义结构如下(以圆柱形底盘为例): ```xml <!-- base.urdf.xacro --> <xacro:macro name="base_xacro" params="length radius mass material:='gray'"> <link name="base_link"> <!-- 视觉外观 --> <visual> <geometry> <cylinder length="${length}" radius="${radius}"/> </geometry> <material name="${material}"/> </visual> <!-- 碰撞属性 --> <collision> <geometry> <cylinder length="${length}" radius="${radius}"/> </geometry> </collision> <!-- 惯性矩阵(关键物理参数) --> <inertial> <mass value="${mass}"/> <inertia ixx="${mass*(3*radius*radius + length*length)/12}" ixy="0" ixz="0" iyy="${mass*(3*radius*radius + length*length)/12}" iyz="0" izz="${mass*radius*radius/2}"/> </inertial> </link> </xacro:macro> ``` *公式推导:圆柱体惯性张量计算参考经典刚体力学理论[^1]* #### 二、几何形状配置方案 ##### 方案1:圆柱体底盘 ```xml <xacro:base_xacro length="0.15" radius="0.10" mass="2.5" material:="blue"/> ``` - $length$:圆柱体高度方向尺寸 - $radius$:底面半径 - **适用场景**:移动机器人、服务机器人 ##### 方案2:长方体底盘 修改宏定义中的几何描述: ```xml <geometry> <box size="${width} ${length} ${height}"/> <!-- x y z 方向尺寸 --> </geometry> ``` 对应惯性矩阵计算调整为: $$ \begin{cases} i_{xx} = \frac{mass(width^2 + height^2)}{12} \\ i_{yy} = \frac{mass(length^2 + height^2)}{12} \\ i_{zz} = \frac{mass(width^2 + length^2)}{12} \end{cases} $$ #### 三、多参数调用示例 ```xml <!-- 组合式底盘结构 --> <xacro:base_xacro length="0.12" radius="0.08" mass="1.8" xyz="0 0 0.05" rpy="0 ${pi/4} 0"/> ``` *说明:此配置创建了一个倾斜45度、离地5cm的圆柱体底盘[^2]* #### 四、参数验证方法 1. **语法检查**: ```bash xacro --check-params base.urdf.xacro ``` 2. **可视化验证**: ```bash check_urdf <(xacro base.urdf.xacro) # 显示参数解析树 ``` 3. **Gazebo仿真测试**: ```xml <gazebo reference="base_link"> <material>Gazebo/${material}</material> </gazebo> ``` #### 五、配置优化建议 1. **参数标准化**: ```xml <xacro:property name="default_radius" value="0.1"/> <xacro:base_xacro radius="${default_radius}"/> ``` 2. **模块化设计**: ```xml <!-- base_config.xacro --> <xacro:property name="robot_base_spec"> <length>0.15</length> <radius>0.10</radius> <mass>2.0</mass> </xacro:property> ``` --- ### 常见问题解答 **Q1:如何修改已存在的base_xacro参数?** A:直接在调用语句中覆盖默认值: ```xml <xacro:base_xacro length="0.18" radius="0.12"/> <!-- 扩展底盘尺寸 --> ``` **Q2:参数传递出现类型错误怎么办?** A:使用显式类型转换: ```xml <xacro:property name="safety_factor" value="1.5"/> <xacro:base_xacro mass="${2.0 * float(safety_factor)}"/> ``` **Q3:如何实现动态参数计算?** A:在宏定义中使用数学表达式: ```xml <xacro:macro name="adaptive_base" params="payload"> <xacro:base_xacro mass="${0.5 + payload*0.2}"/> <!-- 根据负载调整质量 --> </xacro:macro> ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值