<bdo id='vQMg1'></bdo><ul id='vQMg1'></ul>
    1. <i id='vQMg1'><tr id='vQMg1'><dt id='vQMg1'><q id='vQMg1'><span id='vQMg1'><b id='vQMg1'><form id='vQMg1'><ins id='vQMg1'></ins><ul id='vQMg1'></ul><sub id='vQMg1'></sub></form><legend id='vQMg1'></legend><bdo id='vQMg1'><pre id='vQMg1'><center id='vQMg1'></center></pre></bdo></b><th id='vQMg1'></th></span></q></dt></tr></i><div id='vQMg1'><tfoot id='vQMg1'></tfoot><dl id='vQMg1'><fieldset id='vQMg1'></fieldset></dl></div>

    2. <small id='vQMg1'></small><noframes id='vQMg1'>

      1. <legend id='vQMg1'><style id='vQMg1'><dir id='vQMg1'><q id='vQMg1'></q></dir></style></legend>
        <tfoot id='vQMg1'></tfoot>

        旋转后查找线/点左侧的点

        时间:2023-07-25

            <bdo id='1lNFe'></bdo><ul id='1lNFe'></ul>
            1. <i id='1lNFe'><tr id='1lNFe'><dt id='1lNFe'><q id='1lNFe'><span id='1lNFe'><b id='1lNFe'><form id='1lNFe'><ins id='1lNFe'></ins><ul id='1lNFe'></ul><sub id='1lNFe'></sub></form><legend id='1lNFe'></legend><bdo id='1lNFe'><pre id='1lNFe'><center id='1lNFe'></center></pre></bdo></b><th id='1lNFe'></th></span></q></dt></tr></i><div id='1lNFe'><tfoot id='1lNFe'></tfoot><dl id='1lNFe'><fieldset id='1lNFe'></fieldset></dl></div>
              <legend id='1lNFe'><style id='1lNFe'><dir id='1lNFe'><q id='1lNFe'></q></dir></style></legend>
                  <tbody id='1lNFe'></tbody>

              • <small id='1lNFe'></small><noframes id='1lNFe'>

                  <tfoot id='1lNFe'></tfoot>
                1. 本文介绍了旋转后查找线/点左侧的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在尝试统一编写一个着色器,如果两个国家不属于同一个玩家,则该着色器会在风险风格的游戏中围绕国家绘制三角形图案(视觉辅助来查看您的边界).

                  I am currently trying to write a shader in unity that draws a triangular pattern around countries in a risk-styled game if both countries are not owned by the same player (visual aid to see your borders).

                  现在,我在让着色器正确设置国家/地区时遇到问题.

                  Right now, I'm having an issue with making the shader set the countries properly.

                  它总是将国家 0 设置在左侧,国家 1 设置在右侧 - 国家 0 和 1 是通过程序设置的.

                  It always sets country 0 to the left, and country 1 to the right - country 0 and 1 are set programically.

                  线,一个边界,可以在 0 到 359 度之间.

                  The line, a border, can be between 0 and 359 degrees.

                  我如何找到国家 0 和 1 是我在线中点的左侧和右侧画了 3 个点,一个 .01f、一个 .1f 和一个 1f 远离每个方向的中点,然后旋转它们到适当位置的中点.

                  How I find the countries 0 and 1 is I draw 3 points to the left and right of the midpoint of the line, one .01f, one .1f and one 1f away from the midpoints in each direction, then spin them around the midpoint to the appropriate location.

                  之后,我会进行奇偶校验,看看这些点是在每个国家的内部还是外部,并比较权重结果(最近的得 3 分,中的得 2 分,最远的得 1,以防万一有人建造了一个真正搞砸了与另一个国家相邻的国家).

                  After that I do an even-odd check to see if the points are inside or outside of each country, and compare the weight results (closest gets 3 points, mid gets 2, furthest gets 1, just in case someone builds a really screwed up country that flanks the other country).

                  在我的测试地图中,一个接近等切的八边形,边界显示正确(在我颠倒国家 0 和 1 的位置后,如果角度超过 90 且小于或等于 180).可以正常工作,但在其他地图中效果不佳.

                  In my test map, a close to equally sliced octagon, the borders showed up correctly (after I reversed the positions of country 0 and 1 in the event the angle was over 90 and less then or equal 180). Worked without a flaw, but in other maps it doesn't work very well.

                  除了国家/地区分配外,其他一切都很好,所以我很好奇是否有人知道更好的方法来确定哪个点在左侧或旋转线上,或者更好的概念性方法来处理这个问题.

                  Everything but the country allocation works well, so I'm curious if anyone knows of a better way to figure out which point is to the left or a spun line, or a better conceptual way to handle this.

                  上面基本上是当我在做的时候,红色是左,右是蓝色,然后我只是检查 3 个不同的点,然后权衡找到的左右两边,并把它偶/奇到适当的国家(一个在 +/- .01,另一个在 +/- .1 和第三个 1,以防出现偶数/奇数舍入问题.

                  That above is basically when I'm doing, red being left right being blue, then I'm just checking 3 different spots then weighing in the lefts and rights found with even/odding it into the appropriate countries (one at +/- .01, the other at +/- .1 and the third 1, in case of even/odd rounding issues with closeness).

                  如果我发现 A 国在右侧,我会翻转它们,因为根据我绘制的角度它在左侧.(我的着色器先渲染左,后渲染右,这就是我这样做的原因).

                  I then flip them if I find that country A is to the right, as it is on the left according to the angles I had draw. (my shader renders left first and right second, hence why I do this).

                  推荐答案

                  1. 一条线上的左/右方向是什么?

                  从上次编辑开始,这不是您的情况.为什么不使用点积?

                  From last edit is this not your case. Why not use dot product?

                  因此,如果行在 -x 方向上,则结果为负,如果在 +x 方向上,则结果为正.如果结果为零,则表示该线仅上升或下降,或者它只是一个点.如果您需要特定方向而不是左/右,则使用适当的 a 向量而不是 x 轴.

                  So if the line goes in -x direction the result is negative and if in the +x direction then the result is positive. if the result is zero that means the line goes up or down only or it is juts a point. If you need specific direction instead of left/right then use appropriate a vector instead of x axis.

                  • dot(a,b)=a.x*b.x+a.y*b.y 二维
                  • dot(a,b)=a.x*b.x+a.y*b.y+a.z*b.z 3D
                  • dot(a,b)=a.x*b.x+a.y*b.y in 2D
                  • dot(a,b)=a.x*b.x+a.y*b.y+a.z*b.z in 3D

                  图像与 a 向量为单位大小的情况相关,在这种情况下,点的结果是 ba 的垂直投影就像图片上的一样

                  Image is relevant for cases where a vector is in unit size in that case the result of dot is perpendicular projection of b into a just like on image

                  某个点在哪一边?

                  我想这就是你需要的.

                  如您所见,如果您处理线 (P0,P1) 和点 P 您想要分类为三角形,那么它的 多边形缠绕也决定了线的一侧.所以对于隐式轴方向:

                  As you can see if you handle line (P0,P1) and point P you want to classify as triangle then its polygon winding determines also the side of the line. So for implicit axis directions:

                  • 顺时针(顺时针)多边形缠绕表示线的右侧
                  • CCW(逆时针)多边形缠绕表示线的左侧
                  • CW(clockwise) polygon winding means right side of the line
                  • CCW(counter-clockwise) polygon winding means left side of the line

                  如何上链?...只需计算法线向量并获取其 Z 坐标.它的极性(符号)决定了绕组(CW/CCW 或相反的方式取决于坐标系).

                  How to get winding? ... simply compute normal vector and get its Z coordinate. Its polarity (sign) determines winding (CW/CCW or the other way around depends on the coordinate system).

                  • 法向量计算为三角形的两个顶点的叉积(P1-P0)x(P-P1)

                  不需要计算其他轴只需 z 所以:

                  No need to compute other axises just the z so:

                  • normal.z = ((P1.x-P0.x)*(Py-P1.y)) - ((P1.y-P0.y)*(Px-P1.x))

                  现在只需执行 if (normal.z<0) ... else ... 它永远不应该为零,除非您将其称为线上的点或线是点... 看这里类似的问题:Determine rotation direction/toward/variable point on a circle

                  Now just do if (normal.z<0) ... else ... it should never be zero unless you call it for point on the line or the line is a point ... look here at similar question: Determine rotation direction /toward/ variable point on a circle

                  这篇关于旋转后查找线/点左侧的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    <bdo id='Qohaw'></bdo><ul id='Qohaw'></ul>
                    <tfoot id='Qohaw'></tfoot>

                  • <legend id='Qohaw'><style id='Qohaw'><dir id='Qohaw'><q id='Qohaw'></q></dir></style></legend>

                      1. <small id='Qohaw'></small><noframes id='Qohaw'>

                            <tbody id='Qohaw'></tbody>
                          <i id='Qohaw'><tr id='Qohaw'><dt id='Qohaw'><q id='Qohaw'><span id='Qohaw'><b id='Qohaw'><form id='Qohaw'><ins id='Qohaw'></ins><ul id='Qohaw'></ul><sub id='Qohaw'></sub></form><legend id='Qohaw'></legend><bdo id='Qohaw'><pre id='Qohaw'><center id='Qohaw'></center></pre></bdo></b><th id='Qohaw'></th></span></q></dt></tr></i><div id='Qohaw'><tfoot id='Qohaw'></tfoot><dl id='Qohaw'><fieldset id='Qohaw'></fieldset></dl></div>