100分求助高手帮我把以下C#代码转换成C语言的代码

dopsop110 2010-05-23 08:32:03
1.
/// <summary>
/// 获取查询字符串
/// </summary>
public string GetQueryStr()
{
string str = " From T_PRC_Process as a "
+ " inner join T_BAS_WorkCenter as b on a.WorkCenterID=b.WorkCenterID "
+ " inner join T_PRC_PartSpecPara as c on a.PartSpecParaID=c.PartSpecParaID "
+ " inner join T_BAS_Bearing as d on a.BearingID=d.BearingID "
+ " inner join T_BAS_ForgePrcType as e ON a.FgPrcTypeID = e.FgPrcTypeID "
+ " left join T_PRC_ForgeFactoryProcess as f on a.ProcessID=IsNull(f.ProcessID,'') "
+ " left join T_BAS_ForgeFactory as g on IsNull(f.ForgeFactoryID,'')=IsNull(g.ForgeFactoryID,'') ";
return str;
}
---------------------------------------------------------------------------------------
2.
/// <summary>
/// 计算2条直线的相交点
/// </summary>
public double[] GetLineInt(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)
{
double[] p1 = new double[3] ;

double x5;
double y5;

if(((x3 - x4) * (y1 - y2) - (x1 - x2) * (y3 - y4)) != 0)
{
x5 = ((x1 - x2) * (x3 * y4 - x4 * y3) - (x3 - x4) * (x1 * y2 - x2 * y1)) / ((x3 - x4) * (y1 - y2) - (x1 - x2) * (y3 - y4));
y5 = ((y1 - y2) * (x3 * y4 - x4 * y3) - (x1 * y2 - x2 * y1) * (y3 - y4)) / ((y1 - y2) * (x3 - x4) - (x1 - x2) * (y3 - y4));

p1[0] = x5;
p1[1] = y5;
p1[2] = 0;
return p1;
}
else
{
return null;
}

}
--------------------------------------------------------
3.
/// <summary>
/// 描 述:获取线的角度
/// </summary>
public double GetLineAngle(double[] lineStartPoint,double[] lineEndPoint)
{
if (lineStartPoint[0]==lineEndPoint[0])
{
return Math.PI/2;
}
else
{
return Math.Atan( (lineStartPoint[1]-lineEndPoint[1])/(lineStartPoint[0]-lineEndPoint[0]) );
}
}
----------------------------------------------------------------
4.
/// <summary>
/// 描 述:获取一个点在线上的垂直点位置
/// </summary>
public double[] GetPointToLineVerticalPoint(double[] point,double[] lineStartPoint,double[] lineEndPoint)
{
double[] vp = new double[3];
string lineDirection=GetLineDirection(lineStartPoint,lineEndPoint);//该方法在下边
if (lineDirection=="H")
{//纵线
vp[0]=lineStartPoint[0];
vp[1]=point[1];
}
else if (lineDirection=="W")
{//横线
vp[0]=point[0];
vp[1]=lineStartPoint[1];
}
else
{//斜线
//先求ab的斜率
double k0 =(lineEndPoint[1]-lineStartPoint[1])/(lineEndPoint[0]-lineStartPoint[0]);
//其垂线的斜率为
double k1 = - 1/k0;

//垂足坐标:
double x=(point[1]-lineStartPoint[1]+lineStartPoint[0]*k0-point[0]*k1)/(k0-k1);

double y=point[1]+(x-point[0])*k1;

vp[0]=x;
vp[1]=y;
}
return vp;
}
-----------------------------------------
5.
/// <summary>
/// 描 述:获取线的方向,H 纵线,W 横线,S 斜线
/// </summary>
public string GetLineDirection(double[] p1,double[] p2)
{
if (Math.Round(p1[0],8)==Math.Round(p2[0],8))
{//纵线
return "H";
}
else if (Math.Round(p1[1],8)==Math.Round(p2[1],8))
{//横线
return "W";
}
else
{//斜线
return "S";
}
}
C语言实在是想不起来了,希望XDJM们帮忙
...全文
206 点赞 收藏 23
写回复
23 条回复
bobo364 2010年05月24日
像f.ForgeFactoryID这样的不好办是结构体还好办,是方法还要重写函数

/// <summary>
/// 获取查询字符串
/// </summary>
string GetQueryStr()
{
string str = " From T_PRC_Process as a "
+ " inner join T_BAS_WorkCenter as b on a.WorkCenterID=b.WorkCenterID "
+ " inner join T_PRC_PartSpecPara as c on a.PartSpecParaID=c.PartSpecParaID "
+ " inner join T_BAS_Bearing as d on a.BearingID=d.BearingID "
+ " inner join T_BAS_ForgePrcType as e ON a.FgPrcTypeID = e.FgPrcTypeID "
+ " left join T_PRC_ForgeFactoryProcess as f on a.ProcessID=IsNull(f.ProcessID,'') "
+ " left join T_BAS_ForgeFactory as g on IsNull(f.ForgeFactoryID,'')=IsNull(g.ForgeFactoryID,'') ";
return str;
}
回复 点赞
huanmie_09 2010年05月24日

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

#define PI 3.1415926535897931

char *GetQueryStr()
{
char *str;
str = (char *)malloc(1024*sizeof(char));
if(str == NULL) {
printf("malloc error!\n");
return NULL;
}
sprintf(str, " From T_PRC_Process as a "
" inner join T_BAS_WorkCenter as b on a.WorkCenterID=b.WorkCenterID "
" inner join T_PRC_PartSpecPara as c on a.PartSpecParaID=c.PartSpecParaID "
" inner join T_BAS_Bearing as d on a.BearingID=d.BearingID "
" inner join T_BAS_ForgePrcType as e ON a.FgPrcTypeID = e.FgPrcTypeID "
" left join T_PRC_ForgeFactoryProcess as f on a.ProcessID=IsNull(f.ProcessID,'') "
" left join T_BAS_ForgeFactory as g on IsNull(f.ForgeFactoryID,'')=IsNull(g.ForgeFactoryID,'') ");
return str;
}

/// <summary>
/// 计算2条直线的相交点
/// </summary>
double *GetLineInt(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)
{
double *p1 = (double *)malloc(3*sizeof(double));
if(p1 == NULL) {
printf("malloc error!\n");
return NULL;
}
double x5, y5;
if(((x3 - x4) * (y1 - y2) - (x1 - x2) * (y3 - y4)) != 0) {
x5 = ((x1 - x2) * (x3 * y4 - x4 * y3) - (x3 - x4) * (x1 * y2 - x2 * y1)) / ((x3 - x4) * (y1 - y2) - (x1 - x2) * (y3 - y4));
y5 = ((y1 - y2) * (x3 * y4 - x4 * y3) - (x1 * y2 - x2 * y1) * (y3 - y4)) / ((y1 - y2) * (x3 - x4) - (x1 - x2) * (y3 - y4));

p1[0] = x5;
p1[1] = y5;
p1[2] = 0;
return p1;
}
else {
free(p1);
return NULL;
}
}

/// <summary>
/// 描 述:获取线的角度
/// </summary>
double GetLineAngle(double *lineStartPoint,double *lineEndPoint)
{
if(lineStartPoint[0]==lineEndPoint[0]) {
return PI/2;
}
else {
return atan( (lineStartPoint[1]-lineEndPoint[1])/(lineStartPoint[0]-lineEndPoint[0]) );
}
}

/// <summary>
/// 描 述:获取线的方向,H 纵线,W 横线,S 斜线
/// </summary>
char GetLineDirection(double *p1,double *p2)
{


if (fabs(p1[0] - p2[0]) < 1e-9 ) {//纵线
return 'H';
}
else if (fabs(p1[1] - p2[2]) < 1e-9 ) {//横线
return 'W';
}
else {//斜线
return 'S';
}
}

/// <summary>
/// 描 述:获取一个点在线上的垂直点位置
/// </summary>
double *GetPointToLineVerticalPoint(double *point,double *lineStartPoint,double *lineEndPoint)
{
double *vp = (double *)malloc(3*sizeof(double));
char lineDirection;
if(vp == NULL) {
printf("malloc error!\n");
return NULL;
}
lineDirection = GetLineDirection(lineStartPoint,lineEndPoint);
if (lineDirection=='H') {//纵线
vp[0]=lineStartPoint[0];
vp[1]=point[1];
}
else if (lineDirection=='W') {//横线
vp[0]=point[0];
vp[1]=lineStartPoint[1];
}
else {//斜线
//先求ab的斜率
double k0 =(lineEndPoint[1]-lineStartPoint[1])/(lineEndPoint[0]-lineStartPoint[0]);
//其垂线的斜率为
double k1 = - 1/k0;

//垂足坐标:
double x=(point[1]-lineStartPoint[1]+lineStartPoint[0]*k0-point[0]*k1)/(k0-k1);

double y=point[1]+(x-point[0])*k1;

vp[0]=x;
vp[1]=y;
}
return vp;
}

回复 点赞
zhangyafei13 2010年05月24日
看看,学习学习
回复 点赞
AlanBruce 2010年05月24日
。。。。。。。。。。。。。。。。。。。。。。。。。
回复 点赞
dopsop110 2010年05月24日
后面几个可能大家对C#的这种计算方法不太懂,给出注释

Math.PI //圆的派值,就是3.145555那个
Math.Atan //返回正切值为指定数字的角度
Math.Round //舍弃小数的方法,第一个是小数值,第二个是精确到多少位

希望大家帮帮忙啊 谢谢啦
回复 点赞
wzywsk 2010年05月24日
可以反汇编后在转?
回复 点赞
yangyunzhao 2010年05月24日
楼上的网友,你们不是在帮楼主,而是在还楼主。
就是因为有了这么多“热心”网友,很多人上课就不认真了,“反正有人帮忙弄嘛”,作业不自己完成,能学到东西么?
回复 点赞
yanran_hill 2010年05月24日

1.
//不考虑线程安全
char * GetQueryStr()
{
static char str[] = " From T_PRC_Process as a "
" inner join T_BAS_WorkCenter as b on"
" a.WorkCenterID=b.WorkCenterID "
" inner join T_PRC_PartSpecPara as c on "
" a.PartSpecParaID=c.PartSpecParaID "
" inner join T_BAS_Bearing as d on a.BearingID=d.BearingID "
" inner join T_BAS_ForgePrcType as e ON a.FgPrcTypeID ="
" e.FgPrcTypeID "
" left join T_PRC_ForgeFactoryProcess as f on a.ProcessID="
" IsNull(f.ProcessID,'') "
" left join T_BAS_ForgeFactory as g on ""
"IsNull(f.ForgeFactoryID,'')=IsNull(g.ForgeFactoryID,'') ";
return str;
}
-------------------------------------------------------------------------------------
2.
double* GetLineInt(double x1,double y1,double x2,double y2,double x3,
double y3,double x4,double y4)
{
double * p1;

double x5;
double y5;

p1 = (double *)malloc(sizeof(double)*3);

if(((x3 - x4) * (y1 - y2) - (x1 - x2) * (y3 - y4)) != 0)
{
x5 = ((x1 - x2) * (x3 * y4 - x4 * y3) - (x3 - x4) * (x1 * y2 - x2 * y1)) /
((x3 - x4) * (y1 - y2) - (x1 - x2) * (y3 - y4));
y5 = ((y1 - y2) * (x3 * y4 - x4 * y3) - (x1 * y2 - x2 * y1) * (y3 - y4)) /
((y1 - y2) * (x3 - x4) - (x1 - x2) * (y3 - y4));

p1[0] = x5;
p1[1] = y5;
p1[2] = 0;
return p1;
}
else
{
delete[] p1;//需要释放空间
return NULL;
}
}
回复 点赞
dopsop110 2010年05月24日
哦 继续顶啊。。。。分不够可以加
回复 点赞
thanktheworld 2010年05月24日
小弟,你真厉害,佩服,我让同事把分都给你了。谢谢哈!
回复 点赞
dopsop110 2010年05月24日
谢谢你啊
回复 点赞
huanmie_09 2010年05月24日
大姐,
打印浮点数,用格式%f好不好.
for(int i=0;i<3;i++){
printf("%s",p1[i]); -->printf("%f",p1[i]);
}
另外,调用完double *p1=GetLineInt(15.0,11.0,20.0,12.0,15.0,20.0,30.0,13.0);
之后,最好判断一段p1是否为NULL,因为函数可能返回为NULL,如果为NULL的话,后面的循环打印就会出错了.
回复 点赞
thanktheworld 2010年05月24日
huanmie_09你不要分了吗,第二个问题你解决了,分就全给你了,要不别人给你解决了,都给别人了不太可惜了么。
回复 点赞
thanktheworld 2010年05月24日
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

#define PI 3.1415926535897931

double *GetLineInt(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)
{
double *p1 = (double *)malloc(3*sizeof(double));
if(p1 == NULL) {
printf("malloc error!\n");
return NULL;
}

double x5, y5;
if(((x3 - x4) * (y1 - y2) - (x1 - x2) * (y3 - y4)) != 0) {
x5 = ((x1 - x2) * (x3 * y4 - x4 * y3) - (x3 - x4) * (x1 * y2 - x2 * y1)) / ((x3 - x4) * (y1 - y2) - (x1 - x2) * (y3 - y4));
y5 = ((y1 - y2) * (x3 * y4 - x4 * y3) - (x1 * y2 - x2 * y1) * (y3 - y4)) / ((y1 - y2) * (x3 - x4) - (x1 - x2) * (y3 - y4));

p1[0] = x5;
p1[1] = y5;
p1[2] = 0;
return p1;
}
else {
free(p1);
return NULL;
}
}

int main(int argc, char *argv[])
{
double *p1=GetLineInt(15.0,11.0,20.0,12.0,15.0,20.0,30.0,13.0);
for(int i=0;i<3;i++){
printf("%s",p1[i]);
}
system("pause");
}

huanmie_09你试试

回复 点赞
thanktheworld 2010年05月24日
huanmie_09,你的第二个方法好像有问题啊,我分别在.net和c环境里测试了一下,得出的结果不一样啊。你看看是哪里出毛病了。
回复 点赞
renbin5566 2010年05月23日
lu guo
回复 点赞
cattycat 2010年05月23日
后面的需要math的库的,可能需要#include <cmath>
回复 点赞
cattycat 2010年05月23日
第一个去掉public就可以了。第二个返回数组的改成指针。其他的类似。

 string GetQueryStr()
{
string str = " From T_PRC_Process as a "
+ " inner join T_BAS_WorkCenter as b on a.WorkCenterID=b.WorkCenterID "
+ " inner join T_PRC_PartSpecPara as c on a.PartSpecParaID=c.PartSpecParaID "
+ " inner join T_BAS_Bearing as d on a.BearingID=d.BearingID "
+ " inner join T_BAS_ForgePrcType as e ON a.FgPrcTypeID = e.FgPrcTypeID "
+ " left join T_PRC_ForgeFactoryProcess as f on a.ProcessID=IsNull(f.ProcessID,'') "
+ " left join T_BAS_ForgeFactory as g on IsNull(f.ForgeFactoryID,'')=IsNull(g.ForgeFactoryID,'') ";
return str;
}
---------------------------------------------------------------------------------------
2.
/// <summary>
/// 计算2条直线的相交点
/// </summary>
double* GetLineInt(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)
{
double* p1 = new double[3] ;

double x5;
double y5;

if(((x3 - x4) * (y1 - y2) - (x1 - x2) * (y3 - y4)) != 0)
{
x5 = ((x1 - x2) * (x3 * y4 - x4 * y3) - (x3 - x4) * (x1 * y2 - x2 * y1)) / ((x3 - x4) * (y1 - y2) - (x1 - x2) * (y3 - y4));
y5 = ((y1 - y2) * (x3 * y4 - x4 * y3) - (x1 * y2 - x2 * y1) * (y3 - y4)) / ((y1 - y2) * (x3 - x4) - (x1 - x2) * (y3 - y4));

p1[0] = x5;
p1[1] = y5;
p1[2] = 0;
return p1;
}
else
{
delete[] p1;//需要释放空间
return NULL;
}

}
回复 点赞
zhaiershuaixu 2010年05月23日
不为jf,帮你顶了,下学期可能开c#.
回复 点赞
qifeifei 2010年05月23日
楼主啊,这个任务大了啊,你给我多少分啊。
回复 点赞
发动态
发帖子
C语言
创建于2007-09-28

3.2w+

社区成员

24.0w+

社区内容

C语言相关问题讨论
社区公告
暂无公告