c语言编出的图形如直线是以左上角为(0,0)点如何调整成符合习惯的坐标系

来源:百度知道 编辑:UC知道 时间:2024/06/21 19:42:04
即左下角为原点的平面直角坐标系

c语言本身是无法调整的,但是如果为了使用原点为左下角的坐标系完全可以用坐标变

换实现,你只需要自己写一个自己的直线函数,即参数为以左下角为原点的直线的端点

的直线函数。并在函数中作一次坐标变换就可以了,举个例子:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
/*直线函数*/
void myline(int x1, int y1, int x2, int y2)
{
int ymax = getmaxy(); /*获得屏幕最低点的y坐标*/
y1 = ymax - y1; /*坐标变换*/
y2 = ymax - y2;
line(x1, y1, x2, y2);
}
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int xmax, ymax;

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "h:\\work\\tc3\\bgi");

/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
print