简体   繁体   English

在椭圆上存储点:Java

[英]Storing Points On an Ellipse: Java

Right now I have a basketball court drawn using Graphics (drawLine, drawArc, etc) and have a mouseClicked event that will draw an 'X' or an 'O' on the court based on whether the boolean shotMade is true (set using "Make" and "Miss" buttons at bottom frame). 现在,我有一个使用Graphics(drawLine,drawArc等)绘制的篮球场,并具有mouseClicked事件,该事件将根据布尔ShotMade是否为真(在场上使用“ Make设置”,在场上绘制“ X”或“ O” ”和“ Miss”按钮)。 Right now, I actually will produce the 'X' or 'O' at getX()-6, and getY()+6 so that the center of the 'X' or 'O' will be drawn at the point where the mouse was clicked (using g.drawString() will draw the 'X' or 'O' starting with the bottom left corner so it is not directly centered). 现在,我实际上将在getX()-6和getY()+ 6处生成“ X”或“ O”,以便在鼠标的位置绘制“ X”或“ O”的中心被单击(使用g.drawString()将从左下角开始绘制“ X”或“ O”,以使其不直接居中)。

My question comes in my differentiation between a two-pointer and a three-pointer. 我的问题来自我在两分和三分之间的区别。 Right now, there are straight vertical lines in the corners of the court on the three point line at the x value 52 and 448, so I know any clicked point with an x less than 52 or more than 448 will be a three, as well as any point with ay value more than 250, indicating the top of the key, or the highest y-value at any point along the arc. 现在,在球场角上的x值为52和448的三点线上有垂直的直线,所以我知道x小于52或大于448的任何单击点也将是3。如ay值大于250的任何点,表示键的顶部,或沿弧线任意点的y值最高。 In order to determine a three or two anywhere along the arc, I had an idea to store every single x and y pixel that is used to draw the arc into two ArrayLists (one for x, one for y), and when the mouse is clicked at a point, it would search for the x value in its list, and check to see if the y point is more than that at the corresponding point in its list. 为了确定沿弧线的任何地方三个或两个,我有一个想法是将每个用于绘制弧线的x和y像素存储到两个ArrayLists中(一个用于x,一个用于y),以及当鼠标处于单击某个点,它将在列表中搜索x值,并检查y点是否大于列表中相应点的y点。 I drew the arc with g.drawArc(52,-110,396,360,0,-180), putting its center at the point (250, 70). 我用g.drawArc(52,-110,396,360,0,-180)绘制了圆弧,将圆心置于点(250,70)。

So using all this information, I am first wondering how I might go about storing each pixel value into an ArrayList using some formula to calculate each of the points around the ellipse, and then how I might check to see if the clicked point is indeed a three or two. 因此,使用所有这些信息,我首先想知道如何使用一些公式将每个像素值存储到ArrayList中,以计算椭圆周围的每个点,然后如何检查点击的点是否确实是三个或两个。

Any help is appreciated, including any more efficient ideas or other thoughts. 感谢您提供任何帮助,包括任何更有效的想法或其他想法。 Thanks! 谢谢!

Have a look at java.awt.geom.Area 看看java.awt.geom.Area

notice that in class "Area"... http://docs.oracle.com/javase/7/docs/api/java/awt/geom/Area.html 请注意,在“区域”类中... http://docs.oracle.com/javase/7/docs/api/java/awt/geom/Area.html

.... there is a method contains(double x, double y), which returns boolean. ....有一个方法contains(double x,double y),它返回布尔值。 The method "Tests if the specified coordinates are inside the boundary of the Shape..." 方法“测试指定的坐标是否在Shape的边界内...”

Perhaps you could use this to find whether or not the user clicked within the ellipse shape that defines the 2 point zone. 也许您可以使用它来查找用户是否在定义2点区域的椭圆形内单击。

Also note that the Area class can take in a Shape to define it. 另请注意,Area类可以采用Shape进行定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM