Equation of sector of a circle - geometry

As there is equation for circle such as
(x-h)^2 + (y-k)^2 = r^2 where center(h,k) and redius r.
Is there any equation for sector of circle like that?
As there is equation for circle such as
(x-h)^2 + (y-k)^2 = r^2 where center(h,k) and redius r.
Is there any equation for sector of circle like that?

Related

How to find degree on circle is tangent to point outside of circle?

I know the (x,y) of a point, P, outside of a circle.
I know the (x,y) for the origin of a circle, O.
I know the radius, r, of that circle.
How would I find what degree (e.g. 20 degrees, 270 degrees) is tangent to the point outside of the circle?
Make origin in circle center (subtract center coordinates from coordinates of point P) to simplify calculations
Compose equation system - dot product of tangent and radius-vector is zero, radius vector length is r
tx * (tx - px) + ty * (ty - py) = 0
tx * tx + ty * ty = r*r
Solve this system for unknowns tx, ty (tangent point)
Get angle as atan2(ty, tx)

How to draw an ellipse in codeworld haskell given co-ordinates

I need to draw an ellipse given two co-ordinates
Ellipse Coords
Coords
but i'm not sure how to do this with vertices, co-vertices, foci, and a centre point. I'm basically confused as to which points go into the two co-ordinates.
I have this so far
Ellipse (a, b)(c, d) = scaled(solidCircle(1) (???)
Circle (a, b)(c, d) = (solidCircle (r))
where xc = ((c-a)*(c-a))
yc = ((d-b)*(d-b))
r = sqrt(xc +yc)
I included the circle equation as I'm using scaled circle.
Thank you!

Finding the intersection of the Circle and Infinite Cylinder in 3D space

Finding the intersection of the Circle and Infinite Cylinder. (all in 3D)
• Circle is defined by center, plane in which it lies and radius.
• Cylinder is defined by axis and radius.
how can i get the intersection of these two?
WLOG the cylinder has equation X² + Y² = 1 (if not, you can make it so by translation, rotation and scaling).
Then the parametric equation of the circle is
P = C + U cos t + V sin t
where C is the center point and U, V two orthogonal vectors in the circle plane, of length R.
You can rationalize with the substitution cos t = (1 - u²) / (1 + u²), sin t = 2u / (1 + u²).
Combining these equations,
(Cx (1 + u²) + Ux (1 - u²) + Vx 2u)² + (Cy (1 + u²) + Uy (1 - u²) + Vy 2u)² = (1 + u²)²
which is a quartic one. There is no particular simplification of the coefficients.
You can solve numerically or by the closed-form formulas. There can be up to four solutions.
I guess that this is strictly equivalent to finding the intersections between the torus formed by inflating the circle circumference and the straight line obtained by deflating the cylinder to its axis. This is well addressed in the ray-tracing literature.
You can also sse it as a circle/ellipse intersection problem in 2D.
Let's some base point of cylinder is A0, unit axis direction vector is AD, radius AR. Circle center is B0, circle plane unit normal is BN, radius BR.
Circle intersects cylinder, if distance from B0 to cyl. axis is smaller than sum of cylinder radius plus projection of circle radius onto normal to axis
Dist <= AR + BR * Abs(Cos(AD, BN)).
Cos(AD, BN) = DotProduct(AD, BN)
Distance(B0, cyl.axis) = Abs(VectorProduct(AD, B0-A0))

Tessellating hexagons over a rectangle

I have an infinite grid of hexagons, defined by a cubic (x y z) coordinate system like so:
I also have a viewport -- a rectangular canvas where I will draw the hexagons.
My issue is this. Because the grid of hexagons is infinite in all directions, I can't feasibly draw all of them at once. Therefore, I need to draw all the hexagons that are in the viewport, and ONLY those hexagons.
This image summarizes what I want to do:
In this image, purple-colored hexagons are those I want to render, while white-colored hexagons are those I don't want to render. The black rectangle is hte viewport -- all the hexagons that intersect with it are to be drawn. How would I find which hexagons to render (IE their xyz coordinates)?
Some other info:
I have a function that can recall a hexagon tile and draw it centered at position(x,y) in the viewport, given its cubic xyz coordinates. Therefore, all I should need is the xyz coords of each rectangle to draw, and I can draw them. This might simplify the problem.
I have formulas to convert from cubic hexagon coordinates to x/y coordinates, and back. Given the above diagram, r/g/b being the axes for the cubic coords with the image above, x and y being the cartesian coordinates, and s being the length of a hexagon's edge...
y = 3/2 * s * b
b = 2/3 * y / s
x = sqrt(3) * s * ( b/2 + r)
x = - sqrt(3) * s * ( b/2 + g )
r = (sqrt(3)/3 * x - y/3 ) / s
g = -(sqrt(3)/3 * x + y/3 ) / s
r + b + g = 0
Let's X0, Y0 are coordinates of top left corner, RectWidth is rectangle width, HexWidth = s * Sqrt(3/2) is hexagon width.
Find center of the closest hexagon r0, g0, b0, HX0, HY0. (Rect corner lies in this hexagon, because hexagons are Voronoy diagram cells). Remember horizontal and vertical shift DX = X0 - HX0, DY = Y0 - HY0
Draw horizontal row of Ceil(RectWidth/HexWidth) hexagons, incrementing r coordinate, decrementing f, and keeping b the same, ROWINC=(1,-1,0).
Note that if DY > HexWidth/2, you need extra top row with initial coordinates shifted up (r0, g0-1, b0+1)
Shift starting point by L=(0, 1, -1) if the DX < 0, or by R=(1, 0, -1) otherwise. Draw another horizontal row with the same ROWINC
Shift row starting point by alternative way (L after R, R after L). Draw horizontal rows until bottom edge is reached.
Check whether extra row is needed in the bottom.
You can think of the rectangular box in terms of constraints on an axis.
In the diagram, the horizontal lines correspond to b and your constraints will be of the form somenumber ≤ b and b ≤ somenumber. For example the rectangle might be in the range 3 ≤ b ≤ 7.
The vertical lines are a little trickier, but they are a “diagonal” that corresponds to r-g. Your constraints will be of the form somenumber ≤ r-g and r-g ≤ somenumber. For example it might be the range -4 ≤ r-g ≤ 5.
Now you have two axes with constraints on them, and you can form a loop. The easiest thing will be to have the outer loop use b:
for (b = 3; b ≤ 7; b++) {
…
}
The inner loop is a little trickier, because that's the diagonal constraint. Since we know r+g+b=0, and we know the value of b from the outer loop, we can rewrite the two-variable constraint on r-g. Express r+g+b=0 as g=0-r-b. Now substitute into r-g and get r-(0-r-b). Simplify r-(0-r-b) to 2*r-b. Instead of -4 ≤ r-g we can say -4 ≤ 2*r-b or -4+b ≤ 2*r or (-4+b)/2 ≤ r. Similarly, we can rearrange r-g ≤ 5 to 2*r-b ≤ 5 to r ≤ (5+b)/2. This gives us our inner loop:
for (b = 3; b ≤ 7; b++) {
for (r = (-4+b)/2; r ≤ (5+b)/2; r++) {
g = 0-b-r;
…
}
}
The last bit is to generalize, replacing the constants 3,7,-4,5 with the actual bounds for your rectangle.

Find a coordinate along a path

My trigonometry needs a little help.
How would I go about calculating the point of the nearest possible intersection with a line along a rounded corner?
Take this image:
What I would like to know is, given that I know point a, and the dimensions of the rectangle, how would I find point b when the edges of the rectangle are curved?
So far, as you can see, I've only managed to calculate the nearest edge of the rectangle as if it had right-angled corners.
If it matters, I'm doing this in ActionScript 3. But example sudo-code will suffice.
Calculate the vector from the midpoint M of the corner to A:
v_x = a_x - m_x
v_y = a_y - m_y
then go radius of the corner r times towards A to get to the intersection point I
i_x = m_x + r*v_x
i_y = m_y + r*v_y
This obviously only works if the nearest intersection is on the rounded corner. Just calculate the other intersections with the edges, too, and then check which has the nearest distance to A.
You need to know the radius R of the circle that generates the round corner and the coordinates (Xr,Yr) of the point where the two sides of a non rounded rectangle cross each other.
Then the coordinates for the center of the circle that generates the round corner are (Xc, Yc) = (Xr-R, Yr-R)
From here, it's a matter of solving the equation of the cross point between the segment line defined by point A=(Xa, Ya) and point (Xc, Yc), whose parametric equation is:
x = Xa + p*(Xc-Xa)
y = Ya + p*(Yc-Ya)
and the circle whose equation is
(x-Xc)^2 + (y-Yc)^2 = R^2
Substitute values for x and y from the parametric euation of the line in the equation of the circle, and you will have an equation with only one unkown: p. Solve the equation, and if there are more than one solution, choose the one that is in the range [0,1]. Substitute the found value of p in the parametric equation of the line to get the point of intersection.
Graphically:
If you know the radius and center of the corner as R and C=(Xc, Yc), then the nearest point on the corner to the given point A=(Xa, Ya) is the intersection point of the corner and the line defined by the given point and the center. This point can be directly expressed as
X = Xc + R*(Xa-Xc)/|AC|
Y = Yc + R*(Ya-Yc)/|AC|
where |AC| = Sqrt((Xa-Xc)^2 + (Ya-Yc)^2)

Resources