Search Results

Search found 902 results on 37 pages for 'circle'.

Page 1/37 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Circle to Circle collision, checking each circle against all others

    - by user14861
    I'm currently coding a little circle to circle collision demo but I've got a little stuck. I think I currently have the code to detect collision but I'm not sure how to loop through my list of circles and check them off against one another. Collision check code: public static Vector2 GetIntersectionDepth(Circle a, Circle b) { float xValue = a.Center.X - b.Center.X; float yValue = a.Center.Y - b.Center.Y; Vector2 depth = Vector2.Zero; float distance = Vector2.Distance(a.Center, b.Center); if (a.Radius + b.Radius > distance) { float result = (a.Radius + b.Radius) - distance; depth.X = (float)Math.Cos(result); depth.Y = (float)Math.Sin(result); } return depth; } Loop through code: Vector2 depth = Vector2.Zero; for (int i = 0; i < bounds.Count; i++) for (int j = i+1; j < bounds.Count; j++) { depth = CircleToCircleIntersection.GetIntersectionDepth(bounds[i], bounds[j]); } Clearly I'm a complete newbie, wondering if anyone can give any suggestions or point out my errors, thanks in advance. :)

    Read the article

  • How to handle circle penetration

    - by Kaertserif
    I've been working on cirlce to circle collision and have gotten the intersection method working correctly, but I'm having problems using the returned values to actually seperate the circles from one another. This is the method which calculates the depth of the circle collision public static Vector2 GetIntersectionDepth(Circle a, Circle b) { float xValue = a.Center.X - b.Center.X; float yValue = a.Center.Y - b.Center.Y; Vector2 depth = Vector2.Zero; float distance = Vector2.Distance(a.Center, b.Center); if (a.Radius + b.Radius > distance) { float result = (a.Radius + b.Radius) - distance; depth.X = (float)Math.Cos(result); depth.Y = (float)Math.Sin(result); } return depth; } This is where I'm trying to apply the values to actually seperate the circles. Vector2 depth = Vector2.Zero; for (int i = 0; i < circlePositions.Count; i++) { for (int j = 0; j < circlePositions.Count; j++) { Circle bounds1 = new Circle(circlePositions[i], circle.Width / 2); Circle bounds2 = new Circle(circlePositions[j], circle.Width / 2); if(i != j) depth = CircleToCircleIntersection.GetIntersectionDepth(bounds1, bounds2); if (depth != Vector2.Zero) { circlePositions[i] = new Vector2(circlePositions[i].X + depth.X, circlePositions[i].Y + depth.Y); } } } If you can offer any help in this I would really appreciate it.

    Read the article

  • Box2d too much for Circle/Circle collision detection?

    - by Joey Green
    I'm using cocos2d to program a game and am using box2d for collision detection. Everything in my game is a circle and for some reason I'm having a problem with some times things are not being detected as a collision when they should be. I'm thinking of rolling up my own collision detection since I don't think it would be too hard. Questions are: Would this approach work for collision detection between circles? a. get radius of circle A and circle B. b. get distance of the center of circle A and circle B c. if the distance is greater than or equal to the sum of circle A radius and circle B radius then we have a hit Should box2d be used for such simple collision detection? There are no physics in this game.

    Read the article

  • Render only the segment/area of a circle that intersects the main circle

    - by Greenhouse Gases
    I absolutely love maths (or 'math' as most of you would say!) but I haven't done it to a level where I know the answer to this problem. I have a main circle which could have a centre point at any x and y on a display. Other circles will move around the display at will but at any given call to a render method I want to render not only those circles that intersect the main circle, but also only render the segment of that circle that is visible inside the main circle. An analogy would be a shadow cast on a real life object, and I only want to draw the part of that object that is 'illuminated'. I want to do this preferably in Java, but if you have a raw formula that would be appreciated. I wonder how one might draw the shape and fill it in Java, I'm sure there must be some variation on a polyline with arcs or something? Many thanks

    Read the article

  • Drawing a circle in opengl es android, squiggly boundaries

    - by ladiesMan217
    I am new to OpenGL ES and facing a hard time drawing a circle on my GLSurfaceView. Here's what I have so far. the Circle Class public class MyGLBall { private int points=40; private float vertices[]={0.0f,0.0f,0.0f}; private FloatBuffer vertBuff; //centre of circle public MyGLBall(){ vertices=new float[(points+1)*3]; for(int i=3;i<(points+1)*3;i+=3){ double rad=(i*360/points*3)*(3.14/180); vertices[i]=(float)Math.cos(rad); vertices[i+1]=(float) Math.sin(rad); vertices[i+2]=0; } ByteBuffer bBuff=ByteBuffer.allocateDirect(vertices.length*4); bBuff.order(ByteOrder.nativeOrder()); vertBuff=bBuff.asFloatBuffer(); vertBuff.put(vertices); vertBuff.position(0); } public void draw(GL10 gl){ gl.glPushMatrix(); gl.glTranslatef(0, 0, 0); // gl.glScalef(size, size, 1.0f); gl.glColor4f(1.0f,1.0f,1.0f, 1.0f); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertBuff); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, points/2); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glPopMatrix(); } } I couldn't retrieve the screenshot of my image but here's what it looks like As you can see the border has crests and troughs thereby renering it squiggly which I do not want. All I want is a simple curve

    Read the article

  • Choosing circle radius to fully fill a rectangle

    - by Andy
    Hi, the pixman image library can draw radial color gradients between two circles. I'd like the radial gradient to fill a rectangular area defined by "width" and "height" completely. Now my question, how should I choose the radius of the outer circle? My current parameters are the following: A) inner circle (start of gradient) center pointer of inner circle: (width*0.5|height*0.5) radius of inner circle: 1 color: black B) outer circle (end of gradient) center pointer of outer circle: (width*0.5|height*0.5) radius of outer circle: ??? color: white How should I choose the radius of the outer circle to make sure that the outer circle will entirely fill my bounding rectangle defined by width*height. There shall be no empty areas in the corners, the area shall be completely covered by the circle. In other words, the bounding rectangle width,height must fit entirely into the outer circle. Choosing outer_radius = max(width, height) * 0.5 as the radius for the outer circle is obviously not enough. It must be bigger, but how much bigger? Thanks!

    Read the article

  • How does this circle collision detection math work?

    - by Griffin
    I'm going through the wildbunny blog to learn about collision detection. I'm confused about how the vectors he's talking about come into play. Here's the part that confuses me: p = ||A-B|| – (r1+r2) The two spheres are penetrating by distance p. We would also like the penetration vector so that we can correct the penetration once we discover it. This is the vector that moves both circles to the point where they just touch, correcting the penetration. Importantly it is not only just a vector that does this, it is the only vector which corrects the penetration by moving the minimum amount. This is important because we only want to correct the error, not introduce more by moving too much when we correct, or too little. N = (A-B) / ||A-B|| P = N*p Here we have calculated the normalised vector N between the two centres and the penetration vector P by multiplying our unit direction by the penetration distance. I understand that p is the distance by which the circles penetrate, but I don't get what exactly N and P are. It seems to me N is just the coordinates of the 3rd point of the right trianlge formed by point A and B (A-B) then being divided by the hypotenuse of that triangle or distance between A and B (||A-B||). What's the significance of this? Also, what is the penetration vector used for? It seems to me like a movement that one of the circles would perform to get un-penetrated.

    Read the article

  • Help needed throwing a ball in AS3

    - by Opoe
    I'm working on a flash game, coding on the time line. What I'm trying to accomplish is the following: With the mouse you swing and throw/release a ball which bounces against the walls and eventualy comes to point where it lays still (like a real ball). I allmost had it working, but now the ball sticks to the mouse, in stead of being released, my question to you is: Can you help me make this work and explain to me what I did wrong? You can simply preview my code by making a movieclip named 'circle' on a 550x400 stage. stage.addEventListener(Event.ENTER_FRAME, circle_update); var previousPostionX:Number; var previousPostionY:Number; var throwSpeedX:Number; var throwSpeedY:Number; var isItDown:Boolean; var xSpeed:Number = 0; var ySpeed:Number = 0; var friction:Number = 0.96; var offsetX:Number = 0; var offsetY:Number = 0; var newY:Number = 0; var oldY:Number = 0; var newX:Number = 0; var oldX:Number = 0; var dragging:Boolean; circle.buttonMode = true; circle.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); circle.addEventListener(Event.ENTER_FRAME, throwcircle); circle.addEventListener(MouseEvent.MOUSE_DOWN, clicked); circle.addEventListener(MouseEvent.MOUSE_UP, released); function mouseDownHandler(e:MouseEvent):void { dragging = true; stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); offsetX = mouseX - circle.x; offsetY = mouseY - circle.y; } function mouseUpHandler(e:MouseEvent):void { dragging = false; } function throwcircle(e:Event) { circle.x += xSpeed; circle.y += ySpeed; xSpeed *= friction; ySpeed *= friction; } function changeFriction(e:Event):void { friction = e.target.value; trace(e.target.value); } function circle_update(e:Event){ if ( dragging == true ) { circle.x = mouseX - offsetX; circle.y = mouseY - offsetY; } if(circle.x + (circle.width * 0.50) >= 550){ circle.x = 550 - circle.width * 0.50; } if(circle.x - (circle.width * 0.50) <= 0){ circle.x = circle.width * 0.50; } if(circle.y + (circle.width * 0.50) >= 400){ circle.y = 400 - circle.height * 0.50; } if(circle.y - (circle.width * 0.50) <= 0){ circle.y = circle.height * 0.50; } } function clicked(theEvent:Event) { isItDown =true; addEventListener(Event.ENTER_FRAME, updateView); } function released(theEvent:Event) { isItDown =false; } function updateView(theEvent:Event) { if (isItDown==true){ throwSpeedX = mouseX - previousPostionX; throwSpeedY = mouseY - previousPostionY; circle.x = mouseX; circle.y = mouseY; } else{ circle.x += throwSpeedX; circle.y += throwSpeedY; throwSpeedX *=0.9; throwSpeedY *=0.9; } previousPostionX= circle.x; previousPostionY= circle.y; }

    Read the article

  • How to draw a circle in java with a radius and points around the edge

    - by windopal
    Hi, I'm really stuck on how to go about programming this. I need to draw a circle within a JFrame with a radius and points around the circumference. i can mathematically calculate how to find the coordinates of the point around the edge but i cant seem to be able to program the circle. I am currently using a Ellipse2D method but that doesn't seem to work and doesn't return a radius, as under my understanding, it doesn't draw the circle from the center rather from a starting coordinate using a height and width. My current code is on a separate frame but i need to add it to my existing frame. import java.awt.*; import javax.swing.*; import java.awt.geom.*; public class circle extends JFrame { public circle() { super("circle"); setSize(410, 435); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Panel sp = new Panel(); Container content = getContentPane(); content.add(sp); setContentPane(content); setVisible(true); } public static void main (String args[]){ circle sign = new circle(); } } class Panel extends JPanel { public void paintComponent(Graphics comp) { super.paintComponent(comp); Graphics2D comp2D = (Graphics2D) comp; comp2D.setColor(Color.red); Ellipse2D.Float sign1 = new Ellipse2D.Float(0F, 0F, 350F, 350F); comp2D.fill(sign1); } }

    Read the article

  • Most "thorough" distribution of points around a circle

    - by hippietrail
    This question is intended to both abstract and focus one approach to my problem expressed at "Find the most colourful image in a collection of images". Imagine we have a set of circles, each has a number of points around its circumference. We want to find a metric that gives a higher rating to a circle with points distributed evenly around the circle. Circles with some points scattered through the full 360° are better but circles with far greater numbers of points in one area compared to a smaller number in another area are less good. The number of points is not limited. Two or more points may coincide. Coincidental points are still relevant. A circle with one point at 0° and one point at 180° is better than a circle with 100 points at 0° and 1000 points at 180°. A circle with one point every degree around the circle is very good. A circle with a point every half degree around the circle is better. In my other (colour based question) it was suggested that standard deviation would be useful but with caveat. Is this a good suggestion and does it cope with the closeness of 359° to 1°?

    Read the article

  • How to detect if an ellipse intersects(collides with) a circle

    - by php html
    I want to improve a collision system. Right now I detect if 2 irregular objects collide if their bounding rectangles collide. I want to obtain the for rectangle the corresponding ellipse while for the other one to use a circle. I found a method to obtain the ellipse coordinates but I have a problem when I try to detect if it intersects the circle. Do you know a algorithm to test if a circle intersects an ellipse?

    Read the article

  • Silverlight 3 ArcSegment to always draw circle's

    - by kapaboo
    Hi everyone, Ok, my arcSegment must always draw Circle's. For this reason I calculate the Arc's Width with the following formula: arcXRadius = (4 * Math.Pow(height, 2) + Math.Pow(distanceArcPoints, 2)) / (8 * height); so Arcs.Size = (arcXRadius,height) But seems that the height is scaled down when drawn. I want to add a small Circle to the Arc's middle (highest point) so when you drag it it changes the arc Height but also changes the Width so it will remain a circle. Here's how I calculate the Circle's (highest) point: Point middlePoint = GetMiddlePoint(arcPointA,arcPointB); double arcYRadius = arcSegment.Size.Height; if (arcYRadius <= 0) return middlePoint; double angle = arcSegment.RotationAngle; Point ellinewPoint = new Point(); ellinewPoint.X = Math.Cos((angle + 90) * Math.PI / 180) * arcYRadius + middlePoint.X; ellinewPoint.Y = Math.Sin((angle + 90) * Math.PI / 180) * arcYRadius + middlePoint.Y; Until Arc's.Size.Height Property gets Closer to the Width my Circle is not at the right Point. So maybe someone can give me a hint or tell me what am I doing wrong. Cheers, kapaboo

    Read the article

  • Sphere-Sphere intersection and Circle-Sphere intersection

    - by cagirici
    I have code for circle-circle intersection. But I need to expand it to 3-D. How do I calculate: Radius and center of the intersection circle of two spheres Points of the intersection of a sphere and a circle? Given two spheres (sc0,sr0) and (sc1,sr1), I need to calculate a circle of intersection whose center is ci and whose radius is ri. Moreover, given a sphere (sc0,sr0) and a circle (cc0, cr0), I need to calulate the two intersection points (pi0, pi1) I have checked this link and this link, but I could not understand the logic behind them and how to code them. I tried ProGAL library for sphere-sphere-sphere intersection, but the resulting coordinates are rounded. I need precise results.

    Read the article

  • UIButton: Need a circle hit area

    - by Pavan
    Ok I have 6 custom UIButtons. Their normal state image are all circles images. They are all spaced out equally but all the circles touch each other. The problem with the custom UIbutton (which has a circle image on it), is that the hit area of that button is square, and the corners of this square overlaps the hitarea of the other custom button's hitarea. How do i make the hit area of a UIbutton whos normal state has a circle image, be only clickable on that circle only, rather than the normal square hit area?! I hope that someone can find a way for me to solve this problem that i currently am having! Thanks in advance Pavan

    Read the article

  • Great Circle & Ray intersection

    - by Karl T
    I have a Latitude, Longitude, and a direction of travel in degrees true north. I would like to calculate if I will intersect a line defined by two more Lat/Lon points. I figure the two points defining the line would create my great circle and my location and azimuth would define my ray (or possibly a small circle). Any ideas?

    Read the article

  • libgdx - removing the circle outline rendered on Box2d CircleShape

    - by Brett
    How can I remove the outline on the circleshape below.. CircleShape circle = new CircleShape(); circle.setRadius(1f); ... using ... batch.draw(textureRegion, position.x - 1, position.y - 1, 1f, 1f, 2, 2, 1, 1, angle); I use this to set the body for a Box2d collision but I get a silly circle shape around my texture in libGdx, i.e. my textured sprite (ball) has a circle over the top of it with a line running from center along the radius. Any ideas on how to remove the overlying circle lines?

    Read the article

  • circle - rectangle collision in 2D, most efficient way

    - by john smith
    Suppose I have a circle intersecting a rectangle, what is ideally the least cpu intensive way between the two? method A calculate rectangle boundaries loop through all points of the circle and, for each of those, check if inside the rect. method B calculate rectangle boundaries check where the center of the circle is, compared to the rectangle make 9 switch/case statements for the following positions: top, bottom, left, right top left, top right, bottom left, bottom right inside rectangle check only one distance using the circle's radius depending on where the circle happens t be. I know there are other ways that are definitely better than these two, and if could point me a link to them, would be great but, exactly between those two, which one would you consider to be better, regarding both performance and quality/precision? Thanks in advance.

    Read the article

  • PHP: How to find connections between users so I can create a closed friend circle?

    - by CuSS
    Hi all, First of all, I'm not trying to create a social network, facebook is big enough! (comic) I've chosen this question as example because it fits exactly on what I'm trying to do. Imagine that I have in MySQL a users table and a user_connections table with 'friend requests'. If so, it would be something like this: Users Table: userid username 1 John 2 Amalia 3 Stewie 4 Stuart 5 Ron 6 Harry 7 Joseph 8 Tiago 9 Anselmo 10 Maria User Connections Table: userid_request userid_accepted 2 3 7 2 3 4 7 8 5 6 4 5 8 9 4 7 9 10 6 1 10 7 1 2 Now I want to find circles between friends and create a structure array and put that circle on the database (none of the arrays can include the same friends that another has already). Return Example: // First Circle of Friends Circleid => 1 CircleStructure => Array( 1 => 2, 2 => 3, 3 => 4, 4 => 5, 5 => 6, 6 => 1, ) // Second Circle of Friends Circleid => 2 CircleStructure => Array( 7 => 8, 8 => 9, 9 => 10, 10 => 7, ) I'm trying to think of an algorithm to do that, but I think it will take a lot of processing time because it would randomly search the database until it 'closes' a circle. PS: The minimum structure length of a circle is 3 connections and the limit is 100 (so the daemon doesn't search the entire database) EDIT: I've think on something like this: function browse_user($userget='random',$users_history=array()){ $user = user::get($userget); $users_history[] = $user['userid']; $connections = user::connection::getByUser($user['userid']); foreach($connections as $connection){ $userid = ($connection['userid_request']!=$user['userid']) ? $connection['userid_request'] : $connection['userid_accepted']; // Start the circle array if(in_array($userid,$users_history)) return array($user['userid'] => $userid); $res = browse_user($userid, $users_history); if($res!==false){ // Continue the circle array return $res + array($user['userid'] => $userid); } } return false; } while(true){ $res = browse_user(); // Yuppy, friend circle found! if($res!==false){ user::circle::create($res); } // Start from scratch again! } The problem with this function is that it could search the entire database without finding the biggest circle, or the best match.

    Read the article

  • Great Circle & Rhumb line intersection

    - by Karl T
    I have a Latitude, Longitude, and a direction of travel in degrees true north. I would like to calculate if I will intersect a line defined by two more Lat/Lon points. I figure the two points defining the line would create my great circle and my location and azimuth would define my Rhumb line. I am only interested in intersections that will occur with a few hundred kilometers so I do not need every possible solution. I have no idea where to begin.

    Read the article

  • Why circles are not created if small?

    - by Suzan Cioc
    I have changed the scale to my own and now I cant create any object, including circle, if it is of the size which is normal for my scale. I am to create big object first and then modify it to smaller size. Looks like minimal size protection is set somewhere. Where? UPDATE While creating a circle, if I drag for 0.04m circle disappears after drag end. If I drag for 0.08m circle also disappears. If I drag for more than 0.1m, circle persists after drag end. How to set so that it persist after 0.01m too?

    Read the article

  • Circle drawing with SVG's arc path

    - by ????
    The following SVG path can draw 99.99% of a circle: (try it on http://jsfiddle.net/DFhUF/46/ and see if you see 4 arcs or only 2, but note that if it is IE, it is rendered in VML, not SVG, but have the similar issue) M 100 100 a 50 50 0 1 0 0.00001 0 But when it is 99.99999999% of a circle, then nothing will show at all? M 100 800 a 50 50 0 1 0 0.00000001 0 And that's the same with 100% of a circle (it is still an arc, isn't it, just a very complete arc) M 100 800 a 50 50 0 1 0 0 0 How can that be fixed? The reason is I use a function to draw a percentage of an arc, and if I need to "special case" a 99.9999% or 100% arc to use the circle function, that'd be kind of silly. Again, a test case on jsfiddle using RaphaelJS is at http://jsfiddle.net/DFhUF/46/ (and if it is VML on IE 8, even the second circle won't show... you have to change it to 0.01) Update: This is because I am rendering an arc for a score in our system, so 3.3 points get 1/3 of a circle. 0.5 gets half a circle, and 9.9 points get 99% of a circle. But what if there are scores that are 9.99 in our system? Do I have to check whether it is close to 99.999% of a circle, and use an arc function or a circle function accordingly? Then what about a score of 9.9987? Which one to use? It is ridiculous to need to know what kind of scores will map to a "too complete circle" and switch to a circle function, and when it is "a certain 99.9%" of a circle or a 9.9987 score, then use the arc function.

    Read the article

  • Circle-Line Collision Detection Problem

    - by jazzdawg
    I am currently developing a breakout clone and I have hit a roadblock in getting collision detection between a ball (circle) and a brick (convex polygon) working correctly. I am using a Circle-Line collision detection test where each line represents and edge on the convex polygon brick. For the majority of the time the Circle-Line test works properly and the points of collision are resolved correctly. Collision detection working correctly. However, occasionally my collision detection code returns false due to a negative discriminant when the ball is actually intersecting the brick. Collision detection failing. I am aware of the inefficiency with this method and I am using axis aligned bounding boxes to cut down on the number of bricks tested. My main concern is if there are any mathematical bugs in my code below. /* * from and to are points at the start and end of the convex polygons edge. * This function is called for every edge in the convex polygon until a * collision is detected. */ bool circleLineCollision(Vec2f from, Vec2f to) { Vec2f lFrom, lTo, lLine; Vec2f line, normal; Vec2f intersectPt1, intersectPt2; float a, b, c, disc, sqrt_disc, u, v, nn, vn; bool one = false, two = false; // set line vectors lFrom = from - ball.circle.centre; // localised lTo = to - ball.circle.centre; // localised lLine = lFrom - lTo; // localised line = from - to; // calculate a, b & c values a = lLine.dot(lLine); b = 2 * (lLine.dot(lFrom)); c = (lFrom.dot(lFrom)) - (ball.circle.radius * ball.circle.radius); // discriminant disc = (b * b) - (4 * a * c); if (disc < 0.0f) { // no intersections return false; } else if (disc == 0.0f) { // one intersection u = -b / (2 * a); intersectPt1 = from + (lLine.scale(u)); one = pointOnLine(intersectPt1, from, to); if (!one) return false; return true; } else { // two intersections sqrt_disc = sqrt(disc); u = (-b + sqrt_disc) / (2 * a); v = (-b - sqrt_disc) / (2 * a); intersectPt1 = from + (lLine.scale(u)); intersectPt2 = from + (lLine.scale(v)); one = pointOnLine(intersectPt1, from, to); two = pointOnLine(intersectPt2, from, to); if (!one && !two) return false; return true; } } bool pointOnLine(Vec2f p, Vec2f from, Vec2f to) { if (p.x >= min(from.x, to.x) && p.x <= max(from.x, to.x) && p.y >= min(from.y, to.y) && p.y <= max(from.y, to.y)) return true; return false; }

    Read the article

  • How do I create a curved line or filled circle or generally a circle using C++/SDL?

    - by NoobScratcher
    Hello I've been trying for ages to make a pixel circle using the putpixel function provided by SDL main website here is that function : void putpixel(int x,int y , int color , SDL_Surface* surface) { unsigned int *ptr = static_cast <unsigned int *> (surface->pixels); int offset = y * (surface->pitch/sizeof(unsigned int)); ptr[offset + x] = color; } and my question is how do I curve a line or create an circle arc of pixels or any other curved shape then a rectangle or singular pixel or line. for example here are some pictures filled pixel circle below enter link description here now my idea was too change the x and y value of the pixel position using + and - to create the curves but in practice didn't provide the correct results what my results are in this is to be able to create a circle that is made out of pixels only nothing else. thank you for anyone who takes the time to read this question thanks! :D

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >