I'm interested in knowing how I would go about detecting a primitive circle touching another primitive circle?
So, if I had a circle with 5,10 and another one with 5,13 with each of them having a radius of 2. well the distance formula is the Pythagorean theorem. which is sqrt((x2-x1)^2 + (y2-y1)^2) = distance and if this distance is less than or equal to the sum of their radius. the sum of the radius is 4? since each circle has a radi of 2? Is this kinda waht you mean?
You can check if the distance between their center is less or equal to the sum of their radius
Related
My question is probably more about maths rather than programming, but I hope that is not a problem.
In my app, I am calculating some movement paths, consisting of pixel coordinates (only calculating, not displaying them). I am now trying to smoothen the turn, which are now too sharp, so I would like to use some arc here. I found how I could draw the exact arc I need, using code like this:
e.Graphics.DrawArc(myPen, myPoint.X, myPoints.Y, 50, 50, 180, 90);
Basically what I know are three points (the arc will be between two of these, third is now the turn's corner), the height and width of the arc, the initial and wanted course/heading/angle. I tried this in an app that visualizes the path later, and it works. However, I need to calculate some coordinates on the arc, to add to the array of Points that I save as the path. Anyone knows how? I would need about 5 points for an arc of this size (the number of points will change however)
Thanks
DrawArc draws a part of an ellipse or a circle in your case (regarding the 4th and 5th parameter.) The radius of your circle is 25. The math of a circle is: x^2 + y^2 = r^2.
Therefore, I think you can calculate points on this circle by calculating:
Y = myPoint.Y + 25 +/- Sqrt(625 - (X - myPoint.X - 25)^2).
Let X run from myPoint.X to myPoint.X + 50 and you will find some corresponding Y's.
Because it is a circle, each X has 2 Y values (Therefore, +/- in the formula; you need to calculate the + and the -).
I have two points specified as lat/long(s) and would like to insert a new point in between them a certain distance (in meters) from point the initial point.
Presumably I convert the lat/longs to radians and then use a version of midpoint formula?
How can i accomplish this task?
I'm living in c# land btw.
TIA
The exact solution is not that simple (an approximate solution is just given by linear interpolation). You're not going to love it.
The trajectory follows a great circle, which is the intersection between the sphere and a plane through the center and the two given points.
First convert from spherical to Cartesian coordinates. Then by the cross product of the vectors from the center to the two points, determine the direction of the normal to the plane (normalize the vector). Then use the formula for 3D rotation around this axis and rotate the starting point. The rotation angle is given by the desired distance divided by the radius of the Earth. Finally, convert back to spherical coordinates.
I am currently building a game about infrastructure building and management in XNA(C#).
What I am currently trying to achieve is to make the game draw 'bends' between train tracks. I want to do this by drawing only a certain part of a circle texture.
In other words, I only want to draw a "pizza slice" of this texture. The slice of the circle that needs to be drawn is based on three points:
The center of the sprite;
A variable position 'a';
A variable position 'b';
These three points together determine how much of my circle is drawn on the screen e.g. how big the pizza slice is.
To put it simply: If I have a circle and cut it from the centre to a point 'a' and then again from the centre to a point 'b', how can I only draw the part I've just cut out?
This slice has to be altered in real-time, so the slice becomes bigger and smaller based on those two positions 'a' and 'b'.
What is the best way to achieve this effect?
This can be done entirely in the shader with relatively simple trig. In your pixel shader (effect) try something like:
float dX = b.x - a.x;
float dY = b.y - a.y;
float theta = Math.Atan2(dY, dX);
Note that theta will be in radians. Then just check if theta is within your limits. Say, between 0 and pi/2. If it is, then sample the texture, if not then return a float4 with no alpha (transparent). That should give you the top right quarter of your texture with the rest masked out. If you want to convert theta to degrees you can do that too, but I recommend staying with radians as it makes your math so much easier.
You'll have to set your limits with
effect.Parameters['thetamin']=/*minTheta*/;
effect.Parameters['thetamax']=/*maxTheta*/;
Before you call EffectPass.Apply().
Chart 1:
So let's say I'm given angles 1,2,3, and 4 and their average. Imagine that these angles could potentially be any angle on the circle.
How do I:
A. From the average angle, detect the furthest angle in the clockwise direction (4).
B. From the average angle, detect the furthest angle in the counterclockwise direction (1).
C. Compute the radians/degrees between A and B that INCLUDES the average angle in that range. I'm not entirely sure how to phrase this, but going by the way the chart is setup, C should essentially be the difference in radians/degrees going clockwise from angle 1 until you reach angle 4.
Another example:
Chart 2:
A should be angle 1, B should be angle 2, and C should be 270 degrees (not 90).
Background:
I was recently playing around with GDI+ to draw a "Disc" displaying a sweeping color change through 360 degrees. (I dug up some HSL to RGB code to loop through HSL(1,1,1) -> HSL(360,1,1))
Regarding the disc, I first drew a full solid circle using the above, and then a second circle in Grey over the center to give the following
So this is all fine... but I realised that GDI+ is insulating us from a lot of the tricky match that's going on here by way of the FillPie method. Also, FillPie requires you to supply a bounding rectangle for the pie as opposed to a Radius Length. It also does a full segment fill and doesnt allow you to specify a part of that segment only.
Question:
Can anyone point me in the direction of some Math functions or give any explanation on what forumla I would need to calculate the area & plot points of the following "Green Filled Area" given:
Point `c` - an x,y co-ordinate
Angle `A` - an angle from horizontal
Angle `B - an angle from horizontal where `B` - `A` == the sweep angle
Length `r` - a distance from `c`
Length `r2` - a distance from `c` where `r2` - `r` == the `height` of the segment to be filled.
Links to Math sources are fine but I've had a quick google & look at Wolfram Math and could find what I was looking for. Also, if there was some way to generate a sequence of bounding (x,y) co-or's that could be passed as a Point[] to Graphics.FillPolygon, that'd be cool too.
The area is the difference of the outer and inner disc parts. The area of a disc part is proportional to the angle sweep:
area = (b-a)*((r+r2)^2-r^2)/2
a and b must be expressed in radians.
For b-a = 2*Pi, area = Pi*(r+r2)^2 - Pi*r^2 is the difference of the areas of the outer and inner discs.
You can generate points on the inner / outer circle using
x = cx + r * cos(t) / x = cx + (r+r2) * cos(t)
y = cy + r * sin(t) / y = cy + (r+r2) * sin(t)
Where t varies from a to b.
Hope this helps. The second part provides a method for calculating the area of a sector of a circle
http://www.wikihow.com/Calculate-the-Area-of-a-Circle
The area of a segment of a circle is simply the angle of the arc (in radians) times the radius. So the area of the green circle is obviously:
(B-A) * r2
You need to draw lines (this pseudo code):
for aa from A to B
set color to required color // you could use aa in an equation with HSL to get something like your sample
x1=r*cos(aa)+x
y1=r*sin(aa)+y
x2=r1*cos(aa)+x
y2=r1*sin(aa)+y
draw line between (x1,y1) and (x2,y2)
for a small-enough increment in the angles, and small-enough radii, this should be OK.
The points you're looking for are (x1,y1) and (x2,y2) for each angle aa