Area of hexagon outside circle - geometry

Let's have a circle with radius r.
I want to find out the area of the hexagon drawn around the circle. Supplemented is a sample image except I need to whole are of hexagon, not just intersection.
Area of hexagon drawn inside circle is:
(sqrt3*r)^2
as far as I know.

This hexagon consists of 6 equilateral triangles with height R. Area of such triangle is
s = R * R * Sqrt(3) / 3
Area of hexagon
S = 6 * s = 2 * Sqrt(3) * R^2
(If you need area of colored region, it is R^2 * (2 * Sqrt(3) - Pi))

Related

Is there a way to transform a point in the initial photo coordinates after a crop with cropperjs

I use cropperjs to crop some image, I keep in database the result of getData method who return values in white on the picture.
{x, y, width, height, rotate}
My users can place points on the cropped image in the red space, is there a way to retrieve the coordinates of the point in the blue space?
The crop ratio is free so there is no relation between original image ratio and crop ratio and I don't have the original image size.
Thank you for your help
At first get coordinates in bounding box
bbx = redx + x
bby = redy + y
Now make rotation about bounding box center
bluex = bbcenterx + (bbx - bbcenterx) * Cos(rotate) + (bby - bbcentery) * Sin(rotate)
bluey = bbcentery - (bbx - bbcenterx) * Sin(rotate) + (bby - bbcentery) * Cos(rotate)
If you don't know bounding box size, but know initial picture width w and height h, you can calculate bounding box center
bbcenterx = (w * Abs(Sin(rotate)) + h * Abs(Cos(rotate))) / 2
bbcenterx = (w * Abs(Cos(rotate)) + h * Abs(Sin(rotate))) / 2

Drawing a circle without using a function for it

So I was wondering how does a circle() function work, and how can I draw to circle without using it (wanted to do something related to it). Does anyone know this stuff?
A classic way of rasterizing a circle is using the Midpoint Circle Algorithm.
It works by tracking the pixels which are as close to the x2 + y2 = r2 isoline as possible. This can even be done with purely integer calculations, which is particularly suitable for low-computation power devices.
A circle is the set of points located at a constant distance from another point, called the center.
If you can draw lines defined by two points, you can draw the representation of a circle on a canvas, knowing its center, and its radius.
The approach is to determine a set of consecutive points located on the circumference, then join them with lines.
for instance, in python (which reads like pseudocode):
import math
def make_circle(center, radius, num_points=40):
"""returns a sequence of points on the circumference
"""
points = [center]
d_theta = 2 * math.pi / num_points
cx, cy = center
for idx in range(num_points + 1):
theta = idx * d_theta
points.append((cx + math.cos(theta) * radius, cy + math.sin(theta) * radius))
return points
And if you want to try it, here it is: circles codeskulptor.
You will see that for display purposes, 40 points on the circumference is enough to give an acceptable rendition.

Having the coordinates of the two triangles of a twisted triangle prism, how can I know if a point is inside it?

Here some examples of twisted triangle prisms.
I want to know if a moving triangle will hit a certain point. That's why I need to solve this problem.
The idea is that a triangle with random coordinates becomes the other random triangle whose vertices all move between then
related: How to determine point/time of intersection for ray hitting a moving triangle?
One of my students made this little animation in Mathematica.
It shows the twisting of a prism to the Schönhardt polyhedron.
See the Wikipedia page for its significance.
It would be easy to determine if a particular point is inside the polyhedron.
But whether it is inside a particular smooth twisting, as in your image, depends on the details (the rate) of the twisting.
Let's bottom triangle lies in plane z=0, it has rotation angle 0, top triangle has rotation angle Fi. Height of twisted prism is Hgt.
Rotation angle linearly depends on height, so layer at height h has rotation angle
a(h) = Fi * h / Hgt
If point coordinates are (x,y,z), then shift point to z=0 and rotate (x,y) coordinates about rotation axis (rx, ry) by -a(z) angle
t = -a(z) = - Fi * z / Hgt
xn = rx + (x-rx) * Cos(t) - (y-ry) * Sin(t)
yn = ry + (x-rx) * Sin(t) - (y-ry) * Cos(t)
Then check whether (xn, yn) lies inside bottom triangle

How to calculate rectangle size for specific corner radius?

I have some square board .
I would like it to be inside a rounded corners square box.
Question seems to be basic, but how do you calculate how much length you have to add to your square board ,in order to make a rounded square box with specific radius that cover it exactly ?
For example i have a square 30x30mm board , and i would like to cover it with a square box that has corner radius of 6mm , how much length do i have to add to the 30mm , to create that box so it can filled with the original board ( so the board can exactly "live" inside that box )
Agree that the OP application may be carpentry but it seems like an interesting enough geometry problem that it could have programming/graphics applications. Here's what I come up with:
Let I = inner square side length (30mm)
O = outer rounded square side length
r = corner radius (6mm)
Decompose the outer rounded square into 9 sections:
1 center square (with diagonal length d and side length c)
4 side squares (left, right, above, and below)
4 round corners
Since the inner square fits into the outer square,
the outer rounded square diagonal is I * sqrt(2)
Since there are 2 rounded corners the diagonal of the center square is
d = I sqrt(2) - 2 * r
The diagonal of the center square is sqrt(2) times its side
d = c * sqrt(2)
Equating these two
c = I - r * sqrt(2)
The side length of the outer square is
O = c + 2 * r
Substituting for c
O = I + r * (2 - sqrt(2))
Your question asked for the amount of length to add which would be
length to add = O - I = r * (2 - sqrt(2))
In your case, 6mm * (2 - sqrt(2)) = 3.515mm (approximately)

Normalized Device Coordinates to window coordinates

I just read some stuff about the theory behind 3d graphics. As I understand it, normalized device coordinates (NDC) are coordinates that describe a point in the interval from -1 to 1 on both the horizontal and vertical axis. On the other hand window coordinates describe a point somewhere between (0,0) and (width,height) of the window.
So my formula to convert a point from the NDC coordinate system to the window system would be
xwin = width + xndc * 0.5 * width
ywin = height + ynfv * 0.5 * height
The problem now is that in the OpenGL documentation for glViewport there is an other formula:
xwin = ( xndc + 1 ) * width * 0.5 + x
ywin = ( yndc + 1 ) * height * 0.5 + y
Now I'm wondering what I am getting wrong. Especially I'm wondering what the additional "x" and "y" mean.
Hope the question isn't too "not programming related", but I thought somehow it is related to graphics programming.
Viewport doesn't necessarily start at (0; 0), so 'x' and 'y' in OpenGL documentation refers to viewport starting position.
To see what's wrong with your equation, try transforming (0; 0) normalized position, and you will get (width; height) instead of (width / 2; height / 2).

Resources