1 | initial version |
Your approach will not work since you try to play with plots. Instead, you have to play with vectors, not their plots.
To my understanding of the picture, D
is the orthogonal projection of A
to the line (B,C)
.
If v1
denotes the vector BA
and v2
denotes the vector BC
, the length j
is the inner product of v1
by v2
divided by the norm of v2
. Here is how to do it in Sage:
sage: A = (9, 5); B = (2, 4); C = (16, -2); sage: v1 = vector(A)-vector(B) sage: v2 = vector(C)-vector(B) sage: v1.inner_product(v2)/v2.norm() 23/29*sqrt(58)
If you want a floating approximation, you can do:
sage: RDF(v1.inner_product(v2)/v2.norm()) 6.040095911547238
2 | No.2 Revision |
Your approach will not work since you try to play with plots. Instead, you have to play with vectors, not their plots.
To my understanding of the picture, D
is the orthogonal projection of A
to the line (B,C)
.
If v1
denotes the vector BA
and v2
denotes the vector BC
, the length j
is the inner product of v1
by v2
divided by the norm of v2
. Here is how to do it in Sage:
sage: A = (9, 5); B = (2, 4); C = (16, -2);
sage: v1 = vector(A)-vector(B)
sage: v2 = vector(C)-vector(B)
sage: v1.inner_product(v2)/v2.norm()
If you want a floating approximation, you can do:
sage: RDF(v1.inner_product(v2)/v2.norm())
3 | No.3 Revision |
Your approach will not work since you try to play with plots. Instead, you have to play with vectors, not their plots.
To my understanding of the picture, D
is the orthogonal projection of A
to the line (B,C)
.
If v1
denotes the vector BA
and v2
denotes the vector BC
, the length j
is the inner product of v1
by v2
divided by the norm of v2
. Here is how to do it in Sage:
sage: A = (9, 5); B = (2, 4); C = (16, -2);
sage: v1 = vector(A)-vector(B)
sage: v2 = vector(C)-vector(B)
sage: v1.inner_product(v2)/v2.norm()
23/29*sqrt(58)
If you want a floating approximation, you can do:
sage: RDF(v1.inner_product(v2)/v2.norm())
6.040095911547238
*EDIT : * When you write
sage: plot(x,(x,2,5),color='red')
You ask Sage to plot the function x
(i.e. the identity function), for x
varying from 2
to 5
.
To compute the coordinates of D
, you can do:
sage: BA = -AB
sage: D = vector(B) + BC*BA.inner_product(BC)/BC.norm()/BC.norm()
sage: D
(219/29, 47/29)
To add the point D
on the picture, you can do:
sage: P += point(D)
If you want the x-axis and the y-axis to have the same scale (so that the right angles are visible), you can do:
sage: P.set_aspect_ratio(1)
4 | No.4 Revision |
Your approach will not work since you try to play with plots. Instead, you have to play with vectors, not their plots.
To my understanding of the picture, D
is the orthogonal projection of A
to the line (B,C)
.
If v1
denotes the vector BA
and v2
denotes the vector BC
, the length j
is the inner product of v1
by v2
divided by the norm of v2
. Here is how to do it in Sage:
sage: A = (9, 5); B = (2, 4); C = (16, -2);
sage: v1 = vector(A)-vector(B)
sage: v2 = vector(C)-vector(B)
sage: v1.inner_product(v2)/v2.norm()
23/29*sqrt(58)
If you want a floating approximation, you can do:
sage: RDF(v1.inner_product(v2)/v2.norm())
6.040095911547238
*EDIT : *EDIT : When you write
sage: plot(x,(x,2,5),color='red')
You ask Sage to plot the function x
(i.e. the identity function), for x
varying from 2
to 5
.
To compute the coordinates of D
, you can do:
sage: BA = -AB
sage: D = vector(B) + BC*BA.inner_product(BC)/BC.norm()/BC.norm()
sage: D
(219/29, 47/29)
To add the point D
on the picture, you can do:
sage: P += point(D)
If you want the x-axis and the y-axis to have the same scale (so that the right angles are visible), you can do:
sage: P.set_aspect_ratio(1)