So I want to make a script that can draw various microscope darkfield filters.
in those you have 3 support bars with a 120° angle holding a circle inside a circle.
I came up with something but wrongfully calculated the blue triangle value while I should have computed the purple triangle value.
I had to wake up my 9 years old trigonometry knowledge and it worked however I can't figure a way to compute the purple triangle values.
Here is an image :
for now since I'm computing the blue triangle I get this result :
Would anyone know what I need to compute the purple triangle?
Thanks.
Three intersect points will have coordinates (if circle center is 0,0), where i = 0,1,2:
for i = 0..2 do
Fi = Pi/2 + i * 2 * Pi / 3 //probably -Pi/2 depending on your graphics coordinate system
X = R * Cos(Fi)
Y = R * Sin(Fi)
Trivially: ac = r;
For de we look at half the side of an equal sided triangle: de = sin(a) = sin(30 degrees) = r/2
When it comes to ad we can use Pythagoras to compute; ad = cos(a)= cos(30 degrees) = r*sqrt(3)/2:
Related
I'm working on a project with two infrared positioning cameras which output the (X,Y) coordinate of any IR source. I'm placing them next to each other and my goal is to measure the 3D coordinate (X,Y,Z) of the IR source, using the same technique our eyes use to measure depth.
I have drawn a (lousy) sketch here
which illustrates what I'm trying to calculate. The red dot is my IR source, which can also be seen on the 'views' of the camera to the right. I am trying to measure the length of the blue line.
I have a few known variables:
The cameras have a resolution of 1024x768 (which also means that this is the maximum of the (X,Y) coordinate mentioned earlier)
Horizontally the field of view is 41deg, vertically 31deg.
I have yet to decide on the distance between cameras (AB), but this will be a known variable. Let's make it 30 cm for now.
Sadly I cannot seem to find the focal length of the camera.
Ultimately I'm hoping for an (X,Y,Z) coordinate relative to the middle point of AB. How would I go about measuring (Z)?
I am not sure how well aligned your cameras are, but from your pictures I am beginning to assume that the camera A and camera B are so well aligned that the rectangle representing the camera B's screen is simply horizontal translation of the rectangle representing the camera A's screen. What I mean by that is that the corresponding edges of the screens' rectangles are parallel to each other and the two rectangular screens lie in a common vertical plane perpendicular to the ground. Now, consider the plane parallel to the vertical plane that contains the two camera screens and passing through the focal points A and B of the two cameras. Call this latter plane the screen_plane. Also, the focal points A and B are at an equal height from the ground. If that is the case, and if I assume that c = |AB| is the distance between the focal points of the two cameras, and if I put a coordinate system at A, so that the x axis is horizontal to the ground, the y axis is perpendicular to the ground, and the z axis is parallel to the ground but perpendicular to the screen, then the focal point of camera B would have coordinates ( c, 0, 0 ). As an example, you have given c = 30 cm. Also the screen_plane is spanned by the x and y axes described above and the z axis is perpendicular to the screen_plane.
If that is the setting you want to work with, then the red point P will appear on both screens with the same coordinate Y_A = Y_B but different coordinates X_A and X_B.
Then let us denote by theta the horizontal field of view angle, which you have determined as theta = 41 deg. Just to be clear, I am assuming the angle between the leftmost side to the rightmost side of view is 2 * theta = 82 deg.
If I understand correctly, you are trying to calculate the distance Z between the vertical plane screen_plane that contains both camera focal points and the plane parallel to screen_plane and passing through the red point P, i.e. you are trying to calculate the distance from P to the vertical plane screen_plane.
Then, here is how you calculate Z:
Step 1: From the image of point P on screen A calculate the distances (e.g. the number of pixels) from P to the vertical edges of the screen. Say they are dist_P_to_left_edge and dist_P_to_right_edge. Set
a_A = dist_P_to_left_edge / (dist_P_to_left_edge + dist_P_to_right_edge) (this one is not really necessary)
b_A = dist_P_to_right_edge / (dist_P_to_left_edge + dist_P_to_right_edge)
Step 2: Do the same with the image of point P on screen B:
a_B = dist_P_to_left_edge / (dist_P_to_left_edge + dist_P_to_right_edge)
b_B = dist_P_to_right_edge / (dist_P_to_left_edge + dist_P_to_right_edge) (this one is not really necessary)
Step 3: Apply the formula:
Z = c * cot(theta) / (2 * (1 - b_A - a_B) )
So for example, from the pictures of the screens of camera A and B you have provided, I measured with a ruler, that
b_A = 4/38
a_B = 12.5/38
and from the data you have included
theta = 41 deg
c = 30 cm
so I have calculated that the length of the blue segment on your picture is
Z = 30 * cos(41*pi/180) / (sin(41*pi/180) * (1 - 4/38 - 12.5/38))
= 60.99628 cm
I have a bounding Box that is represented as a Cartesian starting point(0,0) with a width and height.
I have a circle with centre point that can be anywhere within the bounding box.
the circumference of the circle is fixed.
When the circle intersects the edge of the bounding box an arc is formed.
This new arc has to have a length = to the circumference of the original circle.
The location of the centre of the circle is is known there for the distance from the centre to the edge of the bounding box is know.
as you move closer to the edge of the bound box the radius of the circle must increase to keep the arc length the same
the start and stop points of the arc are unknown as the radius is unknown.
This is where I'm stuck. knowing only the distance from the bounding box and the fixed length of the arc how can I find the radius of the circle ?
I have drawn an image to represent the question but I'm unable to post due to lack of reputation.
Any help on this will be greatly appreciated as I have spent many days trying to figure this out.
What I am trying to achieve is a radial menu with fixed number of items (of a fixed size) can be displayed around a centre point. the fixed length is a calculated length that all menu items can fit around.
I am implementing this in .net but for the sake of this query its purely a Math question.
Edit: here is image of the issue:
Here is a possible line of attack. Let's put some names:
alpha = angle at which the circle intercepts the horizontal line on the right side
r = radius
arc = length of the "visible" circle (known)
L = length to edge (known) (Let's assume L > 0)
Pi the number pi.
Using that arc = radius * angle (radians), we have:
arc = Pi * r + 2 * alpha * r
sin(alpha) = L / r
Solving for alpha in the first equation
alpha = arc / (2 * r) - Pi / 2
Using that sin(a - b) = sin(a)cos(b) - cos(a)sin(b)
L / r = sin(alpha) = -cos(arc / (2 * r))
Now put u = L/r. Since L is known, u becomes the unknown. Replacing:
u = -cos(arc / (2 * L) * u)
Finally put F = arc / (2 * L). Then F is known and
u = - cos(F * u)
So, the problem reduces to solve this equation, which will require some numerical algorithm.
What I have done is created a multiplier and maped the distance from the edge so Y = 0 to 150 and mapped that down to 2 to 1 so if Y = 150 the map = 1 and if Y = 0 the map is 2 so if y = 75 then the map = 1.5 ect
This mapping is then used as a multiplier
radius = radius * map
This gets me close enough...
Then in the corner i do the same thing for X and add the 2 multiplier together so if you're in the far corner both maps = 2 and
so radius = radius * (mapX + mapY)
Doubles it on edges and quadruples it in the corners. which is ~ close enough
http://i.stack.imgur.com/7InNo.png
I am trying to find the green points using the angle ,radius and center of the circle.
I am using this image that was posted by another member.
I wish to find the green points, but in a 3d space instead.
I am able to get the x and y value but i am unable to get the z.
r = radius
X = r * cos(angle)
Y = r * sin(angle)
How can i get the value for z-axis?
In the case of 3 dimensions you need 2 angles. Basically what you are doing is converting from spherical coordinates to cartesian coordinates. So your formulas can be found here
Please see the image below for a visual clue to my problem:
I have the coordinates for points 1 and 2. They were derived by a formula that uses the other information available (see question: How to calculate a point on a circle knowing the radius and center point).
What I need to do now (separately from the track construction) is plot the points in green between point 1 and 2.
What is the best way of doing so? My Maths skills are not the best I have to admit and I'm sure there's a really simple formula I just can't work out (from my research) which to use or how to implement.
In the notation of my answer to your linked question (i.e. x,y is the current location, fx,fy is the current 'forward vector', and lx,ly is the current 'left vector')
for (i=0; i<=10; i++)
{
sub_angle=(i/10)*deg2rad(22.5);
xi=x+285.206*(sin(sub_angle)*fx + (1-cos(sub_angle))*(-lx))
yi=y+285.206*(sin(sub_angle)*fy + (1-cos(sub_angle))*(-ly))
// now plot green point at (xi, yi)
}
would generate eleven green points equally spaced along the arc.
The equation of a circle with center (h,k) and radius r is
(x - h)² + (y - k)² = r² if that helps
check out this link for points http://www.analyzemath.com/Calculators/CircleInterCalc.html
The parametric equation for a circle is
x = cx + r * cos(a)
y = cy + r * sin(a)
Where r is the radius, cx,cy the origin, and a the angle from 0..2PI radians or 0..360 degrees.
how can we draw a polygon. when only the sides and radius is given.
I have to make a pop up box which will take as input the radius and number of sides and will draw a ploygon. just need the formula.
Imagine a circle of radius r. It is like a regular polygon with an infinite number of sides.
Trigonometry tells us:
x = r * cos(a);
y = r * sin(a);
We know there are 360 degrees or 2pi radians in a circle. So to draw it we would start with angle = 0, calculate that co-ord, step to the next angle and calculate that point, then draw a line between the two.
There are only so many points we can calculate around the edge of the circle, eventually it won't make any difference. If the circle is small enough, even 8 sides will look round.
To draw an 8 sided circle we want 8 points evenly spaced around the circle. Divide the circle into 8 angles, each one is 2 * pi / 8 radians.
So:
angle = 0.0;
step = 2 * pi / 8;
for ( n = 0; n < 8; n++ ) {
x = radius * cos(angle);
y = radius * sin(angle);
angle += step;
}
Now you can draw an octagon, change it to draw the general case.