当前位置:首页 > 开发 > 互联网 > 正文

三点定位的算法

发表于: 2014-10-28   作者:haoningabc   来源:转载   浏览:
摘要: 三点定位, 已知a,b,c三个顶点的x,y坐标 和三个点都z坐标的距离,la,lb,lc 求z点的坐标 原理就是围绕a,b,c 三个点画圆,三个圆焦点的部分就是所求 但是,由于三个点的距离可能不准,不一定会有结果, 所以是三个圆环的焦点,环的宽度开始为0,没有取到则加1 运行 gcc -lm test.c test.c代码如下 #include "stdi
三点定位,
已知a,b,c三个顶点的x,y坐标
和三个点都z坐标的距离,la,lb,lc

求z点的坐标
原理就是围绕a,b,c 三个点画圆,三个圆焦点的部分就是所求
但是,由于三个点的距离可能不准,不一定会有结果,
所以是三个圆环的焦点,环的宽度开始为0,没有取到则加1
运行
gcc -lm test.c
test.c代码如下
#include "stdio.h" 
#include "stdlib.h" 
#include <math.h> 
//坐标 
double ax,ay,bx,by,cx,cy,zx,zy; 
//距离 
double la,lb,lc; 
double cx1,cy1,cx2,cy2,cx3,cy3,cx4,cy4; 
int main(void) 
{ 
    int i = 0,j = 0,n = 0; 
    int okflag = 0; 
    int err = 0; 
    int aberr = 0; 
    int acerr = 0; 
    int abcerr = 0; 
    int len; 
    int abrequery = 0; 
    int acrequery = 0; 
    int requery1 = 0; 
    int loopnum = 1; 
    int option = 0; 
    double cax,cay,cbx,cby,ccx,ccy; 
    double cax_abeyance1[6000],cay_abeyance1[6000]; 
    double cbx_abeyance1[6000],cby_abeyance1[6000]; 
    double ccx_abeyance1[6000],ccy_abeyance1[6000]; 
    double cabx_abeyance1[10],caby_abeyance1[10],cabx_abeyance2[10],caby_abeyance2[10]; 
    double cacx_abeyance1[10],cacy_abeyance1[10],cacx_abeyance2[10],cacy_abeyance2[10]; 
    //遍历圆周上所有点 
    printf("use 'Enter' to divide x y\n"); 
    printf("input A coordinate:\n"); 
    scanf("%lf%lf",&ax,&ay); 
    if((ax > 1000)||(bx > 1000)) 
    { 
            printf("figure is too big! input A coordinate again:\n"); 
            scanf("%lf%lf",&ax,&ay); 
    } 
    printf("input B coordinate:\n"); 
    scanf("%lf%lf",&bx,&by); 
    if((bx > 1000)||(bx > 1000)) 
    { 
            printf("figure is too big! input B coordinate again:\n"); 
            scanf("%lf,%lf",&bx,&by);   
    } 
    printf("input C coordinate:\n"); 
    scanf("%lf%lf",&cx,&cy); 
    if((cx > 1000)||(cx > 1000)) 
    { 
            printf("figure is too big! input C coordinate again:\n"); 
            scanf("%lf%lf",&cx,&cy); 
    } 
    printf("input distance from A to Z:\n"); 
    scanf("%lf",&la); 
    if(la > 1000) 
    { 
            printf("figure is too big! inputdistance from A to Z again:\n"); 
            scanf("%lf",&la); 
    } 
    printf("input distance from B to Z:\n"); 
    scanf("%lf",&lb); 
    if(lb > 1000) 
    { 
            printf("figure is too big! inputdistance from B to Z again:\n"); 
            scanf("%lf",&lb); 
    } 
    printf("input distance from C to Z:\n"); 
    scanf("%lf",&lc); 
    if(lc > 1000) 
    { 
            printf("figure is too big! inputdistance from C to Z again:\n"); 
            scanf("%lf",&lc); 
    } 
    printf("\n"); 
    printf("A(%lf,%lf)\n",ax,ay); 
    printf("B(%lf,%lf)\n",bx,by); 
    printf("C(%lf,%lf)\n",cx,cy); 
    printf("AZ = %lf\n",la); 
    printf("BZ = %lf\n",lb); 
    printf("CZ = %lf\n",lc); 
//INPUT: 
    for(zx = ax -la;zx <= ax + la;zx++) 
    { 
            do 
            { 
                    for(zy = ay -la;zy <= ay + la;zy++) 
                    { 
                            cax = zx - ax; 
                            cax = fabs(cax); 
                            cax = pow(cax,2); 
                            cay = zy - ay; 
                            cay = fabs(cay); 
                            cay = pow(cay,2); 
                            if(((cax + cay) > (la*la - err))&&((cax + cay) < (la*la + err))) 
                            { 
                                    okflag = 1; 
                                    cax_abeyance1[i] = zx; 
                                    cay_abeyance1[i] = zy; 
                                    n++; 
                            } 
                    } 
                    if(!okflag)err++; 
            } while (okflag == 0); 
            i++; 
            err = 0; 
            okflag = 0; 
    } 
    printf("query...\n"); 
    i = 0; 
    for(zx = bx -lb;zx <= bx + lb;zx++) 
    { 
            do 
            { 
                    for(zy = by -lb;zy <= by + lb;zy++) 
                    { 
                            cbx = zx - bx; 
                            cbx = fabs(cbx); 
                            cbx = pow(cbx,2); 
                            cby = zy - by; 
                            cby = fabs(cby); 
                            cby = pow(cby,2); 
                            if(((cbx + cby) > (lb*lb - err))&&((cbx + cby) < (lb*lb + err))) 
                            { 
                                    okflag = 1; 
                                    cbx_abeyance1[i] = zx; 
                                    cby_abeyance1[i] = zy; 
                            } 
                    } 
                    if(!okflag)err++;       
            } while (okflag == 0); 
            i++; 
            err = 0; 
            okflag = 0; 
    } 
    printf("query...\n"); 
    getchar(); 
    i = 0; 
    for(zx = cx -lc;zx <= cx + lc;zx++) 
    { 
            do 
            { 
                    for(zy = cy -lc;zy <= cy + lc;zy++) 
                    { 
                            ccx = zx - cx; 
                            ccx = fabs(ccx); 
                            ccx = pow(ccx,2); 
                            ccy = zy - cy; 
                            ccy = fabs(ccy); 
                            ccy = pow(ccy,2); 
                            if(((ccx + ccy) > (lc*lc - err))&&((ccx + ccy) < (lc*lc + err))) 
                            { 
                                    okflag = 1; 
                                     
                                    ccx_abeyance1[i] = zx; 
                                    ccy_abeyance1[i] = zy; 
                                    n++; 
                            } 
                    } 
                    if(!okflag)err++; 
            } while (okflag == 0); 
            i++; 
            err = 0; 
            okflag = 0; 
    } 
    printf("query a b c over!\n"); 
    printf("press Enter to continue!\n"); 
    //必须加不然运行出错,但不会停止 
    getchar(); 
    do 
    { 
    //找ab 交点,因为距离的偏差,所以坐标会有偏差 
            aberr =0; 
            do 
            { 
                    for(i = 0;i <= 2*la;i++) 
                    { 
                            for(j = 0;j <= 2*lb;j++) 
                            { 
                                    if(cax_abeyance1[i] == cbx_abeyance1[j]) 
                                    { 
 
                                            if((cay_abeyance1[i]  >  (cby_abeyance1[j]  -  aberr  - abcerr))&&(cay_abeyance1[i] < (cby_abeyance1[j] + aberr + abcerr))) 
                                            { 
                                                      cabx_abeyance1[abrequery] = cax_abeyance1[i]; 
                                                      caby_abeyance1[abrequery] = cay_abeyance1[i]; 
printf("cabx_abeyance1[%d]=%f",abrequery,cabx_abeyance1[abrequery]); 
printf("caby_abeyance1[%d]=%f\n\n",abrequery,caby_abeyance1[abrequery]); 
                                                      abrequery++; 
                                            } 
                                    } 
                            } 
                    }   
                    if(abrequery < loopnum)aberr++; 
            }while(abrequery < loopnum); 
            acerr =0; 
            //找ac 交点 
            do 
            { 
                      for(i = 0;i <= 2*la;i++) 
                    { 
                            for(j = 0;j <= 2*lc;j++) 
                            { 
                                    if(cax_abeyance1[i] == ccx_abeyance1[j]) 
                                    { 
                                            if((cay_abeyance1[i]  >  (ccy_abeyance1[j]  -  acerr  - abcerr))&&(cay_abeyance1[i] < (ccy_abeyance1[j] + acerr + abcerr))) 
                                            { 
                                                      cacx_abeyance1[acrequery] = cax_abeyance1[i]; 
                                                      cacy_abeyance1[acrequery] = cay_abeyance1[i]; 
                                                      acrequery++; 
                                            } 
                                    } 
                            } 
                    } 
                    if(acrequery < loopnum)acerr++; 
            }while(acrequery < loopnum); 
            //找交点的交点 
            for(i = 0;i < abrequery;i++) 
            { 
                    for(j = 0;j < acrequery;j++) 
                    { 
                            if(cabx_abeyance1[i] == cacx_abeyance1[j]) 
                            { 
                                    requery1 = 1; 
                                    printf("final result is (%f,%f)\n",cabx_abeyance1[i],caby_abeyance1[i]); 
                            } 
                    } 
            } 
            if(requery1 == 0) 
            { 
                    loopnum++; 
                    abcerr++; 
            } 
            if(loopnum == 10) 
            { 
                    printf("chech input figure is right\n"); 
            } 
    }while(requery1 ==0); 
    printf("finish!\n"); 
    getchar(); 
    return 0; 
}  

三点定位的算法

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
计划评审技术PERT(Program Evaluation and Review Technique) 每个活动有三个估计值 最可能(Most li
   Time Difference of Arrival 到达时间差 什么是TDOA   TDOA是一种无线定位技术。   不同于
空间3点投影定位算法 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:
网络广告现在是主流的网站收入来源,在电子商务中,无论是B2B、B2B、C2C,广告都是必不可少的。 广
空间3点投影定位算法 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:
http://www.cnblogs.com/LBSer/p/4020370.html 1 定位背景介绍 一说到定位大家都会想到gps,然而gps
一. 引言 如何从一副图片中找到车牌? 这是机器视觉的一个应用. 理所当然地, 思考的角度是从车牌本身
来源:http://blog.csdn.net/lezhiyong 流程:采集图像→图像滤波增强→图像分割→特征提取→特征分
进行车牌识别和定位首先要了解车牌的特征以及分类。 车牌主要包括以下几种: 蓝牌白字:普通小型车
经典的计算几何方面问题,判断二维坐标系中是否三个点在一条直线上: A (ax,ay) ,B(bx,by),C(cx,cy)
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号