How to find a point lies inside circle
Hi,
How do I find a point (x,y) is lies inside a circle? I trying to do a small shooting game.
If the user clicks inside the circle they get a point. I am using the Pythagoras theorem to achieve this. But I can't.
Please advice me.
Here is my code
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Shoot extends JFrame implements MouseListener, MouseMotionListener
private int winWidth = 300;
private int winHeight = 300;
private MyCanvas canvas = null;
private int ballX = 50;
private int ballY = 50;
private int ballW = 50;
private int ballH = 50;
private int ballR = ballW / 2;
private int curX = 0;
private int curY = 0;
private int left = 0;
private int top = 0;
public Shoot()
Cursor c = new Cursor(Cursor.CROSSHAIR_CURSOR);
this.setCursor(c);
canvas = new MyCanvas();
packIt();
left = getInsets().left;
top = getInsets().top;
private void packIt()
setTitle("My first game!");
setPreferredSize(new Dimension(winWidth, winHeight));
setSize(new Dimension(winWidth, winHeight));
setContentPane(canvas);
addMouseListener(this);
addMouseMotionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//setUndecorated(true);
setLocation(300, 0);
setVisible(true);
public void mouseClicked(MouseEvent e)
int x = e.getX() - left - ballX;
int y = e.getY() - top - ballY;
int r = ballR;
System.out.println("x :" + x + "\ty :" + y);
//Trying to implememt Pythagoras theorem. But I am missing something.
System.out.println(((x * x) + (y * y)) + "\t=\t" + (r * r));
System.out.println();
public void mousePressed(MouseEvent e)
public void mouseReleased(MouseEvent e)
public void mouseEntered(MouseEvent e)
public void mouseExited(MouseEvent e)
public void mouseDragged(MouseEvent e)
public void mouseMoved(MouseEvent e)
curX = e.getX() - left;
curY = e.getY() - top;
canvas.repaint();
private class MyCanvas extends JPanel
public MyCanvas()
setBackground(Color.BLACK);
setBorder(BorderFactory.createLineBorder(Color.yellow));
public void paintComponent(Graphics g)
super.paintComponent(g);
g.setColor(Color.WHITE);
g.drawString("x :" + curX, 10, 20);
g.drawString("y :" + curY, 10, 30);
g.setColor(Color.RED);
g.fillOval(ballX, ballY, ballW, ballH);
public static void main(String[] asd)
new Shoot();
}
public boolean isPointInCircle(){
double x= circle.getWidth/2.0+circle.getX();
double y= circle.getHeight/2.0+circle.getY();
double distance=getDistance(x,y,pointX,PointY);
return (distance<= circle.getWidth/2.0); //if the distance from the point to the center of the circle is less than the radius of the circle return true
double getDistance(double x1, double y1, double x2, double y2){
return math.sqrt((x1-x2)(x1-x2) + (y1-y2)(y1-y2));
}Edited by: ghostbust555 on Jan 23, 2011 3:20 PM
Similar Messages
-
How to find CR Request Number inside a package
Hi Folks,
how to find the CR Request Number list present inside one package.
Reg,
HariharanHi ,
i had gone through the Transaction se03 Search for Object in Request/Task, in the selection screen no option for Package can you just breaf about the Selection Screen Step.
Reg,
Hari. -
Check if a point lies inside a rectangle
Hi im making an application that displays a shape on the screen at different locations. The shape is a combination of an ellipse and a line. My problem is when i want to draw the shapes i created a method to check if the point given is contained by any other shape and if it is it should create a new point. However when the .contains(Point) method is run it doesnt reply true or false so my code just goes into an infinite loop and crashes.
Here is the checkpoint method that loops infintly
private void setPoint(Point pow) {
boolean anythingthere = false;
while (anythingthere==!true) {
Rectangle test = list.getBounds();
if (test.contains(pow)) {
int f = pow.x;
f = f+200;
int g = pow.y;
pow.setLocation(f, g);
System.out.println(pow);
f = 0;
else {
if (pow.x+150 > getWidth()) {
pow.setLocation(50, pow.y+180);
anythingthere = true;
i++;
}And because my shape is a combination of graphics2D shapes i created this method in its class to return the rectangle that bounds the shapepublic Rectangle getBounds() {
bound = new Rectangle(location.x,location.y,size,size);
return bound;
}Thanks for any help you can give im really stumped!!Hi thanks for your reply's. Thanks for tips on making my code nicer and efficient ive tried to do it throughout my project so hopefully its more readable now. The problem was to do with scope like one of you said so i moved a few things round and got it working. The problem was when i called the bounds of the rectangle it was returning the bounds using the last changed point which meant that every time i tested the loop the point was inside that bound so it basically looped infinitely. One line moved and it worked perfectly.
Thanks everyone -
How to find particular date lies in between two given dates
hi,
i have a problem. i have to find if particular day lies in between two given dates.
example two dates are joindate and expirydate.
1.joindate is 1/03/2007
expdate is 1/03/2008
now i have to find if 29 feb is in between this joindate and expirydate.
if any1 has ny idea please reply asap.
thanks.The Date class has a before() and after() method you can use to compare Date objects.
-
How to find inflection point in graph when dx is very small
Hello,
I'm trying to sort through position data from a feedback pot to calculate linearity of movement as part of a testing procedure. An image of the data is attached. I want to delete all data in the 'flat' part, in order to do a linear fit and R^2 of the sloped line.
This is made trickier by the fact that the number of samples, the start and end points, and slope of the line can all vary considerably. Therefore I need some way to find the 'knee' in the graph and remove all subsequent samples from the data.
The most obvious method I tried was to use a derivative to find the inflection point, but since I have so many data points, the dx is very small
(~0.05) when using the built-in labview derivatives. This means that I can't distinguish the inflection point from any other change in the values due to noise or change in velocity. I made my own derivative function, which was a newton quotient that looked at (xi+N)-(xi-N) instead of (xi+1) - (xi-1), but this still did not give good results. My next idea is to just look at the difference of every N points, and arbitrarily decide a threshold to indicate when it has levelled off. Any other ideas would be really helpful though.
Thanks,
-SK-
Attachments:
position.PNG 17 KBLets see if I can answer without having to write a book.
Fisrt I'd run the data through a zero-phase shift low pass filter. Then look at the 2nd derivative to find the knee. Using a zero-pahse shift fileter I was able to detect when a value was jumping up when it started to jump rather than after. THis thread may be interesting.
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction -
How to find nearest point on polyline
Hi,
I have to find the nearest point to my standing point on a polyline. I have Oracle Locator installed, but my data is not in a locator format. Is it possible to do this by using Locator's functionality by for example puting the polyline and standing point coordinate values into a spatial type variable and calling some locator functionality?
Or I have to coordinate data into a "spatial enabled" table, create spatial index etc and then call some Locator procedure.
TamasLuc,
Thanks for the reference.
When the data is converted, finding the nearest vertex in an sdo_geometry object could be done this way (of, of course, many):
select f.vertex_id,f.dist,f.min_dist,f.a_vertex
from (select p.vertex_id,
sdo_geom.sdo_distance(p.the_point,p.a_vertex,0.005) as dist,
min(sdo_geom.sdo_distance(p.the_point,p.a_vertex,0.005)) over (order by sdo_geom.sdo_distance(p.the_point,p.a_vertex,0.005) asc) as min_dist,
p.the_point,
p.a_vertex
from (select t.id as vertex_id,
mdsys.sdo_geometry(2001,NULL,mdsys.sdo_point_type(358615,5407047,null),null,null) as the_point,
mdsys.sdo_geometry(2001,NULL,mdsys.sdo_point_type(t.x,t.y,t.z),null,null) as a_vertex
from table(sdo_util.getVertices(
MDSYS.SDO_GEOMETRY(2002,null,null,MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),MDSYS.SDO_ORDINATE_ARRAY(362253.9,5409676.63,355608.12,5407615.16,358063.37,5407673.48,355276.53,5407361.08,360471.08,5408880.79,362483.4,5406024.69,362359.16,5408840.11,354570.21,5406219.18,360204.62,5405849.14,359214.51,5408283.5,358761.06,5406683.88,356739.05,5405590.46,358615.79,5407047.29,355978.02,5407326.33,356240.87,5409898.7,363159.35,5405510.46,358588.81,5406536.54,354822.42,5408643.75,357690.2,5408872.57,359839.29,5407253.86,355236.29,5409711.53,355342.54,5407448.87,360290.53,5405111.51,354677.02,5407916.83,361651.27,5409178.26,361730.18,5407553.5,357402.33,5409065.5,361546.51,5407278.41,361915.65,5408942.57,361974.74,5405464.91,357794.3,5406979.33,356106.58,5405481.32,357604.96,5407407.72,360718.31,5406765.8,359745.49,5406568.16,363005.29,5407557.46,355844.01,5407095.47,362749.66,5405041.82,359714.13,5408898.69,354509.69,5406113.6,360041.59,5406204.24,360380.17,5408751.21,356621.4,5409603.06,355156.27,5405401.98,354441.35,5409090.68,356376.45,5407472.81,363877.1,5405582.72,361883.83,5409696.17,356363.41,5406434.53,362078.96,5406617.37,362714.59,5409800.2,362703.49,5408513.33,358317.64,5408170.64,359294.27,5409197.53,360240.93,5406333.84))
)) t
) p
) f
where f.dist = f.min_dist;Hope this helps.
Simon -
How to find all query elements inside a Query
Hi,
I would like to find out all query elements inside my query.
Is there any table which stores all query elements inside my query ?
Thanks
PratyushHi,
Query elements are stored in this follwing table:
SE11
Table name : RSZELTXREF [Directory of query element references]
other query related tables :
Tables used in Queries
RSZELTDIR Directory of the reporting component elements
RSZELTTXT Texts of reporting component elements
RSZELTXREF Directory of query element references
RSRREPDIR Directory of all reports (Query GENUNIID)
RSZCOMPDIR Directory of reporting components
RSZRANGE Selection specification for an element
RSZSELECT Selection properties of an element
RSZELTDIR Directory of the reporting component elements
RSZCOMPIC Assignment reuseable component <-> InfoCube
RSZELTPRIO Priorities with element collisions
RSZELTPROP Element properties (settings)
RSZELTATTR Attribute selection per dimension element
RSZCALC Definition of a formula element
RSZCEL Query Designer: Directory of Cells
RSZGLOBV Global Variables in Reporting
RSZCHANGES Change history of reporting components
Hope it will helps you.
Thanks
Hemav -
How to find intersection point between a lineseries and a vertical line.
I have a lineseries chart (refer the screenshot). As I move the spend slider shown in the attachment, a vertical line is drawn in the chart. (I did this using the cartesian canvas as annotation element - using canvas.moveTo(), canvas.lineTo() functions)
I want to find out the intersection point(y value) where the vertical line meets the lineseries. Can someone help me on this. It will be really helpful.
Thanks,
JayakrishnanHere are a few functions I wrote years ago for common chart transformations... the function you're going to focus on for your solution is chartToScreen...
* Converts the screen position to chart value position
* @param thePos - Number - The position you want to convert
* @private
private function getChartCoordinates(thePos:Point):Object
var tmpArray:Array = dataTransform.invertTransform(thePos.x, thePos.y);
return {x:tmpArray[0], y:tmpArray[1]};
* Takes a non-numeric chart value and returns a proper numeric value
* @param inValue - String - The display name of the instance showing on the axis (eg. if we're showing months, it might be 'Sep - 06'
* @param theAxis - IAxis - The axis on which we're looking
public function getNumericChartValue(inValue:String, theAxis:IAxis):Object
var axisCache:Array = new Array({inValue: inValue})
if(!(theAxis is LinearAxis))
theAxis.mapCache(axisCache, "inValue", "outValue", true);
return {numericValue: axisCache[0].outValue}
else
return {numericValue: Number(inValue)};
* Converts the chart values into screen coordinate values
* @param chartX - Number - The display name of the instance showing on the axis (eg. if we're showing months, it might be 'Sep - 06'
* @param chartY - Number - The axis on which we're looking
public function chartToScreen(chartX:Number, chartY:Number, theSeries:Series):Point
var tmpCache:Array = new Array({chartX:chartX, chartY:chartY});
if(theSeries)
theSeries.dataTransform.transformCache(tmpCache, "chartX", "screenX", "chartY", "screenY");
else
dataTransform.transformCache(tmpCache, "chartX", "screenX", "chartY", "screenY");
return new Point(Math.round(tmpCache[0].screenX), Math.round(tmpCache[0].screenY));
* takes a point in mouse position, and runs it through converting to chart coordinates, converts chart coordinate to numeric value if needed
* and then back into mouse position to get the nearest axis snap point
* @param thePoint - Point - The position we're converting
* @private
private function getSnapPosition(thePoint:Point):Point
var chartPoint:Object = getChartCoordinates(new Point(thePoint.x, thePoint.y));
//if either of the axis chart results is not in numeric format, we get the numeric equivalent of it
var chartX:* = chartPoint.x;
var chartY:* = chartPoint.y;
chartX = getNumericChartValue(chartPoint.x, CartesianChart(this.chart).horizontalAxis).numericValue;
chartY = getNumericChartValue(chartPoint.y, CartesianChart(this.chart).verticalAxis).numericValue;
return chartToScreen(chartX, chartY, null); -
How to find, which file present inside .ZIP?
Hi Experts,
I have test_20130303010203.dat file after ziping it the file name is test_20130305010203.dat.zip.
My question is how can i find which file got ziped?(in code).
Lets say i have 10 .dat file already in the same path where i am unziping my file....how can i find my unziped file?
Please help meHi Asma,
How is your question related to SSIS?
To find out you need to see what and how zips/unzips the file up.
I assume you are free to choose how you proceed, so then why not using a utility at your disposal set to unzip the files to the needed directory?
Arthur My Blog -
How to find the points that define an edge?
I'm looking at a very large geometry that's generating an error from VALIDATE_GEOMETRY_WITH_CONTEXT:
ORA-13349: polygon boundary crosses itself 13349 [Element <5>] [Ring <1>][Edge <7566>][Edge <7591>]
How can I find the X & Y coordinates of those two edges?
It's a two-dimensional polygon, with thirty two inner rings, and extracting ring 5 doesn't show any obvious errors: It doesn't have seven thousand edges to it either though - is that supposed to be the edge number counting from the start of the outer ring, or just the start of that element?
Cheers
Simon Anderson
ScisysHi,
What I'm looking for is a way to report the error back to the end-user. The information is there in the form of:
[Element <5>] [Ring <1>][Edge <7566>][Edge <7591>]
But the exact position of the error is often hard to find in a CAD system.
I want to return edge 7566 and edge 7591 as geometry objects.
So the question is:
Given a geometry object and a list of element,ring,edge elements. How to create geometry objects for these edges?
Rene -
How to find enhancement point or enhancement section
Hi,
If anybody is trying to make changes to the approved sale order it shows a message
"SALE ORDER APPROVED BY xx CHANGES NOT POSSIBLE".
i want to know where excatly the enhacement code is written.
Thanks & Regards,
vijay karri.
Edited by: vijaykarri on Jul 8, 2010 11:39 AMHi ,
Please find in the Source code using Search Option with the Message String Or Using the Message No and Whereused List .
Regards,
Kishore.S -
How to find the T-codes that's in a Single Role & Composite Role??
Hi all,
Some of the user have authorization to particular t-codes. However single roles are not created for them.
Now I need to assign authorization to that particular t-code to a new employee.
Since the single role is not there, I do not know how to find if it is inside a composite role.
Which table should I find all the t-codes that are assigned to a single role / composite role?
pls help.
Regards,
PriRakesh Kulkarni wrote:>
> Table AGRS_TCODES give the roles with their tcode assignment.
Beware of AGR_TCODES, it only reports transactions entered into the role menu. If you query table AGR_1251 filtered on object S_TCODE you get the actual transaction authorizations.
Besides that, authorizations are always in single roles, so if you cannot find them there there's no point in searching through the composites. -
How to find Correct IDoc Status in SAP
Hi All,
I need some help on IDoc scenario, I have custom program to create Idoc and as well it will send IDoc to XI. I want to know idoc staus in the program to update custom table whether idoc sent successfully or not but idoc giving status as 03 (Data passed to port OK) irrespective of idoc send or not, actually idoc not sent to xi when I check SM58 showing error.
Please advice me how to find correct idoc status inside program itself.
**-----Create IDoc
CALL FUNCTION 'IDOC_OUTBOUND_WRITE_TO_DB'
TABLES
int_edidd = i_edidd
CHANGING
int_edidc = wa_int_edidc
EXCEPTIONS
idoc_not_saved = 1
OTHERS = 2.
COMMIT WORK.
i_edidc = wa_int_edidc.
APPEND i_edidc.
REFRESH i_edidd.
**-----Send Idoc
CLEAR i_edidd.
**-------Send Idoc to XI
CALL FUNCTION 'EDI_OUTPUT_NEW'
EXPORTING
onl_option = 'B'
error_flag = ' '
TABLES
i_edidc = i_edidc
i_edidd = i_edidd.
COMMIT WORK.
READ TABLE i_edidc INDEX 1.
**-----Update Dispatch order status based on Idoc status.
IF sy-subrc = 0 AND i_edidc-status ='03'.
znxi01_update c_03 i_edidc-docnum.
gw_success_record = gw_success_record + 1.
ELSE. " Error in Data Transfer
znxi01_update c_02 i_edidc-docnum.
gw_fail_record = gw_fail_record + 1.
ENDIF.Hi Anil,
for setting IDOC Status you can send back a IDOC of type <i>ALEAUD01</i>.
The function IDOC_INPUT_ALEAUD takes automatically this IDOC and writes the status to the origin IDOC.
Regards Mario -
"if for some reason u have the icon in your task bar (the one with 2 arrows pointing in a circle) just go into mobile me pref...click sync...and uncheck box show status in menu bar."
I do not have the option box to "show status in menu bar"
I tried the free for a little while Mobile me, and didn't use it, so cancled. I cannot get the sync status roundabout arrows out of my status bar. AND, they keep trying to sync.
Another issue related with this is that during the time that I tried out Mobile me, I had my ical alarm set to go off every 2 hours. NOW my computer has an ical pop-up every 2 hours. I cannot find how to stop it.
Another issue, Yahoo is trying to sync with my computer and I have no idea why or where that one came from.
Can anyone out there help me please."if for some reason u have the icon in your task bar (the one with 2 arrows pointing in a circle) just go into mobile me pref...click sync...and uncheck box show status in menu bar."
I do not have the option box to "show status in menu bar"
I tried the free for a little while Mobile me, and didn't use it, so cancled. I cannot get the sync status roundabout arrows out of my status bar. AND, they keep trying to sync.
Another issue related with this is that during the time that I tried out Mobile me, I had my ical alarm set to go off every 2 hours. NOW my computer has an ical pop-up every 2 hours. I cannot find how to stop it.
Another issue, Yahoo is trying to sync with my computer and I have no idea why or where that one came from.
Can anyone out there help me please. -
How to remove arrow pointer in painting tool circle?
I'm running Adobe Photoshop 7.0 in Windows 7 Virtual XP mode, since the program won't run in Win7 64-bit mode. It used to run fine in 32-bit mode. It runs OK in the virtual XP mode, but I find that the circle tool in the painting or clone stamp functions always has an arrowhead in the center of the circle. It never used to, just the circle for painting or cloning. How do I get rid of it? Changing the settings in the Preferences menu does not help.
Also, the virtual mode doesn't seem to allow updating program files, although it updates XP files. Maybe there is a firewall issue? I tried to download a Photoshop update file. There was a prompt asking where it should go. But when I selected a place, and clicked OK, the Next button did not come on.
Thanks in advance for any suggestions.
BKNoel,
Thanks for your response. I was only joking.
As far as the virtual XP mode goes: I wasted a lot of time with Adobe techies – in India and elsewhere – first, trying to get an unlock code to install the Photoshop 7 on my new hard disk, then when it booted up, the program would not initialize. I just get an error message, saying “Photoshop 7.9 could not initialize because your scratch disks are full.” Then it shuts down. This, after I have a 1.5 TB size new main drive.
Unless you have any ideas on how to get around this bad penny initialization error message, I am stuck. It does work in XPM mode, though. Although I was able to change the screen resolution to remove the mouse pointer in the circle tool, now the tool is the cursor that looks like a small oval over which crosshairs are placed. I can’t seem to get a normal, single circle. Is there a switch that restores cursors to a default?
Barrett Kalellis
Maybe you are looking for
-
What could cause the lock in my preferences to seemingly to click open on there own,I use my home wifi network which is private and have never given out that password either for my network or preferences password.....help,Thank you
-
Hi, I have the following problem. What do you suggest? I have an interface A, abstract class B, B's subclasses C and D, and mainClass interface A abstract class B implements A { B b; public B(String desc) if (desc.equals("C")) b=new C();
-
Why does my 16gb mini only have12 GB of available storage?
-
I have a very simple graphical application. The first two constructions are responsive and variations on the third not. The responsive code is very simple: frame = new JFrame("Frame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(
-
Some podcast episodes I can drag & drop, not others
New current gen iPod Touch, 16gb. Just downloaded iTunes 8.2 (which may have been my first mistake, in hindsight...always wait for that .1) on an HP Vista laptop (which I know is my second problem...can't be helped). When I started using it (just got