How I find the total area of a triangle from the areas of three sections out of six created by concurrent lines one from each vertex? - math

In this triange:
Given the areas of triangles UPZ ZPW and WPY, how do you calculate the total area?
I've already found the solution from the available submissions at the website. But I want to know how to derive that solution.
cin >> a >> b >> c;
// a is UPZ, b is ZPW, c is WPY
double n = b*(a+b)*(a+b+c);
double d = b*(a+b)-(a*c);
cout << (n / d) ;

Indeed, this question is kind of off topic, it is a geometry problem. The way to find the area of the big triangle UVW is to apply the link between areas and ratioes of lengths of the segments of the triangle UYW and then to apply Menelaus' theorem to derive the ratio
WY/WV which reveals the ratio between the areas of the triangle UYW and UVW.
Let h_p be the length of the height from point P to the edge UW. Then
a = UZ * h_p / 2 and b = ZW * h_p / 2
Thus:
a / b = (UZ * h_p / 2) / (ZW * h_p / 2) = UZ / ZW
Let h_W be the length of the height from point W to the line UY
a + b = Area(WPU) = PU * h_W / 2 and c = YP * h_w / 2
Thus:
c / (a + b) = (YP * h_W / 2) / (PU * h_W / 2) = YP / PU
By Menelaus' theorem for the triangle UWY and the line VZ, with P on VZ, we get:
1 = ( VW / VY ) * ( YP / PU ) * ( UZ / ZW ) = ( VW / WY ) * (c / (a + b)) * (a / b)
so
VY / VW = (c * a) / ( b * (a + b))
and therefore:
WY / VW = 1 - (VY / VW) = 1 - (c*a) / ( b*(a + b)) = (a*b + b^2 - a*c ) / (a*b + b^2)
Let h_U be the length of the height from the point U to the edge VW. Then
Area(UVW) = VW * h_U / 2
and
Area(UYW) = a + b + c = WY * h_U / 2
Hence
Area(UVW) / Area(UYW) = Area(UVW) / (a + b + c) = (VW * h_U / 2) / (WY * h_U / 2) = VW / WY
so
Area(UVW) / Area(UYW) = VW / WY = (a*b + b^2) / (a*b + b^2 - a*c)
Area(UVW) / Area(UYW) = Area(UVW) / (a + b + c) = (a*b + b^2) / (a*b + b^2 - a*c)
Finally, we obtain the formula:
Area(UVW) = (a + b + c) * (a*b + b^2) / (a*b + b^2 - a*c)
Area(UVW) = b * (a + b) * (a + b + c) / (b*(a + b) - a*c)

Related

plotting Hamid Naderi Yeganehs parrot using ggplot

I am a) new to stackoverflow and b) an advanced beginner to R ;-)
i saw some bird artworks of Yeganeh with the associated functions in the web Drawing Birds in Flight With Mathematics and wanted to reproduce them in R to experiment a bit with colouring and so on.
However, while this one yielded a quite good result:
k <- 1:9830
X <- function(k) {
sin(pi * k / 20000) ^ 12 *
(0.5 * cos(31 * pi * k / 10000) ^ 16 *
sin(6 * pi * k / 10000) + (1 / 6 * sin(31 * pi * k / 10000)) ^ 20) +
3 * k / 20000 + cos(31 * pi * k / 10000) ^ 6 *
sin((pi / 2) * ((k - 10000) / 10000) ^ 7 - pi / 5)
}
Y <- function(k) {
-9 / 4 * cos(31 * pi * k / 10000) ^ 6 *
cos(pi / 2 * ((k - 10000) / 10000) ^ 7 - pi / 5) *
(2 / 3 + (sin(pi * k / 20000) * sin(3 * pi * k / 20000)) ^ 6) +
3 / 4 * cos(3 * pi * ((k - 10000) / 100000)) ^ 10 *
cos(9 * pi * ((k - 10000) / 100000)) ^ 10 *
cos(36 * pi * ((k - 10000) / 100000)) ^ 14 +
7 / 10 * ((k - 10000) / 10000) ^ 2
}
R <- function(k) {
sin(pi * k / 20000) ^ 10 *
(1 / 4 * cos(31 * pi * k / 10000 + 25 * pi / 32) ^ 20 +
1 / 20 * cos(31 * pi * k / 10000) ^ 2) +
1 / 30 * (3 / 2 - cos(62 * pi * k / 10000) ^ 2)
}
bird <- data.frame(x = X(k), y = Y(k), r = R(k))
library(tidyverse)
library(ggforce)
q <- ggplot() +
geom_circle(aes(x0 = x, y0 = y, r = r),
data = bird,
n = 30) +
coord_fixed() +
theme_void()
the following code yielded some weird result which should basically be related to the difference in the function. (x-A(k))+(y-B(k))=(R(k)) for the parrot below, whlie the bird above "simply" consisted of the k-th circle (X(k), Y(k)) and the radius of the k-th circle R(k)
k <- -10000:10000
A <- function(k) {
(3*k/20000)+(cos(37*pi*k/10000))*sin((k/10000)*(3*pi/5))+(9/7)*(cos(37*pi*k/10000))*(cos(pi*k/20000))*sin(pi*k/10000)
}
B <- function(k) {
(-5/4)*(cos(37*pi*k/10000))*cos((k/10000)*(3*pi/5))*(1+3*(cos(pi*k/20000)*cos(3*pi*k/20000)))+(2/3)*(cos(3*pi*k/200000)*cos(9*pi*k/200000)*cos(9*pi*k/100000))
}
R <- function(k) {
(1/32)+(1/15)*(sin(37*pi*k/10000))*((sin(pi*k/10000))+(3/2)*(cos(pi*k/20000)))
}
parrot <- data.frame(a = A(k), b = B(k), r = R(k))
q <- ggplot() +
geom_circle(aes(x0 = a, y0 = b, r = r),
data = parrot,
n=30) +
coord_fixed() +
theme_void()
q
Any help would be very much appreciated. Cartesian coords already applied as [explained here] (https://www.wikiwand.com/en/Hamid_Naderi_Yeganeh). From the visual point of view, it seems like the function is plotted properly but the "view" on it needs to be changed...
Thanks in advance!

Find maximum angle of box in slot

How would I find the maximum possible angle (a) which a rectangle of width (W) can be at within a slot of width (w) and depth (h) - see my crude drawing below
Considering w = hh + WW at the picture:
we can write equation
h * tan(a) + W / cos(a) = w
Then, using formulas for half-angles and t = tan(a/2) substitution
h * 2 * t / (1 - t^2) + W * (1 + t^2) / (1 - t^2) = w
h * 2 * t + W * (1 + t^2) = (1 - t^2) * w
t^2 * (W + w) + t * (2*h) + (W - w) = 0
We have quadratic equation, solve it for unknown t, then get critical angle as
a = 2 * atan(t)
Quick check: Python example for picture above gives correct angle value 18.3 degrees
import math
h = 2
W = 4.12
w = 5
t = (math.sqrt(h*h-W*W+w*w) - h) / (W + w)
a = math.degrees(2 * math.atan(t))
print(a)
Just to elaborate on the above answer as it is not necessarly obvious, this is why why you can write equation:
h * tan(a) + W / cos(a) = w
PS: I suppose that the justification for "why a is the maximum angle" is obvious

Mutual Information in a Binary Erasure Channel

Imagine a Binary Erasure Channel as depicted on Wikipedia.
One equation describing the mutual information is following:
I(x;y)
= H(x) - H(x|y)
= H(x) - p(y=0) • 0 - p(y=?) • H(x) -p(y=1) • 0
Why is it "p(y=?) • H(x)" and not "p(y=?) • H(x|y=?)"?
It can be proved using Bayes' theorem.
The channel:
x y
1-f
0 --------> 0
\
\ f
+------> ?
/
/ 1-f
1---------> 1
Let input distribution be P(x) = {p(x=0)=g; p(x=1)=1-g}
Then:
p(x=0/y=?) = p(y=?/x=0) * p(x=0) / p(y=?)
p(x=0/y=?) = (f * g) / (f * g - f * (1 - g)) = g;
p(x=1/y=?) = p(y=?/x=1) * p(x=1) / p(y=?)
p(x=1/y=?) = (f * (1 - g)) / (f * g - f * (1 - g)) = 1 - g;
As result:
p(x=0/y=?) = p(x=0)
p(x=1/y=?) = p(x=1)
From the defenitions of entropy and conditional entropy:
H(X) = p(x=0) * log(1 / p(x=0)) + p(x=1) * log(1 / p(x=1))
H(X/y=?) = p(x=0/y=?) * log(1 / p(x=0/y=?)) + p(x=1/y=?) * log(1 / p(x=1/y=?))
So:
H(X) = H(X/y=?)

Find the third point

I have 2 points P1 and P2. I need to find the P3, in order that
all points to be on the same line;
P3 should be at the distance d from the P2 (away from P1)
I started a complicated system apparently hardly to resolve...
PS.
Vectorial answers is cool, but I use C# and don't know how to add vectors over there.
P3 = P2 + d * ±(P2 - P1) / |P2 - P1|
EDIT:
Because shopping is easy:
mag = sqrt((P2x - P1x) ** 2 + (P2y - P1y) ** 2)
P3x = P2x + d * (P2x - P1x) / mag
P3y = P2y + d * (P2y - P1y) / mag
I have translated the code to Objective C
float distanceFromPx2toP3 = 1300.0;
float mag = sqrt(pow((px2.x - px1.x),2) + pow((px2.y - px1.y),2));
float P3x = px2.x + distanceFromPx2toP3 * (px2.x - px1.x) / mag;
float P3y = px2.y + distanceFromPx2toP3 * (px2.y - px1.y) / mag;
CGPoint P3 = CGPointMake(P3x, P3y);

Solving a cubic to find nearest point on a curve to a point

Ok,
I have a projectile that has its position defined such that:
a.x = initialX + initialDX * time;
a.y = initialY + initialDY * time + 0.5 * gravtiy * time^2;
I want to be able to predict which obstacles in my environment this projectile will collide with. I plan on checking the distance from A the closest point on the curve to the point P.
I figure that at the point A the tangent to the curve will be perpendicular to the vector AP, and that the tangent to the curve at A will simply be the velocity V of the projectile at that point.
AP dot V = 0
ap.x = initialX + initialDX * time - p.x;
ap.y = initialY + initialDY * time + gravity * time^2 - p.y;
v.x = initialDX;
v.y = initialDY + gravity * time;
=>
AP dot V =
( 0.5 * gravity^2 ) * t^3 +
( 1.5 * gravity * initialDY ) * t^2 +
( initialDX^2 + initialDY^2 + gravity * ( initialY - p.y ) ) * t +
( initialDX * ( initialX - p.x ) + initialDY * ( initialY - p.y ) )
From here I can see that this is a cubic function. I have spent some time researching online and found that there is a general equation that seems to work for certain values for finding the roots.
This is the process I have attempted to implement.
http://www.sosmath.com/algebra/factor/fac11/fac11.html
a = 0.5 * gravity^2;
b = 1.5 * gravity * initialDY;
c = initialDX^2 + initialDY^2 + gravity * ( initialY - p.y );
d = initialDX * ( initialX - p.x ) + initialDY * ( initialY - p.y );
A = ( c - ( b * b ) / ( 3 * a ) ) / a;
B = -( d + ( 2 * b * b * b ) / ( 27 * a * a ) - ( b * c ) / ( 3 * a ) ) / a;
workingC = -Math.pow( A, 3 ) / 27;
u = ( -B + Math.sqrt( B * B - 4 * workingC ) ) / 2; // Quadratic formula
s = Math.pow( u + B, 1 / 3 );
t = Math.pow( u, 1 / 3 );
y = s - t;
x = y - b / ( 3 * a );
When I plug x back into my original equations for the curve as the time, this should give me A. This seems to work well for certain values, however when p.y is above a certain value, I don't have a positive to take a square root of in the quadratic equation.
I don't have a full enough understanding of the math to understand why this is happening, or what I can do to resolve the issue.
Any help on this would be much appreciated.
UPDATE:
I have adjusted my algorithm to deal with complex roots, however I am still having trouble.
This is what I do now if the discriminant is negative:
a = 0.5 * gravity^2;
b = 1.5 * gravity * initialDY;
c = initialDX^2 + initialDY^2 + gravity * ( initialY - p.y );
d = initialDX * ( initialX - p.x ) + initialDY * ( initialY - p.y );
A = ( c - ( b * b ) / ( 3 * a ) ) / a;
B = -( d + ( 2 * b * b * b ) / ( 27 * a * a ) - ( b * c ) / ( 3 * a ) ) / a;
workingC = -Math.pow( A, 3 ) / 27;
discriminant = B * B - 4 * workingC;
then if discriminant < 0;
uc = new ComplexNumber( -B / 2, Math.sqrt( -discriminant ) / 2 );
tc = uc.cubeRoot( );
uc.a += B;
sc = uc.cubeRoot( );
yc = sc - tc;
yc.a -= b / ( 3 * a );
x = -d / ( yc.a * yc.a + yc.b * yc.b );
For some reason, this is still not giving me the results I expect. Is there anything that stands out as being wrong here?
Real polynomials can have complex number roots and if the roots are not real, they occur in conjugate pairs.
This implies cubics always have at least one real root.
Now if you get a complex root using your method, you can try to get the conjugate, mutiply and divide the constant of the cubic, take reciprocal to get the real root.
So if you had to take the square root of a -ve number, then it is same as multiplying the square root of its modulus by the imaginary number 'i'.
So if you represent your root as (m,n) denoting the complex number m + in. Then the other root is m - in = (m, -n) and m and n are real numbers.
The cubic can then be written as P(x) = (x^2 - 2m + (m^2 + n^2))(x-r).
So if P(x) = x^3 - a_1 *x^2 + a_2*x - a_3, then we have that r = a_3/(m^2 + n^2) (a_3 is the product of the roots, which is r(m^2+n^2))
A simpler way to get r would be to use the formula r = a_1 - 2m (a_1 is the sum of the roots, which is r+2m).
Check out: http://en.wikipedia.org/wiki/Complex_number

Resources