将3d球体投影到屏幕上的2d圆圈中

时间:2022-09-10 18:35:59

What are some rasterization algorithms that can just project a 3d sphere into a pixel grid? I want to avoid ray casting. Essentially, given a 3d coordinate and a radius, is there a quick way to just create a 2d circle/ellipse on a pixel grid?

什么是可以将3d球体投影到像素网格中的一些光栅化算法?我想避免光线投射。基本上,给定一个3d坐标和一个半径,是否有一种快速的方法可以在像素网格上创建一个2d圆/椭圆?

For example: circle at (2,2,2) with radius 4 gets projected to five pixels: p1(2,0)p2(0,1) p3(1,1) p4(2,1)p5(1,2)

例如:半径为4的(2,2,2)圆被投影到五个像素:p1(2,0)p2(0,1)p3(1,1)p4(2,1)p5(1,2) )

I have come across techniques such as pixel splatting for particle systems but I haven't found a clear answer on how to do this.

我遇到了像粒子系统的像素喷溅等技术但我没有找到关于如何做到这一点的明确答案。

Thanks

6 个解决方案

#1


What projection do you have?

你有什么预测?

I'm quite sure the projection isn't a circle in the most interesting ones. Hm. I guess the way I would do it would be to find the circumference circle in 3d whose axis* is aligned to the camera point. Pick whatever points needed from the circle and then transform them to screen space. Most simply, that would give you a polygon, but interpolated splines should probably also give you nice results.

我很确定投影不是最有趣的投影。嗯。我想我会这样做的方法是找到3d中的圆周圆,其轴*与摄像机点对齐。从圆圈中选择所需的任何点,然后将它们转换为屏幕空间。最简单的说,这会给你一个多边形,但插值样条也应该给你很好的结果。

*: axis of rotational symmetry

*:旋转对称轴

#2


I don't understand your problem 100%. Is your pixel grid = pixel in screen space or there's a fix ratio?

我不明白你的问题100%。您的像素网格=屏幕空间中的像素还是有固定比率?

From my best guess, you can try these:

从我最好的猜测,你可以尝试这些:

Map the internal view port coordinate with the screen space pixel and calculate a ratio. Use that ratio to place your object exactly where you wanted. I've written an D3D apps, windows based (not fullscreen) using this method to allow mouse interaction with the 3D objects. This allow moving and resizing the obejct using mouse which makes it feels like ordinary windows apps. I had work out the ratio by trial and error (I wasn't good with matrix calculation).

将内部视图端口坐标映射到屏幕空间像素并计算比率。使用该比率将对象准确放置在您想要的位置。我使用这种方法编写了一个D3D应用程序,基于窗口(不是全屏),允许鼠标与3D对象进行交互。这允许使用鼠标移动和调整对象的大小,这使它感觉像普通的Windows应用程序。我通过反复试验计算了这个比率(我对矩阵计算不好)。

If you didn't disturb the view projection matrix like I did above, the 3D coordinate is -1.0f to 1.0f left to right and bottom to top. Thus you can easily work out the ratio and place your object appropriately using the same method above

如果您没有像我上面那样打扰视图投影矩阵,则3D坐标从左到右,从下到上依次为-1.0f到1.0f。因此,您可以使用上述相同的方法轻松计算出比例并适当放置对象

#3


Perhaps the simplest way (if you don't mind some linear algebra) is to use a 4x4 projection transformation matrix. In fact, just about any kind of 3D transformation can be performed using a 4x4 matrix.

也许最简单的方法(如果你不介意一些线性代数)是使用4x4投影变换矩阵。实际上,几乎可以使用4x4矩阵执行任何类型的3D变换。

Here is a Wikipedia article to get you started.

这是一篇*文章,可以帮助您入门。

#4


It sounds like you're willing to put up with a little unfaithfulness to a true projection to get simpler calculations. If so, follow along...

听起来你似乎愿意忍受一些不忠实的真实投影来获得更简单的计算。如果是这样,请跟随......

I will start by assuming you can shift, rotate and resize the sphere to match the coordinate system of the projected circle. Let's call r the radius for both of them, and assume the center is at (0,0,0) for the sphere and (0,0) for the circle. The X axis runs left-right for both, the Y axis runs bottom-top for both, and the Z axis runs back to front for the sphere.

我将首先假设您可以移动,旋转和调整球体的大小以匹配投影圆的坐标系。让我们将r调用为两者的半径,并假设球体的中心位于(0,0,0),圆圈的中心位于(0,0)。 X轴向左右两个运行,Y轴为两个运行的底部,Z轴向前运行为球体。

Here's the fun part: you're done. The X and Y coordinates are identical for both the sphere and the circle! If the Z coordinate is positive, the point is visible, if it's negative the point is hidden on the back side of the sphere.

这是有趣的部分:你已经完成了。球体和圆形的X和Y坐标是相同的!如果Z坐标为正,则该点是可见的,如果它是负的,则该点隐藏在球体的背面。

#5


cool, so assuming you just take the x,y out of the x,y,z of the sphere to form your circle. How do you go about shading the appropriate pixels on a pixel grid?. Basically, what's the algorithm for rasterizing a circle?

很酷,所以假设你只是将x,y从球体的x,y,z中取出来形成你的圆圈。你如何在像素网格上着色适当的像素?基本上,光栅化圆的算法是什么?

#6


The projection of a sphere onto a plane is an ellipse, but it can be approximated with a circle. This can be done almost the same as the perspective projection of a point.

球体在平面上的投影是椭圆形,但可以用圆形近似。这可以与点的透视投影几乎相同。

Assume the center of the screen is (X=0,Y=0), and the viewer is located at (X=0,Y=0,Z=0). If the sphere is at (sX,sY,sZ) with a radius of sR, and the screen is D units away from the viewer (focal distance), then the circle will be at (cX = sX * D / sZ, cY = sY * D / sZ) with a radius of cR = sR * D / sZ. Everything is simply scaled by D / sZ.

假设屏幕的中心是(X = 0,Y = 0),并且观察者位于(X = 0,Y = 0,Z = 0)。如果球体位于半径为sR的(sX,sY,sZ),并且屏幕距离观察者D个单位(焦距),那么圆圈将处于(cX = sX * D / sZ,cY = sY * D / sZ)半径为cR = sR * D / sZ。一切都只是由D / sZ缩放。

This circle is only a good approximation of the sphere projection if the focal distance (D) is large, or the sX and sY coordinates of the sphere are near to zero.

如果焦距(D)大,或者球的sX和sY坐标接近零,则该圆仅是球投影的良好近似。

#1


What projection do you have?

你有什么预测?

I'm quite sure the projection isn't a circle in the most interesting ones. Hm. I guess the way I would do it would be to find the circumference circle in 3d whose axis* is aligned to the camera point. Pick whatever points needed from the circle and then transform them to screen space. Most simply, that would give you a polygon, but interpolated splines should probably also give you nice results.

我很确定投影不是最有趣的投影。嗯。我想我会这样做的方法是找到3d中的圆周圆,其轴*与摄像机点对齐。从圆圈中选择所需的任何点,然后将它们转换为屏幕空间。最简单的说,这会给你一个多边形,但插值样条也应该给你很好的结果。

*: axis of rotational symmetry

*:旋转对称轴

#2


I don't understand your problem 100%. Is your pixel grid = pixel in screen space or there's a fix ratio?

我不明白你的问题100%。您的像素网格=屏幕空间中的像素还是有固定比率?

From my best guess, you can try these:

从我最好的猜测,你可以尝试这些:

Map the internal view port coordinate with the screen space pixel and calculate a ratio. Use that ratio to place your object exactly where you wanted. I've written an D3D apps, windows based (not fullscreen) using this method to allow mouse interaction with the 3D objects. This allow moving and resizing the obejct using mouse which makes it feels like ordinary windows apps. I had work out the ratio by trial and error (I wasn't good with matrix calculation).

将内部视图端口坐标映射到屏幕空间像素并计算比率。使用该比率将对象准确放置在您想要的位置。我使用这种方法编写了一个D3D应用程序,基于窗口(不是全屏),允许鼠标与3D对象进行交互。这允许使用鼠标移动和调整对象的大小,这使它感觉像普通的Windows应用程序。我通过反复试验计算了这个比率(我对矩阵计算不好)。

If you didn't disturb the view projection matrix like I did above, the 3D coordinate is -1.0f to 1.0f left to right and bottom to top. Thus you can easily work out the ratio and place your object appropriately using the same method above

如果您没有像我上面那样打扰视图投影矩阵,则3D坐标从左到右,从下到上依次为-1.0f到1.0f。因此,您可以使用上述相同的方法轻松计算出比例并适当放置对象

#3


Perhaps the simplest way (if you don't mind some linear algebra) is to use a 4x4 projection transformation matrix. In fact, just about any kind of 3D transformation can be performed using a 4x4 matrix.

也许最简单的方法(如果你不介意一些线性代数)是使用4x4投影变换矩阵。实际上,几乎可以使用4x4矩阵执行任何类型的3D变换。

Here is a Wikipedia article to get you started.

这是一篇*文章,可以帮助您入门。

#4


It sounds like you're willing to put up with a little unfaithfulness to a true projection to get simpler calculations. If so, follow along...

听起来你似乎愿意忍受一些不忠实的真实投影来获得更简单的计算。如果是这样,请跟随......

I will start by assuming you can shift, rotate and resize the sphere to match the coordinate system of the projected circle. Let's call r the radius for both of them, and assume the center is at (0,0,0) for the sphere and (0,0) for the circle. The X axis runs left-right for both, the Y axis runs bottom-top for both, and the Z axis runs back to front for the sphere.

我将首先假设您可以移动,旋转和调整球体的大小以匹配投影圆的坐标系。让我们将r调用为两者的半径,并假设球体的中心位于(0,0,0),圆圈的中心位于(0,0)。 X轴向左右两个运行,Y轴为两个运行的底部,Z轴向前运行为球体。

Here's the fun part: you're done. The X and Y coordinates are identical for both the sphere and the circle! If the Z coordinate is positive, the point is visible, if it's negative the point is hidden on the back side of the sphere.

这是有趣的部分:你已经完成了。球体和圆形的X和Y坐标是相同的!如果Z坐标为正,则该点是可见的,如果它是负的,则该点隐藏在球体的背面。

#5


cool, so assuming you just take the x,y out of the x,y,z of the sphere to form your circle. How do you go about shading the appropriate pixels on a pixel grid?. Basically, what's the algorithm for rasterizing a circle?

很酷,所以假设你只是将x,y从球体的x,y,z中取出来形成你的圆圈。你如何在像素网格上着色适当的像素?基本上,光栅化圆的算法是什么?

#6


The projection of a sphere onto a plane is an ellipse, but it can be approximated with a circle. This can be done almost the same as the perspective projection of a point.

球体在平面上的投影是椭圆形,但可以用圆形近似。这可以与点的透视投影几乎相同。

Assume the center of the screen is (X=0,Y=0), and the viewer is located at (X=0,Y=0,Z=0). If the sphere is at (sX,sY,sZ) with a radius of sR, and the screen is D units away from the viewer (focal distance), then the circle will be at (cX = sX * D / sZ, cY = sY * D / sZ) with a radius of cR = sR * D / sZ. Everything is simply scaled by D / sZ.

假设屏幕的中心是(X = 0,Y = 0),并且观察者位于(X = 0,Y = 0,Z = 0)。如果球体位于半径为sR的(sX,sY,sZ),并且屏幕距离观察者D个单位(焦距),那么圆圈将处于(cX = sX * D / sZ,cY = sY * D / sZ)半径为cR = sR * D / sZ。一切都只是由D / sZ缩放。

This circle is only a good approximation of the sphere projection if the focal distance (D) is large, or the sX and sY coordinates of the sphere are near to zero.

如果焦距(D)大,或者球的sX和sY坐标接近零,则该圆仅是球投影的良好近似。