Intersection points between 2 discs in 3d - algorithm

i am trying to find a algorithm or a way to find the intersection between two circle on a sphere (in 3d). For example if i have two circles center at two pointsA(latitude1,longitude1) and B(latidude2,longitude2)
assuming that they intersect, how can i find the intersection between those two circles? is there an algorithm to do that?
Thank you

Convert from latitude/longitude to 3D Cartesian
coordinates.
For each circle, find the equation nx x + ny y + nz z = d of the
plane whose intersection with the sphere is the circle. Assuming
that the sphere is centered at the origin, the normal vector
(nx, ny, nz) is the circle center (cx, cy, cz) (projected or
not) after normalization.
(cx, cy, cz)
(nx, ny, nz) = -----------------
||(cx, cy, cz)||
2
The distance d is computed using Pythagoras. Let r be the radius
of the circle and R be the radius of the sphere.
2 2 2
R = d + r
_______ _______________
| 2 2 |
d = \|R - r = \|(R + r) (R - r)
The second expression is preferred for numerical stability.
If we know only the length r' on the surface of the sphere from
the projected center of the circle to the circle, then compute
d = R cos(r'/R)
r = R sin(r'/R).
We actually don’t need r in this case.
Find the intersection of the two planes, a
line.
Find the intersection of the line and the sphere, between zero and two
points.
Convert the points to
latitude/longitude.

Related

Geometry - convex flanked by two circle rotate around geometrical center

I want to do it that a convex(consist of some line or arc) rotate around it's geometrical center(Cx,Cy). Meanwhile the convex flanked by two circle (given by radius: R and left center:(Lx,Cy), right center:(Rx,Cy) ). It means the circle center with same X axis as geometrical(Cy).
The model picture:
The algorithm aims to calculate the Lx and Rx when rotate theta(0 to 360 degree) and the convex with two circle only have one contact point separately. How can I achieve it?
Assume we can get the convex discretization points by given delta distance or delta theta around geometrical center.
To provide contact between rotated convex and circle, it is worth to define convex pieces analytically.
For example, if straight segment has parametric equation
X = X0 + t * (X1-X0)
Y = Y0 + t * (Y1-Y0)
then solve equation system
(X - Lx)^2 + (Y - Cy)^2 = R^2 //distance
(X - Lx) * (X1 - X0) + (Y - Cy) * (Y1 - Y0) = 0 //tangent perpendicularity to radius
for unknowns t and Lx and check that t lies in range 0..1. If true - circle touches this segment, Lx if valid
If curved segment is analytical curve, then normal to the curve in touch point should be collinear with radius.
For circle arc segment with radius aR and center ax, ay tangency condition is:
(ax - Lx)^2 + (ay - Cy)^2 = (aR + R)^2
again - one need to check whether tangent point is inside arc limits

Geolocations - How to check if 2 circles are overlapping

Let's say we have 2 locations (latitude,longitude) and each location has a radius (it may be different from each other), making a circle. How to check if these 2 circles are overlapping?
Check if the distance between the centers is smaller than the sum of the radii.
Say for circles A and B with radius Ar and Br respectively, and coordinates (Ax, Ay) and (Bx, By) respectively, the distance between the circles is
D = sqrt( (Ax - Bx)2 + (Ay - By)2 )
They overlap when
D < Ar + Br
There's a catch, however: the centers of the circles are placed on a sphere. The shortest distance between them is a straight line, beneath the sphere's surface. The distance between them following the surface will be larger. For instance, the distance between the North and South pole is 2 Earth radii, but the path on the surface will be 2π Earth radii. Also, these circles don't overlap. So, the above equations only hold when the distances are relatively small.

How do I calculate a new coordinate of a point on a circle’s circumference?

How do I calculate a new coordinate of a point on a circle’s circumference ;
i have O(0,0), A(x,y) and i want to calculate B(x',y')
according to the following rule OA = λ OB like this
http://i59.tinypic.com/aakmqc.png
If I understand correctly, you're doing a projection of a point A onto your circle. Let's say the radius of the circle is r and the distance from the center of the circle to A is d. Then you need λ such that r = λ d, or λ = r/d.
For the circle center at the origin, you have d = Sqrt(x^2 + y^2).

How can I find the middle points of x, y of a line segment in a binary image?

I have some damaged line segments in a binary image and I need to fix them (make them straight and at their original thick). In order to do that I have to find the middle points of the segment, so when I check the neighborhood to find the thickness of the lines I'll be able to find where the pixel stops being 1 and becomes 0.
Assuming your damaged line segments are straight, you can use regionprops in MATLAB to find the center of each bounding box. Because if a segment is straight, its is always the diagonal line of the bounding box, thus the center of the box is also the center of the semgent.
Let's call the points A and B to reduce ambiguity, A(Xa, Ya) and B(Xb, Yb)
Let C be the middle point.
C(Xc, Yc)
Xc = (Xa + Xb) / 2
Yc = (Ya + Yb) / 2
We have four interesting numbers, two for the X coordinates and two for the Y coordinates.
Xmin = floor(Xc)
Xmax = ceil(Xc)
Ymin = floor(Yc)
Ymax = ceil(Yc)
The X coordinate of your middle point is either Xmin or Xmax, the Y coordinate of your middle point is either Ymin or Ymax.
So we have four potential points: (Xmin, Ymin), (Xmin, Ymax), (Xmax, Ymin), (Xmax, Ymax).
So, finally, we must decide which point is nearest to C.
Distance from P(Xp, Yp) to C(Xc, Yc) is:
sqrt(sqr(Xp - Xc) + sqr(Yp - Yc))
Calculate the four distance from the four points to C, choose the minimum and that will be the best possible middle point.
Suppose
A = [xa ya];
B = [xb yb];
then
C = round( mean([A;B]) );
Matlab's round rounds numbers towards their nearest integer, so this minimizes the (city-block) distance from the analytical center (mean([A;B])) to the nearest pixel.
If you want to keep sub-pixel precision (which is actually advisable for most calculations until an explicit map from a result to pixel indices is required), just drop the round and use only the mean part.

How to determine a semi-sphere's point x-y-z coordinates?

I'm having serious problems solving a problem illustrated on the pic below.
Let's say we have 3 points in 3D space (blue dots), and the some center of the triangle based on them (red dot - point P). We also have a normal to this triangle, so that we know which semi-space we talking about.
I need to determine, what is the position on a point (red ??? point) that depends on two angles, both in range of 0-180 degrees. Doesnt matter how the alfa=0 and betha=0 angle is "anchored", it is only important to be able to scan the whole semi-sphere (of radius r).
http://i.stack.imgur.com/a1h1B.png
If anybody could help me, I'd be really thankful.
Kind regards,
Rav
From the drawing it looks as if the position of the point on the sphere is given by a form of spherical coordinates. Let r be the radius of the sphere; let alpha be given relative to the x-axis; and let beta be the angle relative to the x-y-plane. The Cartesian coordinates of the point on the sphere are:
x = r * cos(beta) * cos(alpha)
y = r * cos(beta) * sin(alpha)
z = r * sin(beta)
Edit
But for a general coordinate frame with axes (L, M, N) centered at (X, Y, Z) the coordinates are (as in dmuir's answer):
(x, y, z) =
(X, Y, Z)
+ r * cos(beta) * cos(alpha) * L
+ r * cos(beta) * sin(alpha) * M
+ r * sin(beta) * N
The axes L and N must be orthogonal and M = cross(N, L). alpha is given relative to L, and beta is given relative to the L-M plane. If you don't know how L is related to points of the triangle, then the question can't be answered.
You need to find two unit length orthogonal vectors L, M say, in the plane of the triangle as well as the the unit normal N. The points on the sphere are
r*cos(beta)*cos(alpha) * L + r*cos(beta)*sin(alpha)*M + r*sin(beta)*N

Resources