帮助

内容读取中…

内容读取中…

首页  |  相册  |  共享  |  群组
搜索

正文

[计算几何]反射(hdu2355) (2008-08-17 23:24)

http://acm.hdu.edu.cn/showproblem.php?pid=2355

 

The Sidewinder Sleeps

 

直线反射

//http://acm.hdu.edu.cn/showproblem.php?pid=2353

//http://www.geometryalgorithms.com/Archive/algorithm_0104/algorithm_0104B.htm

#include <stdio.h>

#include <math.h>

#include <iostream>

#include <algorithm>

 

using namespace std;

 

const double inf = 1e15;

const double eps = 1e-6;

const double pi = acos(-1.0);

int P;

int ans[100005];

int ansl;

 

struct TPoint

{

   double x, y;

};

 

struct TSeg

{

   char MSD;

   TPoint start, end;

}seg[105];

 

struct TLine

{

    double a, b, c;

}line[105];

 

double max(double x, double y)

{

    if(x > y) return x;

    else return y;

}

 

double min(double x, double y)

{

    if(x < y) return x;

    else return y;

}

 

double multi(TPoint p1, TPoint p2, TPoint p0)

{

    return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);

}

 

int isIntersected(TPoint s1, TPoint e1, TPoint s2, TPoint e2)

{

    if(

    (max(s1.x, e1.x) >= min(s2.x, e2.x)) &&

    (max(s2.x, e2.x) >= min(s1.x, e1.x)) &&

    (max(s1.y, e1.y) >= min(s2.y, e2.y)) &&

    (max(s2.y, e2.y) >= min(s1.y, e1.y)) &&

    (multi(s2, e1, s1) * multi(e1, e2, s1) >= 0) &&

    (multi(s1, e2, s2) * multi(e2, e1, s2) >= 0)

    )  return 1;

   

    return 0;   

}

 

TPoint LineInter(TLine l1, TLine l2)

{

    TPoint tmp;

    double a1 = l1.a;

    double b1 = l1.b;

    double c1 = l1.c;

    double a2 = l2.a;

    double b2 = l2.b;

    double c2 = l2.c;

    if(fabs(b1) < eps){

        tmp.x = -c1 / a1; 

        tmp.y = (-c2 - a2 * tmp.x) / b2;

    }      

    else{

        tmp.x = (c1 * b2 - b1 * c2) / (b1 * a2 - b2 * a1);

        tmp.y = (-c1 - a1 * tmp.x) / b1;

    }

   return tmp;

}

 

TLine lineFromSegment(TPoint p1, TPoint p2)

{

    TLine tmp;

    tmp.a = p2.y - p1.y;

    tmp.b = p1.x - p2.x;

    tmp.c = p2.x * p1.y - p1.x * p2.y;

    return tmp;

}

 

TPoint symmetricalPointofLine(TPoint p, TLine L)

{

    TPoint p2;

    double d;

    d = L.a * L.a + L.b * L.b;

    p2.x = (L.b * L.b * p.x - L.a * L.a * p.x -

            2 * L.a * L.b * p.y - 2 * L.a * L.c) / d;

    p2.y = (L.a * L.a * p.y - L.b * L.b * p.y -

            2 * L.a * L.b * p.x - 2 * L.b * L.c) / d;

    return p2;

}

 

double dis(TPoint p1, TPoint p2)

{

   return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));   

}

 

TLine SloveLine(TPoint start, TPoint dir)

{

    TLine line;

    if(dir.x == 0)

   {

        line.a = 1;

        line.b = 0;

        line.c = -start.x;

    }

    else

评论 (0) | 阅读 (56)

评论
    内容读取中…
发表评论

你还没有登录,现在登录

个人档案

内容读取中…

博客公告

内容读取中…

博客日历

内容读取中…

文章分类

内容读取中…

文章存档

    内容读取中…

最新发表

    内容读取中…

最新评论

内容读取中…

博主留言

内容读取中…

博主好友

内容读取中…

最新访客

内容读取中…

博客统计

    内容读取中…

友情链接

新闻订阅