我有一个非常普遍的问题.我希望确定多个物体的边界点(包括30-50个闭合多边形(z),每个具有大约300个点(x,y,z)).我正在使用固定视口,该视口围绕x,y和z轴旋转(alpha,beta,gamma),这是多边形坐标系的原点.
我认为它有两种可能性:透视投影或光线追踪.透视投影似乎需要对每个点进行大量矩阵运算,以确定其位置是否在视口内.或者给定大量的点我最好将视口像素光线追踪到对象?即确定是否存在交叉点,然后确定是否在对象内或外交叉处发生交叉.在任何一种情况下,我都会将此结果写为0(外部)或1(内部)到200x200,表示视口的整数矩阵
谢谢你的期待
我希望确定点P(x,y,z)是否位于由其中心C(cx,cy,cz),半径R定义的3D空间中的2D圆内,以及圆位于N上的平面的法线.
我知道在3D空间中位于2D圆上的点P由以下定义:
P = R*cos(t)U + R sin(t)*(N × U)+ C.
其中U是从圆心到圆上任意点的单位矢量.但考虑到Q点,我如何知道Q是在圆圈内还是在圆圈内?t选择适当的参数是什么?我在哪个坐标上比较点Q,看它们是否在圆圈内?
谢谢.
我正在尝试做一些涉及光线追踪的计算,但有点困惑.假设我有一个n-by-n图像,包含N个几何图元,l个光源和kxk超级采样.在最坏的情况下,我会计算多少个光线交叉点?如果我在深度d的反射/折射中加入怎么办?
我正在阅读其他人的代码,他将平面表示为法线和偏移,但我不确定该偏移是什么.我想这是从世界起源到飞机中心的距离?
谢谢
我正在做一个关于光线追踪的项目,现在我可以做一些基本的渲染.
下图有:
镜面反射,折射,纹理映射和阴影.

我正在努力做有光泽的反射,到目前为止这是我得到的.谁能告诉我这个有光泽的反射图像是否有任何问题?

相比之下,下面的图像来自镜面反射

这是关于光泽反射的代码,基本上,一旦主光线与对象相交.从这个交叉点,它会随机拍摄另外80条光线,并取出这80条光线的平均颜色.我对这段代码的问题是x和y的大小,我必须将它们除以某个值,在这种情况下是16,这样光泽反射光线不会太随机.这个逻辑有什么问题吗?
Colour c(0, 0, 0);
for (int i = 0; i < 80; i++) {
Ray3D testRay;
double a = rand() / (double) RAND_MAX;
double b = rand() / (double) RAND_MAX;
double theta = acos(pow((1 - a), ray.intersection.mat->reflectivity));
double phi = 2 * M_PI * b;
double x = sin(phi) * cos(theta)/16;
double y = sin(phi) * sin(theta)/16;
double z = cos(phi);
Vector3D u = reflect.dir.cross(ray.intersection.normal);
Vector3D v = reflect.dir.cross(u);
testRay.dir = x * u …Run Code Online (Sandbox Code Playgroud) 我要编写一个raytracer,但是我似乎已经遇到了我的第一个大问题。出于任何原因,我的球体(自从我才开始-当光线被击中时,我只是将颜色涂成白色)被渲染为椭圆形。
此外,当我将球的中心远离 x = 0 and y = 0
这是交集和主循环代码:
double const Sphere::getIntersection(Ray const& ray) const
{
double t;
double A = 1;
double B = 2*( ray.dir[0]*(ray.origin[0] - center_[0]) + ray.dir[1] * (ray.origin[1] - center_[1]) + ray.dir[2] * (ray.origin[2] - center_[2]));
double C = pow(ray.origin[0]-center_[0], 2) + pow(ray.origin[1]-center_[1], 2) + pow(ray.origin[2] - center_[2], 2) - radius_pow2_;
double discr = B*B - 4*C;
if(discr > 0)
{
t = (-B - sqrt(discr))/2;
if(t <= 0)
{
t = (-B + …Run Code Online (Sandbox Code Playgroud) Kd算法从创建根BSP节点开始,通过对基元数组(三角形,球体......)进行分区,以创建用于创建其两个子树的两个新数组(左和右基元).
通过将给定的基元数组分成两个数组来计算左和右基元.通过取每个三角形的间隔的中点(投影到给定轴(x,y或z)上)的中值来计算分割平面位置.
例如,具有x坐标的三角形:1,2,3具有中点1 =(3-1)/ 2(沿着x轴)具有x坐标的三角形:2,3,8具有中点3 = (8-2)/ 2(沿x轴)具有x坐标的三角形:4,3,8具有中点2.5 =(8-3)/ 2(沿x轴)包含这些的原始数组三个三角形由平面划分,平行于x = 2.5(中位数)平行于yz平面.生成的左基元数组包含三个三角形,生成的右基元数组包含三个三角形.
具有左和右基元的两个结果阵列用于构造Kd节点的左子树和右子树(基元仅存储在叶节点处).
对于左子树:
If (the left primitives are empty) then the left subtree points to NULL
else if (the number of left primitives is smaller than the minimal number || the depth == 1) then the left subtree is a leaf node
else the left subtree is another tree.
create the left subtree with the left primitives along the axis (++axis % 3) with --depth as depth and the …Run Code Online (Sandbox Code Playgroud) 我正在用Java编写一个Raytracer,我已经达到了可以创建对象,光线,测试交叉点然后着色像素的程度.我也做了一些基本的抗锯齿.我的问题是,如果创建一个球体,这应该是世界上(即中心0.0,0.0,0.0),然后绘制图像,我结束了这样的画面.

当红色圆圈应该在图像的中间.
public static void main(String[] args) {
System.out.println("Rendering...");
long start = System.nanoTime();
// Setting up the size of the image to be rendered
world = new World(1920, 1080, 1.0);
image = new Image("image.png");
sampler = new SimpleSampler(4);
projector = new OrthographicProjector();
// Main loop of program, goes through each pixel in image and assigns a colour value
for (int y = 0; y < world.viewPlane.height; y++) {
for (int x = 0; …Run Code Online (Sandbox Code Playgroud) 嗨,我正在实现蒙特卡洛路径跟踪,并且工作正常,但看起来交集代码存在一些问题。以下是图片
如果您在左上角看到红色,似乎是在显示背景颜色。
以下是
float intersectQuad(Ray r, float3 p1, float3 p2, float3 p3, float3 p4,
float3* outNormal)
{
const float3 x1 = p2 - p1;
const float3 x2 = p4 - p1;
const float3 n = (cross(x2, x1));
const float denom = dot(n, r.dir);
if (denom < 0.00000000001f) return 0.0f;
const float3 p0l0 = (p1 - r.origin);
const float t = dot(p0l0, n) / denom;
if( t < 0.000000000001f ) return 0.0f;
const float3 hitPoint = r.origin + r.dir * t; …Run Code Online (Sandbox Code Playgroud) 我已经更改了帖子,并发布了我的整个代码!有人可以告诉我如何优化它吗?
import Base: *, +, -, /, ^
using Images
const ? = convert(Float64, ?)
#define vector
mutable struct Vec3
x::Float64
y::Float64
z::Float64
end
function +(u::Vec3, v::Vec3)
Vec3(u.x+v.x, u.y+v.y, u.z+v.z)
end
function -(u::Vec3, v::Vec3)
Vec3(u.x-v.x, u.y-v.y, u.z-v.z)
end
function /(u::Vec3, v::Float64)
Vec3(u.x/v, u.y/v, u.z/v)
end
function *(u, v::Vec3)
if typeof(u) == Float64
Vec3(u*v.x, u*v.y, u*v.z)
elseif typeof(u) == Vec3
Vec3(u.x*v.x, u.y*v.y, u.z*v.z)
end
end
function ^(u::Vec3, v::Float64)
Vec3(u.x^v, u.y^v, u.z^v)
end
function dot(u::Vec3, v::Vec3)
u.x*v.x + u.y*v.y + u.z*v.z
end …Run Code Online (Sandbox Code Playgroud) raytracing ×10
c++ ×3
graphics ×3
math ×3
bsp ×1
game-engine ×1
geometry ×1
java ×1
julia ×1
matrix ×1
opencl ×1
projection ×1