查找哪一点是一条线/点左侧转动后 [英] Finder what point is to the left of a line/point after spinning it

查看:120
本文介绍了查找哪一点是一条线/点左侧转动后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写在统一着色器,吸引了各国的三角形图案风险风格的游戏,如果这两个国家不被同一玩家拥有的(视觉辅助,看看你的边界)。



现在,我在与制作着色器设置正确的国家的问题。



它总是将全国0〜左侧,国家1到右侧。 - 国0和1 programically设置



的线,边框可以是0和359度之间



如何找到国家0和1是我画3分向左侧和线的中点,一是.01f一.1F并从中点1 1F远的右在每个方向,然后旋转他们周围的中点到适当的位置。



之后,我做了一个奇偶校验,看是否点是内部或各外国家,比较重的结果(最接近的得3分,中得2,最远的得1,以防万一有人建立一个真正搞砸了国家侧翼其他国家)。



在我的测试图,以同样切片紧密八边形,边界出现了正确(后我逆转在事件国0和1的位置的角度为超过90和小于或等于180)。工作没有缺陷,但在其他地图它不工作得很好。



一切,但国家分配工作的很好,所以我很好奇,如果任何人的都知道。更好的方式来弄清楚这一点是向左还是纺线,或者处理这更好的方式概念





这上面基本上是当我在做,红色被左,右幸福蓝,那么我只检查3个不同的点,然后在偶数/ odding其放入相应的国家发现了左派和权利称重(一个在+/- .01,另一个在+/- .1和第三1,在与亲近奇/偶四舍五入问题)的情况下。



然后我翻转他们,如果我发现,A国是正确的,因为它是留给根据上角我有平局。 (我的着色渲染左第一右第二,因此为什么我这样做)。


解决方案

  1. 该方法是左/右一行?



    从去年的编辑难道这不是你的情况。为什么不使用点产品?





    所以,如果行云在 -x 方向的结果是<$ C负,如果$ C> + X 方向那么结果是积极的。如果结果是零,这意味着或者仅线上升,或者它是伸出一点。如果你需要特定的方向,而不是左/右,然后使用适当的 A 矢量,而不是 X 轴。




    • 点(A,b)= AX * b.x + AY *通过在2D

    • 点(A,b)= AX * b.x + AY * b.y + AZ * BZ 在3D



    图像是相关的情况下,其中 A 矢量是在单元尺寸在这种情况下,结果点的是的垂直投影b A 就像图片


  2. 哪一方是一些点?



    我觉得这是你所需要的。





    正如你可以看到,如果你处理行(P0,P1)键,点 P 要分类为三角那么它的多边形绕组也决定了线的一侧。所以对于隐含轴方向上:




    • CW (顺时针)多边形绕指该行的右侧

    • CCW


    侧STRONG>(逆时针)多边形卷绕装置

    如何获得缠绕? ......只是计算法向量并获取其以Z 坐标。它的极性(符号)确定绕组( CW / CCW 或周围的其他方法取决于坐标系)。




    • 法向量计算为三角形(P1-P0)×(P-P1)



    • 没有必要计算等轴系只是以Z 这样:




      • normal.z =((P1.x-P0.x)*(PY-P1.y)) - ((P1.y-P0.y)*( PX-P1.x))



      现在只是做如果(正常的。 z,其中,0)...其他... 这不应该是零,除非你调用它点上或线是一个点...看看这里类似的问题:的确定旋转方向/朝一个圆


$ b /可变点$ b

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.

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

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

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.

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).

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.

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).

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. which way is left/right on a line?

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

    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 in 2D
    • dot(a,b)=a.x*b.x+a.y*b.y+a.z*b.z in 3D

    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

  2. on which side is some point?

    I think this is what you need.

    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:

    • CW(clockwise) polygon winding means right side of the line
    • CCW(counter-clockwise) polygon winding means left side of the line

    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).

    • normal vector is computed as cross product of the two vertices of triangle (P1-P0)x(P-P1)

    No need to compute other axises just the z so:

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

    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

这篇关于查找哪一点是一条线/点左侧转动后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆