c語言坐標函數
1. 用c語言定義一個坐標點類型Point,每個Point有成員x, y表示其坐標。輸入一個函數,求象限
用c語言定義一個坐標點類型Point,每個Point有成員x, y表示其坐標。輸入一個函數,求象限
這么早已經習慣每天
2. 求用c語言實現直角坐標(x,y,z)轉換為球坐標(r,angle_a,angle_b),非常感謝
首先,matlab 本身提供了把直角坐標轉化為極坐標的函數cart2pol。調用方法為:
[TH,R] = cart2pol(X,Y) TH 是極坐標的角度坐標,R 是距離坐標。
[TH,R,Z] = cart2pol(X,Y,Z) 這個函數同時支持3維直角坐標到柱坐標的轉換。
如果因為是作業或者練習,一定要自己寫一個的話,請繼續往下看。
考慮到這個程序的性質,編成一個函數比較適合。編寫這個函數需要用到直角坐標與極坐標的數學關系。考慮到輸入參數可能是一個向量或矩陣,關系式裡面的運算符應該用加點運算符。
函數代碼如下:
function [ TH,R ] = mycart2pol(X,Y)
%this function transforms corresponding elements of data
%stored in Cartesian coordinates X,Y to polar coordinates
%angle TH and radius R.
R=(X.^2+Y.^2).^0.5;
TH=atan(Y./X);
end
測試結果如下:
3. c語言中若要輸入坐標應該怎麼辦
先算出縱坐標的源值,然後
用二維數組來存儲坐標,如:int a[5][5]; 可以用a[0][0] a[0][1]....
a[i][j]....a[4][3] a[4][4],來存儲5對坐標值,i、j分別是橫坐標和縱坐標。
4. C語言設計函數頂點坐標
參考代碼如下:
函數頭文件CalC.h
doublearround(doublex[],doubley[],intp);
函數定義文件CalC.c
#include<math.h>
doublearround(doublex[],doubley[],intp)
{
inti;
doubleC=0;//周長
doublel_p_i;//第i條邊長度
for(i=0;i<p;i++)
{
l_p_i=sqrt((y[i+1]-y[i])*(y[i+1]-y[i])+(x[i+1]-x[i])*(x[i+1]-x[i]));
printf("第%d條邊長=%f ",i+1,l_p_i);
C+=l_p_i;
}
returnC;
}
主文件main.c
#include<stdio.h>
#include"CalC.h"
intmain(void)
{
doublex[3]={0.0,4.0,4.0};
doubley[3]={0.0,0.0,3.0};
intp=3;
doubleC=0.0;//周長
C=arround(x,y,p);
printf("C=%f ",C);
return0;
}
效果圖
5. 用C語言編寫一個程序:定義一個點的坐標,然後定義兩個點,求這兩個點間的距離。
#include<stdio.h>
#include<math.h>
structPoint
{
doublex,y;
};
/**.*/
doubledistance(conststructPoint*a,conststructPoint*b)
{
returnsqrt((a->x-b->x)*(a->x-b->x)+(a->y-b->y)*(a->y-b->y));
}
intmain()
{
structPointa,b;
printf("Pleaseinputthefirstpoint:");
scanf("%lf%lf",&a.x,&a.y);
printf("Pleaseinputthesecondpoint:");
scanf("%lf%lf",&b.x,&b.y);
printf("Thedistanceofthetwopointis%f. ",distance(&a,&b));
return0;
}
說明:
1、distance() 函數的兩個參數 const struct Point *a 和 b 使用了 const 修飾,是表示 a 和 b 在函數執行過程中不會被修改;這樣即使函數體內部寫錯,修改了 a 和 b 的值,編譯也不會通過。
2、對 double,scanf 用 %lf,printf 用 %f。
以上。
6. C語言,如何在指定坐標輸入數據
用gotoxy和gets吧~~~
gotoxy(old_x,old_y);//跳轉到指定坐標輸出信息
cprintf("User Name:");//在指定坐標處輸出User Name:
gotoxy(old_x,old_y+2);//跳轉到指定坐標輸入信息
gets(name);//輸入用戶名,name為所定義的字元數組
這是我做一個游戲界面的用戶名和密碼輸入的代碼~~你看看吧,希望對你有所幫助。。
7. C語言如何將坐標中的(x,y)提取出來
用ReadConsoleOutputCharacterA函數,在windows.h中。
給你一個封好的函數吧,其作用是提取出窗口中第x行y列的位置的字元是什麼。(如果沒有東西會返回空格符號)。
#include<windows.h>
//下標從1開始,x行y列。
charGetStr(intx,inty)
{
COORDpos;
//ReadConsoleOutputCharacterA里的x和y指的是x列y行,且從0開始標號
pos.X=y-1;pos.Y=x-1;
LPSTRstr;
DWORDread;
ReadConsoleOutputCharacterA(GetStdHandle(STD_OUTPUT_HANDLE),str,1,pos,&read);
returnstr[0];
}
使用舉例:
intmain()
{
printf("kjndfgdfg khgfhfhfgd jifdgdfgg ");
printf("1,2:%c ",GetStr(1,2));
return0;
}
輸出為
kjndfgdfg
khgfhfhfgd
jifdgdfgg
1,2:j
8. 求高手們用C語言編寫一個函數,根據兩個變數自動顯示點的坐標(X,Y,Z)
//class是寫成類嗎,這個寫成類有點多此一舉,下面用最簡單的函數寫的,變數自己改成英文命名
1.h
#include<stdio.h>
#include<math.h>
//宏定義值
#definehXX
#defineLXX
#defineαXX
doubleβ,θ;
doubleA[3],B[3],M[3];
voidmath(β,θ,A,B,M);
1.cpp
#include"1.h"
math(β,θ,A,B,M)
{
A[0]=L*sin(fabs(θ-α));
A[1]=L*cos(fabs(θ-α))*cosβ;
A[2]=L*cos(fabs(θ-α))*sinβ,
//公式太長自己寫
}
voidmain()
{
printf("請輸入β,θ的值: ");
scanf("%f,%f",&β,&θ);
math(β,θ,A,B,M);
printf("A的坐標為:(%f,%f,%f) ",A[0],A[1],A[2]);
//輸出自己寫
}
9. C語言編程坐標曲線
下面是的是昨天的,但是修改了一下坐標的刻度.
/*******************************************************
*Author :Wacs5
*Date :20090105(YYYY-MM-DD)
*Function :畫簡易的曲線圖 *********************************************************/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
#include <Graphics.h>
#define n 8
int main()
{
int i,j;
float data[]={7,3,12,6,9,5,8,11};
char str[40];
int gdrive=DETECT,gmode,errorcode;
int maxx,maxy;
int perx,pery;
int x0,x1,y0,y1;
int coloraxis=2,colorline=3;
float mindata,maxdata,ndata;
initgraph(&gdrive,&gmode,""); /*初始化設備*/
if ((errorcode=graphresult())!=grOk) /*查錯*/
{
printf("Graphics error:%s\nPress any key to exit:",grapherrormsg(errorcode));
getch();
exit(1);
}
maxx=getmaxx();
maxy=getmaxy();
mindata=0;
maxdata=data[0];
for (i=1;i<n;i++)
if (maxdata<data[i])
maxdata=data[i];
perx=maxx/(n+4);
pery=maxy/(maxdata-mindata+4);
x0=2*perx;
y0=maxy-2*pery;
x1=maxx-2*perx;
y1=2*pery;
setcolor(coloraxis);
line(x0,y0,x1,y0);
line(x0,y0,x0,y1);
line(x1,y0,x1-4,y0+3);
line(x1,y0,x1-4,y0-3);
line(x0,y1,x0+3,y1+4);
line(x0,y1,x0-3,y1+4);
settextjustify(CENTER_TEXT,TOP_TEXT);
for (i=0;i<=n;i++)
{
j=x0+i*perx;
line(j,y0,j,y0+2); /*刻度線*/
sprintf(str,"%d",i);
outtextxy(j,y0+4,str);
}
settextjustify(RIGHT_TEXT,CENTER_TEXT);
for (i=1;i<=12;i++)
{
j=y0-i*pery;
line(x0,j,x0-2,j); /*刻度線*/
sprintf(str,"%d",i);
outtextxy(x0-4,j,str);
}
setcolor(colorline);
x1=x0+perx;
y1=y0-(data[0]-mindata)*pery;
circle(x1,y1,2);
moveto(x1,y1);
i=1;
do
{
x1+=perx;
y1=y0-(data[i]-mindata)*pery;
lineto(x1,y1);
circle(x1,y1,2);
moveto(x1,y1);
i++;
}while(i<n);
getch();
closegraph();
return 0;
}