#ifndef _BALL_VC_SUPER_ADMI_2009_12_13_INCLUDE_
#define _BALL_VC_SUPER_ADMI_2009_12_13_INCLUDE_
typedef struct tagPOINT3D //3D坐标系
{
float x
float y
float z
}POINT3D
typedef struct tagBALL //球
{
POINT3D cur_coor
POINT3D speed
float radius
}BALL
typedef struct tagBOX //球的长方体运动场所,中空
{
POINT3D angle_coor[8]//坐标,从下往上,顺时针
float length
float width
float height
}BOX
void init_box(BOX *mybox,POINT3D origi_coor,POINT3D LWH)
{
int i
mybox->height=LWH.x
mybox->width=LWH.y
mybox->height=LWH.z
for(i=0i<8i++)mybox->angle_coor[i]=origi_coor
mybox->angle_coor[1].x=origi_coor.x+LWH.x
mybox->angle_coor[2].x=origi_coor.x+LWH.x
mybox->angle_coor[2].y=origi_coor.y+LWH.y
mybox->angle_coor[3].y=origi_coor.y+LWH.y
for(i=4i<8i++)mybox->angle_coor[i].z=origi_coor.z+LWH.z
mybox->angle_coor[5].x=origi_coor.x+LWH.x
mybox->angle_coor[6].x=origi_coor.x+LWH.x
mybox->angle_coor[6].y=origi_coor.y+LWH.y
mybox->angle_coor[7].y=origi_coor.y+LWH.y
}
void move_in_box(BALL* myball,BOX mybox) //匀速运动
{
myball->cur_coor.x+=myball->speed.x
myball->cur_coor.y+=myball->speed.y
myball->cur_coor.z+=myball->speed.z
}
void hit_wall(BALL* myball,POINT3D dir)//撞墙
{
myball->speed.x*=dir.x
myball->speed.y*=dir.y
myball->speed.z*=dir.z
}
int coll_dete_rad_ign(BALL* myball,BOX mybox) //检测(忽略半径)
{
POINT3D dir
dir.x=1dir.y=1dir.z=1
if(myball->cur_coor.x<=mybox.angle_coor[0].x ||myball->cur_coor.x>=mybox.angle_coor[6].x)
dir.x=-1
if(myball->cur_coor.y<=mybox.angle_coor[0].y ||myball->cur_coor.y>=mybox.angle_coor[6].y)
dir.y=-1
if(myball->cur_coor.z<=mybox.angle_coor[0].z ||myball->cur_coor.z>=mybox.angle_coor[6].z)
dir.z=-1
if(dir.x==-1 ||dir.y==-1 ||dir.z==-1){hit_wall(myball,dir)return 1}
return 0
}
#endif
//BALL.H文件结束
/*Ball.c:测试代码*/
#include "Ball.h"
#include <stdio.h>
int main(void)
{
POINT3D origi
POINT3D LWH
BOX mybox
BALL myball
int i
origi.x=0origi.y=0origi.z=0
printf("矩形空间尺寸:")
scanf("%f%f%f",&LWH.x,&LWH.y,&LWH.z)
printf("球的初始坐标:")
scanf("%f%f%f",&myball.cur_coor.x,&myball.cur_coor.y,&myball.cur_coor.z)
printf("球的速度:")
scanf("%f%f%f",&myball.speed.x,&myball.speed.y,&myball.speed.z)
/* LWH.x=10LWH.y=10LWH.z=10
myball.cur_coor.x=5myball.cur_coor.y=5myball.cur_coor.z=5
myball.speed.x=0.2myball.speed.y=0.5myball.speed.z=1*/
i=0init_box(&mybox,origi,LWH)
printf("\n相关信息如下:\n")
printf("矩形空间尺寸--L:%f,W:%f,H:%f\n",LWH.x,LWH.y,LWH.z)
printf("球的初始坐标--X:%f,Y:%f,Z:%f\n",myball.cur_coor.x,myball.cur_coor.y,myball.cur_coor.z)
printf("球的初始速度--X:%f,Y:%f,Z:%f\n",myball.speed.x,myball.speed.y,myball.speed.z)
printf("碰撞点坐标如下:\n")
while(i<10)
{
if(coll_dete_rad_ign(&myball,mybox)==1)
{
i++
printf("%f,%f,%f\n",myball.cur_coor.x,myball.cur_coor.y,myball.cur_coor.z)
}
move_in_box(&myball,mybox)
}
return 0
}
#include<iostream>using namespace stdint main() { int mfloat i,h1,h2cout<<"请输入皮球初始高度:"<<endlcin>>h1cout<<"请输入皮球d跳次数:"<<endlcin>>mh2=h1for(i=1i<=mi++) { h2=h2+h1h1=h1/2} cout<<"第"<<m<<"次的反d高度是:"<<h1<<endlcout<<"经过路程是:"<<h2<<endlreturn 0}编写程序,求由键盘按顺时针方向输入n个顶点坐标的多边形周长。注:各顶点坐标以结构体表示,n值不超过10。输入:第一行输入一个整数,作为n值;以后每行两个浮点数,为多边形各顶点的坐标。输出:多边形的周长,精确到小数点后2位。样例1:输入4欢迎分享,转载请注明来源:内存溢出
评论列表(0条)