Building a Geometric figure with Mathematica.

Not too long ago I wrote here a small piece on creating beautiful figures, I was trying to explain a non trivial example on how to use METAPOST a system created by John D Hobby to build a geometric figure.

I was reading a blog post by Chris Carlson of Wolfram Research named “Always the Right Time for Mathematica” and decided to give Mathematica a try with the same problem in my prior blog post.

So here is the problem again in case you are too lazy to read my prior posting!

Build the following figure. (The lines in red are the altitudes of the triangle)


Well, here is the issue. Mathematica is a general purpose computer system but is not specifically design for graphics like METAFONT, still it should be very straight forward to build some figure like above.Fortunately Mathematica is very rich on Mathematics and this should make the solution easy. We can see multiple path of solution to the problem at hand.

Mathematica provide some native commands that allow one to draw lines and point in such and such Cartesian coordinates. So to draw the triangle ABC with Mathematica we can use the following command.








Where the Line[] Mathematica function draws the triangle and the Inset places the vertex labels in the figure.


The hard part is figuring out how to find the coordinates for the altitudes feet. If we can find a way to get those coordinates then our problem is solve.

Since we are trying to build the altitudes to the triangle. We need to search for properties the altitudes of a triangle satisfy that will facilitate this construction.

Geometrically we can characterize the altitudes of a triangle as the line segment from a vertex to the opposite side and this segment is perpendicular to that side.


Other property is: the altitude from a vertex is the minimal length segment we can build from the vertex to the opposite side.

And yet another property: One can build by reflection symmetry with respect to the side the vertex when reflected this way will produce another symmetrically opposite vertex and joining those two by a segment , half that segment will be the altitude.

You may find the proof to the above facts in some geometry book. If not you should try to proof them yourself.

We will discuss first the minimal path approach.

It seems that if we can build some function depending on one variable that give us any of the points between B and C then we shall be able to find the distance between any of those points and the point A. We should be able to repeat the same procedure for the other vertex.


Well it is good to know the linear Bezier curve equation.

B(t)=C+(B-C)t with t from [0,1]

Since B(t) gives us any point between B and C this shall come very handy in our computations.

Now all we need is to find the distance from B(x) to A and then that should give us a function depending on x. Finding the zeros of first derivative to this function we shall be able to find the values of x such that the distance from B(x) to A is minimal.

This can be performed using the following Mathematica code.





So all that remains for us is to draw the graph

BAB[t_,a_,b_]=(1-t) a+t b;















This solution is valid for A,B and C that form a non obtuse triangle. Can you see why?

I was still not completely satisfied with this solution. Because I wanted something that did not had to use calculus knowledge. So it is fortunate that Mathematica provide other functions like Nearest[], that allow to find from a list of points the closest point to a given point.

I can produce the list of points easily using the table

Something like


And this


Should get me a point sufficiently close to the base of the altitude. We repeat the same procedure for the others so the resulting code looks like this.

BAB[t_,a_,b_]=(1-t) a+t b;
















Yet one last solution this time using the symmetry of the vertex with respect to each of the side and finding the middle point.

BAB[t_,a_,b_]=(1-t) a+t b;













In this case we are using Cross[] to get the perpendicular vector to a given vector and ReflectionTransform[] will give us the corresponding transformation Matrix that performs the reflection symmetry that we need. This solution should be valid for any triangle define by the points A,B and C.

We can see from the 3 solutions above, that Mathematica is a very powerful system when it comes to mathematical computation and it is not difficult once one have the mathematical knowledge to use a system like Mathematica to come up with a solution to a given problem.

If you do have Mathematica and like to try your hands at this problem then try solving it this other way by finding the intersection of a line perpendicular to the given side that passes by the vertex opposite to the side. This should be fairly straight forward!

This is a blog posting from

About these ads


Filed under geometry, graphics, math, Mathematica, mathematics

2 responses to “Building a Geometric figure with Mathematica.

  1. Pingback: Producing animations with Mathematica 6.0 is as easy as pie « Is all about math Weblog

  2. Pingback: One easy problem and One not so easy problem. « Is all about math Weblog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s