예제 #1
0
void CarLocationUpdate(CDistanceValue* distance, const CSpeedVW *present_speed, s32 period )
{
    s32 delta_theta;
    s32 delta_distance = 0;
    static s32 delta_theta_remainder;
    static s32 delta_distance_remainder;
    
    //位移
    delta_distance = present_speed->sV * period + delta_distance_remainder;
    delta_distance_remainder = delta_distance % 1000000;
    delta_distance /= 1000000;
    
    //角度变化,左转弯为角速度正方向
    if(abs(present_speed->sW) < W_NOISE_TH)
    {
        delta_theta = 0;
    }
    else
    {
        delta_theta = present_speed->sW * period + delta_theta_remainder;
        delta_theta_remainder = delta_theta % 1000000;
        delta_theta /= 1000000;
    }
    
    distance->theta += delta_theta;

    distance->theta %= DEGREE(360);
    if(distance->theta < 0)
	{
		distance->theta += DEGREE(360);
	}
    
    distance->distance += delta_distance;
}
예제 #2
0
파일: blockpath.c 프로젝트: aosm/graphviz
/* clone_graph:
 * Create two copies of the argument graph
 * One is a subgraph, the other is an actual copy since we will be
 * adding edges to it.
 */
static Agraph_t*
clone_graph(Agraph_t* ing, Agraph_t** xg)
{
	Agraph_t*  clone;
	Agraph_t*  xclone;
	Agnode_t*  n;
	Agnode_t*  xn;
	Agnode_t*  xh;
	Agedge_t*  e;
	Agedge_t*  xe;
	char       gname[SMALLBUF];
	static int id = 0;

	sprintf (gname, "_clone_%d", id++);
	clone = agsubg(ing, gname);
	sprintf (gname, "_clone_%d", id++);
	xclone = agopen(gname, ing->kind);

	for(n = agfstnode(ing); n; n = agnxtnode(ing, n)) {
		aginsert (clone, n);
		xn = agnode (xclone, n->name);
		CLONE(n) = xn;
	}

	for(n = agfstnode(ing); n; n = agnxtnode(ing, n)) {
		xn = CLONE(n);
		for(e = agfstout(ing, n); e; e = agnxtout(ing, e)) {
			aginsert (clone, e);
			xh = CLONE(e->head); 
			xe = agedge (xclone, xn, xh);
			ORIGE(xe) = e;
			DEGREE(xn) += 1;
			DEGREE(xh) += 1;
		}
	}
	*xg = xclone;
#ifdef OLD
	clone = agopen("clone", root->kind);

	for(n = agfstnode(root); n; n = agnxtnode(root, n)) {
		cn = agnode(clone, n->name);		
		ND_alg(cn) = DATA(n);
		BCDONE(cn) = 0;
	}

	for(n = agfstnode(root); n; n = agnxtnode(root, n)) {
		Agnode_t *t = agnode(clone, n);
		for(e = agfstout(root, n); e; e = agnxtout(root, e)) {
			Agnode_t *h = agnode(clone, e->head->name);
			agedge(clone, t, h);
		}
	}
#endif
	return clone;
}
예제 #3
0
파일: deglist.c 프로젝트: TidyHuang/vizgems
/* removeDeglist:
 * Remove n from list, if it is in the list.
 */
void removeDeglist(deglist_t * list, Agnode_t * n)
{
    degitem key;
    degitem *ip;
    Agnode_t *np;
    Agnode_t *prev;

    key.deg = DEGREE(n);
    ip = (degitem *) dtsearch(list, &key);
    assert(ip);
    if (ip->np == n) {
	ip->np = ND_next(n);
	if (ip->np == NULL)
	    dtdelete(list, ip);
    } else {
	prev = ip->np;
	np = ND_next(prev);
	while (np && (np != n)) {
	    prev = np;
	    np = ND_next(np);
	}
	if (np)
	    ND_next(prev) = ND_next(np);
    }
}
예제 #4
0
파일: deglist.c 프로젝트: TidyHuang/vizgems
/* insertDeglist:
 * Add a node to the node list.
 * Nodes are kept sorted by DEGREE, smallest degrees first.
 */
void insertDeglist(deglist_t * ns, Agnode_t * n)
{
    degitem key;
    degitem *kp;

    key.deg = DEGREE(n);
    kp = dtinsert(ns, &key);
    ND_next(n) = kp->np;
    kp->np = n;
}
예제 #5
0
/* remove_pair_edges:
 * Create layout skeleton of ing.
 * Why is returned graph connected?
 */
static Agraph_t *remove_pair_edges(Agraph_t * ing)
{
    int counter = 0;
    int nodeCount;
    Agraph_t *outg;
    Agraph_t *g;
    deglist_t *dl;
    Agnode_t *currnode, *adjNode;
    Agedge_t *e;

    outg = clone_graph(ing, &g);
    nodeCount = agnnodes(g);
    dl = getList(g);

    while (counter < (nodeCount - 3)) {
	currnode = firstDeglist(dl);

	/* Remove all adjacent nodes since they have to be reinserted */
	for (e = agfstedge(g, currnode); e; e = agnxtedge(g, e, currnode)) {
	    adjNode = e->head;
	    if (currnode == adjNode)
		adjNode = e->tail;
	    removeDeglist(dl, adjNode);
	}

	find_pair_edges(g, currnode, outg);

	for (e = agfstedge(g, currnode); e; e = agnxtedge(g, e, currnode)) {
	    adjNode = e->head;
	    if (currnode == adjNode)
		adjNode = e->tail;

	    DEGREE(adjNode)--;
	    insertDeglist(dl, adjNode);
	}

	agdelete(g, currnode);

	counter++;
    }

    agclose(g);
    freeDeglist(dl);
    return outg;
}
예제 #6
0
//单轴旋转矩阵
Matrix4::Matrix4(char axis, float degree) {
	SetZero();

	var[0][0] = 1.0f;
	var[1][1] = 1.0f;
	var[2][2] = 1.0f;
	var[3][3] = 1.0f;

	//如果没进行旋转
	if (-0.001f <= degree && degree <= 0.001f) {
		return;
	}

	degree = DEGREE(degree);
	float c = cosf(degree);
	float s = sinf(degree);

	switch (axis)
	{
	case 'x':
	case 'X':
		var[1][1] = c;
		var[2][2] = c;
		var[1][2] = s;
		var[2][1] = -s;
		break;
	case 'y':
	case 'Y':
		var[0][0] = c;
		var[2][2] = c;
		var[2][0] = s;
		var[0][2] = -s;
		break;
	case 'z':
	case 'Z':
		var[0][0] = c;
		var[1][1] = c;
		var[0][1] = s;
		var[1][0] = -s;
		break;
	//Should never reach here
	default:
		break;
	}
}
예제 #7
0
int main(int argc, const char * argv[])
{
	if (argc < 5)
	{
		printf("!!!Error: Not enough arguments. <first_long_number_filename> [ + | - | * | / | % | ^ ] <second_long_number_filename> <result_long_number_filename>!!!\n");
		return 0;
	}

	if (argc > 7)
	{
		printf("!!!Error: Many arguments. <first_long_number_filename> [ + | - | * | / | % | ^ ] <second_long_number_filename> <result_long_number_filename> <module_long_number_filename> <-b>!!!\n");
		return 0;
	}

	FILE* firstLongNumFile = fopen(argv[1], "r");	
	if (!firstLongNumFile)	//проверка открытия первого файла с числом
	{
		printf("!!!Error: Unable to open file: %s !!!\n", argv[1]);
		return 0;
	}
	fclose(firstLongNumFile);

	const char* operation = argv[2];	
	if ((strlen(operation) > 1 || operation[0] == '\0') || operation[0] != '+' && operation[0] != '-' && operation[0] != '*' && operation[0] != '/' && operation[0] != '%' && operation[0] != '^')	//проверка оператора
	{
		printf("!!!Error: Wrong operation: %s !!!\n", operation);
		return 0;
	}

	FILE* secondLongNumFile = fopen(argv[3], "r");	//проверка открытия второго файла с числом
	if (!secondLongNumFile)
	{
		printf("!!!Error: Unable to open file: %s !!!\n", argv[3]);
		return 0;
	}
	fclose(secondLongNumFile);

	FILE* resultLongNumFile = fopen(argv[4], "r");
	if (!resultLongNumFile)	//проверка открытия файла для результата
	{
		printf("!!!Error: Unable to open file: %s !!!\n", argv[4]);
		return 0;
	}
	fclose(resultLongNumFile);

	////////////////////////////////////////////////////////////////////////////////

	int bin = 0; //флаг для бинарного файла

	if (argc == 5)
	if (argv[2][0] == '^')
	{
		printf("!!!Error: Input module file!!!\n");
		return 0;
	}

	if (argc == 6)
	{
		if (argv[2][0] == '^')
		{
			FILE* moduleLongNumFile = fopen(argv[5], "r");
			if (!moduleLongNumFile)
			{
				printf("!!!Error: Unable to open file: %s !!!\n", argv[5]);
				return 0;
			}
			fclose(moduleLongNumFile);
		}
		else
		{
			if (strcmp(argv[5], "-b"))
			{
				printf("!!!Error: Invalid flag: %s !!!\n", argv[5]);
				return 0;
			}
			bin = 1;
		}

	}

	if (argc == 7)
	{
		FILE* moduleLongNumFile = fopen(argv[5], "r");
		if (!moduleLongNumFile)
		{
			printf("!!!Error: Unable to open file: %s !!!\n", argv[5]);
			return 0;
		}
		fclose(moduleLongNumFile);

		if (strcmp(argv[6], "-b"))
		{
			printf("!!!Error: Invalid flag: %s !!!\n", argv[6]);
			return 0;
		}
		bin = 1;
	}

	struct LongNumber a, b;

	//загружаем первое число из бинарного файла
	if (bin == 1)
		a = ReadBinFile(argv[1]);
	else
		a = ReadTextFile(argv[1]);

	//загружаем второе число из бинарного файла
	if (bin == 1)
		b = ReadBinFile(argv[3]);
	else
		b = ReadTextFile(argv[3]);

	//выполняем операцию 

	struct LongNumber result;

	switch (operation[0]) {
	case '+':
	{
				result = ADD(a, b);
				break;
	}
	case '-':
	{
				result = SUB(a, b);
				break;
	}
	case '*':
	{
				result = MUL(a, b);
				break;
	}
	case '/':
	{
				result = DIV(a, b, 1);
				break;
	}
	case '%':
	{
				result = DIV(a, b, 2);
				break;
	}
	case '^':
	{
				struct LongNumber c;
				if (bin == 1)
					c = ReadBinFile(argv[5]);
				else
					c = ReadTextFile(argv[5]);

				result = DEGREE(a, b, c);
				c = clear(c);
				break;
	}
	default:
		break;
	}

	//записываем в файл результат
	if (bin == 1)
		WriteBinFile(argv[4], result);
	else
		WriteTextFile(argv[4], result);


	a = clear(a);
	b = clear(b);
	result = clear(result);


	return 0;
}
예제 #8
0
BOOL CPageImageProcess::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	GetClientRect(&m_rect);

	CRect rectClient;
	this->GetOwner()->GetClientRect(&rectClient);
	CTabCtrl *pTab = (CTabCtrl *)this->GetOwner();

	CRect rcHead;
	pTab->GetItemRect(0,&rcHead);
	rectClient.top += rcHead.Height() + 2;
	rectClient.left += 2;
	rectClient.right -= 2;
	rectClient.bottom -= 2;
	MoveWindow(rectClient);

	// Button
	m_BtnUndo.SubclassDlgItem(ID_EDIT_UNDO,this);
	m_BtnUndo.SetTooltipText(_T("撤销"));

	m_BtnFitWindow.SubclassDlgItem(IDC_BTN_FIT_WINDOW,this);
	m_BtnFitWindow.SetTooltipText(_T("适屏"));

	m_BtnZoomIn.SubclassDlgItem(IDC_BTN_ZOOM_IN,this);
	m_BtnZoomIn.SetTooltipText(_T("放大"));

	m_BtnZoom11.SubclassDlgItem(IDC_BTN_ZOOM_11,this);
	m_BtnZoom11.SetTooltipText(_T("实际大小"));

	m_BtnZoomOut.SubclassDlgItem(IDC_BTN_ZOOM_OUT,this);
	m_BtnZoomOut.SetTooltipText(_T("缩小"));

	m_BtnRotateLeft.SubclassDlgItem(IDC_BTN_ROTATE_LEFT,this);
	m_BtnRotateLeft.SetTooltipText(_T("左转90度"));

	m_BtnRotateRight.SubclassDlgItem(IDC_BTN_ROTATE_RIGHT,this);
	m_BtnRotateRight.SetTooltipText(_T("右转90度"));

	m_BtnRotate.SubclassDlgItem(IDC_BTN_ROTATE,this);
	m_BtnRotate.SetTooltipText(_T("任意角度旋转"));

	m_BtnMirror.SubclassDlgItem(IDC_BTN_MIRROR,this);
	m_BtnMirror.SetTooltipText(_T("左右镜像"));

	m_BtnFlip.SubclassDlgItem(IDC_BTN_FLIP,this);
	m_BtnFlip.SetTooltipText(_T("上下翻转"));

	//
	m_BtnMove.SubclassDlgItem(IDC_BTN_MOVE,this);
	m_BtnMove.SetTooltipText(_T("移动"));
	m_BtnMove.SetCheckBox();

	m_BtnSelect.SubclassDlgItem(IDC_BTN_SELECT,this);
	m_BtnSelect.SetTooltipText(_T("选择"));
	m_BtnSelect.SetCheckBox();

	m_BtnZoom.SubclassDlgItem(IDC_BTN_ZOOM,this);
	m_BtnZoom.SetTooltipText(_T("缩放"));
	m_BtnZoom.SetCheckBox();

	m_BtnLine.SubclassDlgItem(IDC_BTN_LINE,this);
	m_BtnLine.SetTooltipText(_T("画直线"));
	m_BtnLine.SetCheckBox();

	m_BtnRect.SubclassDlgItem(IDC_BTN_RECT,this);
	m_BtnRect.SetTooltipText(_T("画矩形"));
	m_BtnRect.SetCheckBox();

	m_BtnEllipse.SubclassDlgItem(IDC_BTN_ELLIPSE,this);
	m_BtnEllipse.SetTooltipText(_T("画椭圆"));
	m_BtnEllipse.SetCheckBox();

	m_BtnDist.SubclassDlgItem(IDC_BTN_DIST,this);
	m_BtnDist.SetTooltipText(_T("测距"));
	m_BtnDist.SetCheckBox();

	m_BtnDegree.SubclassDlgItem(IDC_BTN_DEGREE,this);
	m_BtnDegree.SetTooltipText(_T("量角"));
	m_BtnDegree.SetCheckBox();

	m_BtnText.SubclassDlgItem(IDC_BTN_TEXT,this);
	m_BtnText.SetTooltipText(_T("文字"));
	m_BtnText.SetCheckBox();

	//
	m_BtnNegative.SubclassDlgItem(IDC_BTN_NEGATIVE,this);
	m_BtnNegative.SetTooltipText(_T("负片"));

	m_BtnThreshold.SubclassDlgItem(IDC_BTN_THRESHOLD,this);
	m_BtnThreshold.SetTooltipText(_T("阈值"));

	m_BtnMean.SubclassDlgItem(IDC_BTN_MEAN,this);
	m_BtnMean.SetTooltipText(_T("均值滤波"));

	m_BtnMedian.SubclassDlgItem(IDC_BTN_MEDIAN,this);
	m_BtnMedian.SetTooltipText(_T("中值滤波"));

	m_BtnGauss.SubclassDlgItem(IDC_BTN_GAUSS,this);
	m_BtnGauss.SetTooltipText(_T("高斯滤波"));

	m_BtnEnhance.SubclassDlgItem(IDC_BTN_ENHANCE,this);
	m_BtnEnhance.SetTooltipText(_T("增强"));

	m_SliderGamma.SetRange(0,89);
	m_SliderGamma.SetTicFreq(10);

	double angle = atan(m_dbEditGamma);
	m_SliderGamma.SetPos((int)DEGREE(angle));

	m_Gamma.SetGamma(m_dbEditGamma);

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}
예제 #9
0
struct spectrum *
load_ellips_spectrum(const char *filename, struct extra_param *einf) {
    struct spectrum *spectr = NULL;
    enum spectra_kind spkind;
    FILE *f;
    int iseof, npt, nr;
    str_t ln;

sr_start:
    f = fopen(filename, "r");

    if(f == NULL) {
        notify_error_msg(LOADING_FILE_ERROR, "error loading spectra %s",
                         filename);
        return NULL;
    }

    str_init(ln, 64);
    str_getline(ln, f);
    if(strstr(CSTR(ln), "SE ALPHA BETA")) {
        spkind = AB_ELLISS_SPECTR;
    } else if(strstr(CSTR(ln), "SE PSI DELTA")) {
        spkind = PSIDEL_ELLISS_SPECTR;
    } else {
        goto no_good;
    }

    einf->aoi = 71.7;
    einf->analyzer = 25.0;
    einf->numap = 0.0;

    for(;;) {
        iseof = str_getline(ln, f);

        if(iseof != 0) {
            break;
        }

        nr = sscanf(CSTR(ln), "AOI %lf", & einf->aoi);
        if(nr == 1) {
            continue;
        }

        nr = sscanf(CSTR(ln), "NA %lf", & einf->numap);
        if(nr == 1) {
            continue;
        }

        nr = sscanf(CSTR(ln), "A %lf", & einf->analyzer);
        if(nr == 1) {
            continue;
        }

        break;
    }

    einf->aoi = DEGREE(einf->aoi);
    einf->analyzer = DEGREE(einf->analyzer);

    for(npt = 0; ; npt++, iseof = str_getline(ln, f)) {
        double a[3];
        double *dt[3] = {a, a+1, a+2};
        int k;

        if(spectr) {
            dt[0] = & spectr->lambda[npt];
            dt[1] = & spectr->data.ab[npt].alpha;
            dt[2] = & spectr->data.ab[npt].beta;
        }

        while(iseof == 0) {
            k = sscanf(CSTR(ln), "%*s %lf %lf %lf\n", dt[0], dt[1], dt[2]);
            if(k == 3) {
                break;
            }
            iseof = str_getline(ln, f);
        }

        if(iseof != 0) {
            if(spectr != NULL) {
                break;
            }

            if(npt < 2) {
                goto no_good;
            }

            spectr = emalloc(sizeof(struct spectrum));
            spectr->kind = spkind;
            spectr->npt = npt;
            spectr->lambda  = emalloc(npt * sizeof(double));
            spectr->data.ab = emalloc(npt * sizeof(struct elliss_ab));

            fclose(f);
            str_free(ln);

            goto sr_start;
        }
    }

    spectr->lmin = spectr->lambda[0];
    spectr->lmax = spectr->lambda[spectr->npt - 1];

    str_free(ln);
    fclose(f);

    return spectr;
no_good:
    notify_error_msg(LOADING_FILE_ERROR, "format of spectra %s is incorrect",
                     filename);
    str_free(ln);
    fclose(f);
    return NULL;
}
예제 #10
0
ClassLN PowMod(ClassLN &base, ClassLN &exp, ClassLN &mod)
{
    ClassLN res;
    res.num = DEGREE(base.num, exp.num, mod.num);
    return res;
}
예제 #11
0
inline void get_ra_dec(q3c_coord_t theta, q3c_coord_t phi, q3c_coord_t *ra,
															q3c_coord_t *dec)
{
	*dec =DEGREE(M_PI_2 - theta);
	*ra = DEGREE(phi); /* in theory between 0 and 2*M_PI but could wrap more than that*/
}
예제 #12
0
/* find_pair_edges:
 */
static void find_pair_edges(Agraph_t * g, Agnode_t * n, Agraph_t * outg)
{
    Agnode_t **neighbors_with;
    Agnode_t **neighbors_without;

    Agedge_t *e;
    Agedge_t *ep;
    Agedge_t *ex;
    Agnode_t *n1;
    Agnode_t *n2;
    int has_pair_edge;
    int diff;
    int has_pair_count = 0;
    int no_pair_count = 0;
    int node_degree;
    int edge_cnt = 0;

    node_degree = DEGREE(n);
    neighbors_with = N_GNEW(node_degree, Agnode_t *);
    neighbors_without = N_GNEW(node_degree, Agnode_t *);

    for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
	n1 = e->head;
	if (n1 == n)
	    n1 = e->tail;
	has_pair_edge = 0;
	for (ep = agfstedge(g, n); ep; ep = agnxtedge(g, ep, n)) {
	    if (ep == e)
		continue;
	    n2 = ep->head;
	    if (n2 == n)
		n2 = ep->tail;
	    ex = agfindedge(g, n1, n2);
	    if (ex) {
		has_pair_edge = 1;
		if (n1 < n2) {	/* count edge only once */
		    edge_cnt++;
		    if (ORIGE(ex)) {
			agdelete(outg, ORIGE(ex));
			ORIGE(ex) = 0;	/* delete only once */
		    }
		}
	    }
	}
	if (has_pair_edge) {
	    neighbors_with[has_pair_count] = n1;
	    has_pair_count++;
	} else {
	    neighbors_without[no_pair_count] = n1;
	    no_pair_count++;
	}
    }

    diff = node_degree - 1 - edge_cnt;
    if (diff > 0) {
	int mark;
	Agnode_t *hp;
	Agnode_t *tp;

	if (diff < no_pair_count) {
	    for (mark = 0; mark < no_pair_count; mark += 2) {
		if ((mark + 1) >= no_pair_count)
		    break;
		tp = neighbors_without[mark];
		hp = neighbors_without[mark + 1];
		agedge(g, tp, hp);
		DEGREE(tp)++;
		DEGREE(hp)++;
		diff--;
	    }

	    mark = 2;
	    while (diff > 0) {
		tp = neighbors_without[0];
		hp = neighbors_without[mark];
		agedge(g, tp, hp);
		DEGREE(tp)++;
		DEGREE(hp)++;
		mark++;
		diff--;
	    }
	}

	else if (diff == no_pair_count) {
	    tp = neighbors_with[0];
	    for (mark = 0; mark < no_pair_count; mark++) {
		hp = neighbors_without[mark];
		agedge(g, tp, hp);
		DEGREE(tp)++;
		DEGREE(hp)++;
	    }
	}
    }

    free(neighbors_without);
    free(neighbors_with);
}
예제 #13
0
void Transform::lookAt(const vec3& target, const vec3& up)
{
	rotation.x = DEGREE(atan2(target.z,target.y))-90;
	rotation.y = DEGREE(acos(target.z/(sqrt(target.x*target.x+target.y*target.y))));
	rotation.z = DEGREE(atan2(up.y, up.x))-90;
}