Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to to inscribe a circle in a given triangle but it isn't working. I've used GeoGebra with this construction and worked but as I'm new to Mathematica I am missing something. It can't be so complex to do. Here is my code:

pA = {0, 0}; pB = {1.1, 1}; pC = {1.5, 0};

midAB = (pA + pB)/2; midBC = (pB + pC)/2; midAC = (pA + pC)/2;

myT = Triangle[{pA, pB, pC}];

centerC = (midAB + midBC + midAC)/3

raioC = Last[centerC]

Graphics[{EdgeForm[Directive[Thick, Blue]], White, 
  myT, {PointSize[Large], Red, Point[midBC]}, {PointSize[Large], Red, 
   Point[pA]},
  {Orange, Line[{pA, midBC}]},
  {Orange, Line[{pB, midAC}]},
  {Orange, Line[{pC, midAB}]},
  {Red, Circle[centerC, Last[centerC]]},
  }, AspectRatio -> Automatic, PlotRange -> All]

I understand that I'm not doing right the radius of the circle but I've tried more than one way to do that.

Here is the original (book) construction:

To construct: The circle inscribed in ^ABC

Construction: Construct the bisectors of two of the angles of ^ABC. Their intersection is the center of the required circle, and the distance (perpendicular) to any side is the radius. (Any point on the bisector of an angle is equidistant from the sides of the angle.)

As I said, it worked in GeoGebra and it is almost working with my code. Thank you for any help.

share|improve this question
    
Thank you all for the help, all the answers are fine. –  Luiz Roberto Meier Aug 21 at 2:06

4 Answers 4

up vote 8 down vote accepted

As KennyColnago has observed your equations seem to be off but there is another way of determining the incircle. I'd already typed it up with sources that may be helpful so let's post it, even if it's the same thing.

{a, b, c} = {Norm[pC - pB], Norm[pA - pC], Norm[pA - pB]};
area = With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]];
r = 2 area/(a + b + c);
incenter = (a pA + b pB + c pC)/(a + b + c);

Graphics[{
  EdgeForm[Black], White, Triangle[{pA, pB, pC}],
  Black, Point[incenter],
  Circle[incenter, r]
  }]

Incircle

The formula for the coordinates of the incenter can be found here, the relationship between the radius and the area is discussed here and the area is calculated with Heron's formula found here.

It's also worth noting that we can "cheat" with Mathematica 10:

incenter = {a, b, c}.{pA, pB, pC}/ArcLength[Line[{pA, pB, pC, pA}]];
r = 2 Area[Triangle[{pA, pB, pC}]]/ArcLength[Line[{pA, pB, pC, pA}]];

Although this sort of cheating is not as outrageous as that by Junho Lee of course ;)

share|improve this answer

version 10

pA = {0, 0}; pB = {1.1, 1}; pC = {1.5, 0};
lr = MeshRegion[{pA, pB, pC}, Triangle[Range@3]];
r1 = RegionDistance[InfiniteLine[{pA, pB}], {x, y}];
r2 = RegionDistance[InfiniteLine[{pB, pC}], {x, y}];
r3 = RegionDistance[InfiniteLine[{pC, pA}], {x, y}];
centerC = {x, y} /. NSolve[{r1 == r2, r2 == r3}, {x, y}, Reals];
centerC = Select[centerC, RegionMember[lr, #] &][[1]]
raioC = RegionDistance[Line[{pA, pB}], centerC]
Graphics[{
  EdgeForm[{Thick, Blue}], White, Triangle[{pA, pB, pC}],
  PointSize[Large], Red, Point@centerC,
  Red, Circle[centerC, raioC]}
 ]

{0.954787, 0.369127}

0.369127

enter image description here

share|improve this answer
    
Nice V10 demonstration of a new functionality +1. –  PlatoManiac Aug 21 at 7:44

The incircle of a triangle may be calculated as follows.

InCircle[{x1_, y1_}, {x2_, y2_}, {x3_, y3_}] := 
   With[{
      a = Norm[{x2,y2} - {x3,y3}], 
      b = Norm[{x3,y3} - {x1,y1}], 
      c = Norm[{x1,y1} - {x2,y2}]}, 
   Circle[(a {x1, y1} + b {x2, y2} + c {x3, y3})/(a + b + c), 
          1/2 Sqrt[-(((a - b - c) (a + b - c) (a - b + c))/(a + b + c))]]]

For your example points, InCircle[{0,0},{1.1,1},{1.5,0}] produces Circle[{0.954787, 0.369127}, 0.369127], which may be plotted with

Graphics[{
   Line[{{0, 0}, {1.1, 1}, {1.5, 0}, {0, 0}}],
   Red, Thick, InCircle[{0, 0}, {1.1, 1}, {1.5, 0}]}]

Mathematica graphics

share|improve this answer
inCircle[p_] := 
  Circle[{x, y}, Abs@r] /. 
   Solve[((# - #2).{y, -x} - Det@{##})/Norm[# - #2] & @@@ 
      Subsets[p, {2}] == r {1, -1, 1}];

Manipulate[
 Graphics[{Line@p[[{1, 2, 3, 1}]], Red, inCircle@p}, PlotRange -> 6, 
  Frame -> 1], {{p, {{-2, -1}, {3, -2}, {0, 3}}}, Locator}]

Another inCircle:

inCircle[pt : {v1_, v2_, v3_}] :=
 Block[{a, b, c, p},
  {a, b, c} = Norm /@ {v2 - v3, v3 - v1, v1 - v2};
  p = (a + b + c)/2;
  Circle[{a, b, c}.pt/(2 p),  Sqrt[p (p - a) (p - b) (p - c)]/p]]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.