zoukankan      html  css  js  c++  java
  • 计算几何整理

    计算几何

    1. 基本元素

    1.1 点 && 向量

    1.1.1 定义

    .1.2.6 模长
    typedef struct Point Vector;
    struct Point
    {
    	double x,y;
    	Point(double x=0,double y=0):x(x),y(y){}
    };
    

    1.1.2 基本操作

    1.1.2.1 加法
    Vector operator +(const Vector &a,const Vector &b)
    {
    	return Vector(a.x+b.x,a.y+b.y);
    }
    
    1.1.2.2 减法
    Vector operator -(const Vector &a,const Vector &b)
    {
    	return Vector(a.x-b.x,a.y-b.y);
    }
    
    1.1.2.3 数乘
    Vector operator *(const double &phi,const Vector &a)
    {
    	return Vector(phi*a.x,phi*a.y);
    }
    
    1.1.2.4 点积
    double operator *(const Vector &a,const Vector &b)
    {
    	return a.x*b.x+a.y*b.y;
    }
    
    1.1.2.5 叉积
    double operator ^(const Vector &a,const Vector &b)
    {
    	return a.x*b.y-a.y*b.x;
    }
    
    1.1.2.6 模长
    double Length(const Vector &a)
    {
    	return sqrt(a*a);
    }
    double Length2(const Vector &a)
    {
    	return a*a;
    }
    
    1.1.2.7 调整长度
    Vector Adjust(const double &l,const Vector &a)
    {
    	return a*(l/Length(a));
    }
    
    1.1.2.8 两点间距离
    double Dist(const Point &a,const Point &b)
    {
    	return len(a-b);
    }
    
    1.1.2.9 投影
    double Shade(const Vector &a,const Vector &b)
    {
    	return a*b/Length(a);
    }
    
    1.1.2.10 垂直(右手向)
    Vector Perpendicular(const Vector &a)
    {
    	return Vector(a.y,-a.x);
    }
    

    1.2 线

    1.2.1 定义

    typedef struct Line Segment,HalfLine;
    struct Line
    {
    	Point p;
    	Vector v;
    	Line(Point p,Vector v):p(p),v(v){}
    };
    

    1.2.2 基本操作

    1.2.2.1 点到直线距离
    double DistLine(const Point &a,const Line &b)
    {
    	double x=Length2(a-b.p),y=Shade(a-b.p,b.v);
    	return sqrt(x-y*y);
    }
    
    1.2.2.2 判断两直线是否相交
  • 相关阅读:
    Oracle11g备份与恢复-手工备份与恢复
    undo段及区的状态和使用
    图解一个事务操作流程
    Oracle11g备份与恢复
    undo表空间概述-1
    事务的隔离级别
    事务概述
    系统改变号(SCN)详解
    实例崩溃恢复原理--检查点队列的作用
    Oracle-检查点队列
  • 原文地址:https://www.cnblogs.com/Capella/p/8683371.html
Copyright © 2011-2022 走看看