#include <math.h>
#include "GraphicsGems.h"
/*****************/
/* 2d library */
/*****************/
/* returns squared length of input vector */
double V2SquaredLength(a)
Vector2 *a;
{
return ((a->x * a->x) + (a->y * a->y));
};
double V2Length(a)
Vector2 *a;
{
return (sqrt(V2SquaredLength(a)));
};
/*negates the input of vector and returns it*/
Vector2 *V2Negate(v)
Vector2 *v;
{
v->x = -v->x;
v->y = -v->y;
return (v);
};
/* normalizes the input vector and returns it */
Vector2 *V2Normalize(v)
Vector2 *v;
{
double len = V2Length(v);
if(len != 0)
{
v->x /= len;
v->y /= len;
}
return(v);
};
/* scales the input vector to the new length and returns it */
Vector2 *V2Scale(v, newlen)
Vector2 *v;
double newlen;
{
double len = V2Length(v);
if(len != 0)
{
v->x *= newlen/len;
v->y *= newlen/len;
return(v);
}
};
/* return vector sum c = a+b*/
Vector2 *V2Add(a, b, c)
Vector2 *a;
Vector2 *b;
Vector2 *c;
{
c->x = a->x+b->x;
c->y = a->y+b->y;
return (c);
};
/* return vector difference c = a-b */
Vector2 *V2Sub(a, b, c)
Vector2 *a;
Vector2 *b;
Vector2 *c;
{
c->x = a->x-b->x;
c->y = a->y-b->y;
return (c);
};
/* return the dot product of vectors a and b */
double V2Dot(a, b)
Vector2 *a, *b;
{
return((a->x*b->x) + (a->y*b->y));
};
/* linearly interpolate between vectors by an amount alpha */
/* and return the resulting vector */
/* when alpha=0,result=lo. when alpha=1,result=hi.*/
Vector2 *V2Lerp(lo, hi, alpha, result)
Vector2 *lo, *hi, *result;
{
result->x = LERP(alpha, lo->x, hi->x);
result->y = LERP(alpha, lo->y, hi->y);
return(result);
}
/**************/
/* 3d library */
/**************/
/* returns squared length of input vector */
double V3SquaredLength(a)
Vector3 *a;
{
return ((a->x * a->x) + (a->y * a->y) + (a->z * a->z));
};
double V3Length(a)
Vector3 *a;
{
return (sqrt(V3SquaredLength(a)));
};
/*negates the input of vector and returns it*/
Vector3 *V3Negate(v)
Vector3 *v;
{
v->x = -v->x;
v->y = -v->y;
v->z = -v->z;
return (v);
};
/* normalizes the input vector and returns it */
Vector3 *V3Normalize(v)
Vector3 *v;
{
double len = V3Length(v);
if(len != 0)
{
v->x /= len;
v->y /= len;
v->z /= len;
}
return(v);
};
/* scales the input vector to the new length and returns it */
Vector3 *V3Scale(v, newlen)
Vector3 *v;
double newlen;
{
double len = V3Length(v);
if(len != 0)
{
v->x *= newlen/len;
v->y *= newlen/len;
v->z *= newlen/len;
return(v);
}
};
/* return vector sum c = a+b*/
Vector3 *V3Add(a, b, c)
Vector3 *a;
Vector3 *b;
Vector3 *c;
{
c->x = a->x+b->x;
c->y = a->y+b->y;
c->z = a->z+b->z;
return (c);
};
/* return vector difference c = a-b */
Vector3 *V3Sub(a, b, c)
Vector3 *a;
Vector3 *b;
Vector3 *c;
{
c->x = a->x-b->x;
c->y = a->y-b->y;
c->z = a->z-b->z;
return (c);
};
/* return the dot product of vectors a and b */
double V3Dot(a, b)
Vector3 *a, *b;
{
return((a->x*b->x) + (a->y*b->y) + (a->z*b->z));
};
没有合适的资源?快使用搜索试试~ 我知道了~
light_occur_polygon.rar_多面体 相交_多面体相交
共4个文件
c:2个
h:1个
txt:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 189 浏览量
2022-09-21
19:17:46
上传
评论
收藏 3KB RAR 举报
温馨提示
图形学中光线与多面体相交时,进行判断,是否越界,是否相交。比较好的例子
资源推荐
资源详情
资源评论
收起资源包目录
light_occur_polygon.rar (4个子文件)
GraphicsGems.h 3KB
www.pudn.com.txt 218B
ray-convex.c 3KB
GraphicsGems.c 3KB
共 4 条
- 1
资源评论
JaniceLu
- 粉丝: 78
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功