Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
Entry:
a 3D-graph of m vertex
a sphere of radius r, volume V, any center
a vertex v of the graph
Question:
What is the probability of v to be inside the sphere?
Possible answer:
The intuition tell me this probability is: 1 / (m * V) but I can't prove it.
your equation looks wrong to me as m does not affect probability. The distribution of vertex coordinates does. If it is uniform in some volume V0 covering the whole sphere volume V then the probability should be:
p = V/V0
if you want to have actual count of such points then:
n = m*p = m*V/V0
I can not provide you with mathematical proof but you can simply do this programaticaly. For example let V0 be axis aligned cube with half size R=1000.0 and center (0,0,0) with the sphere as its biggest inscribed sphere with r=1000 and the same center so:
float x,y,x0,y0,z0,r;
float rr ,X0,Y0,Z0,R;
int i,m,n;
r=1000.0; x0=0.0; y0=0.0; z0=0.0; // sphere V
R=1000.0; X0=0.0; Y0=0.0; Z0=0.0; // cube V0
m=10000; // number of points
Randomize();
for (i=0,n=0;i<m;i++)
{
// random uniformly distributed position inside V0
x=X0+2.0*Random()*-0.5)*R;
y=Y0+2.0*Random()*-0.5)*R;
z=Z0+2.0*Random()*-0.5)*R;
// compute sphere radius^2
rr = (x-x0)*(x-x0)+(y-y0)*(y-y0)+(z-z0)*(z-z0);
// if inside
if (rr<=r*r) n++;
}
// here n should be close to m*V/V0 = (4.0/3.0)*M_PI*r*r*r/(8.0*R*R*R);
// the bigger the m the more closer it should be.
This approach is sometimes used to compute the Pi number.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
So I'm trying to make an animation of 2 objects orbiting around one object that we will call the sun. The distance from object 1 to the sun is 2 units and that has a constant angle at which it turns and moves on.
I assume that the farther away from the sun it is the smaller the angle so the bigger the circle, but how would you calculate this angle depending on the distance? Here is a picture:
So let's just talk about how to calculate the X, Y coordinates of an object moving around the origin at a constant distance D and with angular velocity W (angular velocity is the number of degrees per second).
The angle Q that our object will make with the ray beginning at the origin and pointed at the positive X-axis is given by Q(t) = Q0 + Wt, where Q0 is the angle the object makes at time t = 0 (the initial condition). If we assume that the object begins immediately to the right of the origin, Q0 = 0, for instance.
The X, Y coordinates of the object at time t can be found using trigonometry on Q(t):
X(t) = D * cos(Q(t)) = D * cos(Q0 + Wt)
Y(t) = D * sin(Q(t)) = D * sin(Q0 + Wt)
If you have two objects at different distances from the origin/sun, then for the same angular velocity W, the object closer to the origin/sun will move with a slower speed than the one farther away. This is because to move the same number of degrees around a larger circle, the object farther away has longer actual distance to go in the same time. Assuming that the angular velocity is being measured in degrees per second, the object's speed in D's distance units per second can be found as follows:
V = (angular velocity / 360 degrees) * (circumference of circle)
= (W/360) * (2*PI*D)
= 2*PI*D*W/180
So, if you wanted V to be constant rather than W, you could solve this for W in terms of your desired V and D.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
Update
I do not think this question is off topic.
The solution provided is what I was looking for and it is a programming solution.
================
I want to know how can I find the coordinates of equal chords from the same point on the circle.
As shown in the image below, I will like to choose a random point on a circle and a random chord angle (in the example its 110 degrees).
I will know the radius (r) of the circle and one randomly selected point (A) on a circle.
Based on this data, I would like to know how can I draw two equal chords from this point (AB and AC) where AB = AC.
Let you have circle center xc, yc, radius R.
At first choose random angle in range 0..2*Pi
aangle = random(2*Pi)
Then A coordinates are
ax = xc + R * Cos(aangle)
ay = yc + R * Sin(aangle)
Now choose random (or you need specific value?) chord angle in needed range and get B, C coordinates
changle = random(3 * Pi / 4)
bx = xc + R * Cos(aangle + changle)
cx = xc + R * Cos(aangle - changle) // note subtraction
and similar for Y-coordinates
If you have A coordinates, you can also rotate them around center
bx = xc + (ax - xc) * Cos(changle) - (ay - yc) * Sin(changle)
and so on
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Essentially, i want to find the equation of the ring that circles a point in space, this ring is perpendicular to a normal away from this point.
I have a line, in the form of 2 points, L1, L2;
I have the normal from L1->L2, N;
I have the plane that is normal to L1->L2, which L1 lies on. ax + by + cz = d;
I have the radius away from L1, R;
-> I want to make a point V, orbit this line around point L1;
I think I have to make a circular equation in this plane with L1 as the origin. I have no idea how to plot a 2d equation onto a 3d plane.
Or maybe someone knows how to do do this another way, cross products or something?
This problem actually requires a nontrivial solution. Suppose you have U = normalize(L2 - L1) and two unit vectors V and W such that U, V, W are pairwise orthogonal.
Then f(a) = L1 + R * (V * cos(a) + W * sin(a)) for angles a is the equation for the circle you want.
How can you find W given U and V? W can just be their cross product.
How can you find V given U? This is where it's not straightforward. There are a whole circle of such V that could be chosen, so we can't just solve for "the" solution.
Here's a procedure for finding such a V. Let U = (Ux, Uy, Yz).
If Ux != 0 or Uy != 0, then V = normalize(cross(U, (0,0,1)))
Else if Ux != 0 or Uz != 0, then V = normalize(cross(U, (0,1,0)))
Else U = 0, error
Note: You can negate W if you want your point to cycle in the opposite direction.
You may use Rodrigues' Rotation Formula (try to find better description)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I need to calculate circumcenter coordinates (or at least I hope they're called that) at point C for an isosceles triangle (the circle must be such, that created triangle is). I know the point O (origin), two vectors p and q (length may differ) originating in that point (leading to points P and Q). I also know the radius r of this to be circumscribed circle. When the circle's center is known it should create said green highlighted isosceles triangle. Here is drawing for better understanding:
Update (solution):
Calculates the length of p and q vectors
Normalize them both, and add them together
Normalize this to be OC vector again
Finally extend OC vector from point of origin O to length equivalent to radius r
Thinking geometrically:
normalise vectors p and q, i.e. p = p / |p|, q = q / |q|
add them together
normalise the result
multiply that by r - this is the vector OC
add to O
Steps 1 - 3 simply produce the bisection of the vectors p and q
EDIT this is simplified somewhat compared to my original answer.
The first equation of your system is:
(x_c-x_o)^2 + (y_c-y_o)^2 = r^2
The second one is more convoluted. You must intersect the circumference
(x-x_c)^2+(y-y_c)^2 = r^2
with your two vectors, that have equation rispectively
y = (Q_y/Q_x)*x and y = (P_y/P_x)*x
this gives you the two points of intersection p and q in function of x_c and y_c. Now force hte distance OP and OQ to be equal (you want an isoscele triangle), and you have your second equation.
Solve hte two equation system and you have the formula for x_c and y_c.
Assuming i did the math right, the solution is:
x_c = ((a+b)^2 * r^2) / ((a+b)^2+4)
y_c = (-2*(a+b) * r^2) / ((a+b)^2+4)
where
a = p_y / p_x
b = q_y / q_x
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
This is not homework. We are trying to build double connection lines between circles for a project.
Given a triangle of any type (because it will be rotated)
AB is known
AC is known
BC is known Where
AB is equal to BC (they are both the radius of the circle)
Point A is (x1,y1) and is known. It is the center point of the circle.
Point B is (x2,y2) and is known. It is the point on the edge of the circle that connects to the center of a remote circle.
Point C is unknown (x3,y3) and is what we are trying to figure out. I THINK we need to use the law of cosines, but it's not working out so far.
Thanks to anyone who can help!
You have much more info than you need to get the answer and it has nothing to do with law of cosine
Basically you only need A, B, AC, and BC
You draw a circle with A as the center and AC as the edge
You draw another circle with B as the center and BC as the edge
These two circles will have two intersecting points, and they are the two possible location of C
put it in math:
you have two Binary quadratic equations:
(x-x1)^2 + (y-y1)^2 = AC^2
(x-x2)^2 + (y-y2)^2 = BC^2
and you need to get (x, y) from these two equations
You can use the law of cosines, since you know the lengths of the three sides of the triangle (AB), (BC) and (AC). The law of cosines states that
(BC)^2 = (AC)^2 + (AB)^2 - 2 (AC)(AB) cos theta
where theta is the internal angle of the triangle at vertex A. Rearranging this gives
theta = acos(((BC)^2 - (AC)^2 - (AB)^2)/(-2 (AC)(AB)))
then your answer is (in vector notation):
(x,y) = (x1,y1) + (AC)*(v1,v2)
where (v1,v2) is the unit vector in the direction from A to C. (i.e., in scalar notation, x=x1+(AC)*v1 and y=y1+(AC)*v2). We can obtain v1 and v2 by rotating the unit vector from A to B by the angle theta:
v1 = (cos(theta)*(x2-x1) + sin(theta)*(y2-y1))/(AB)
v2 = (cos(theta)*(y2-y1) - sin(theta)*(x2-x1))/(AB)
Flip the sign of theta to get the other of the two solutions.
Note that one can avoid ever calculating theta by observing that:
cos(theta) = ((BC)^2 - (AC)^2 - (AB)^2)/(-2 (AC)(AB))
sin(theta) = sqrt(1-((BC)^2 - (AC)^2 - (AB)^2)/(-2 (AC)(AB))^2)
which may be faster to evaluate than the trigonometric functions.