Jump to content
  • Advertisement
Sign in to follow this  

calculate Triangle Circumcircle And Inscribed_Circle/InCircle

This topic is 3632 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi... I want to calculate Triangle Circumcircle And Inscribed_Circle/InCircle in 3D space.... if anybody know C/java code please give me link of that code...remember in 3D space... please help me.. THanks..

Share this post

Link to post
Share on other sites
This is how it works in general:

Assuming a triangle consisting of three points A, B and C

- find the points halfway on AB and AC (AB being the segment between A and B, AC being the segment between A and C)
- create perpendicular lines on AB and AC in those points
- the intersection between those two lines is the centerpoint of the circumcircle
- the radius is the distance between the center point and any of the three points A, B and C

- create the bisecting line in two points, e.g. A and B
- the intersection of those lines is the center point of the incircle
- the radius is given by the distance between the centerpoint and any of the three triangle sides.

Here's some code (it's in C#, but it should be readable)


// lines from a to b and a to c
var AB = B - A;
var AC = C - A;

// perpendicular vector on triangle
var N = Vector3.Normalize(Vector3.Cross(AB, AC));

// find the points halfway on AB and AC
var halfAB = A + AB*0.5f;
var halfAC = A + AC*0.5f;

// build vectors perpendicular to ab and ac
var perpAB = Vector3.Cross(AB, N);
var perpAC = Vector3.Cross(AC, N);

// find intersection between the two lines
// D: halfAB + t*perpAB
// E: halfAC + s*perpAC
var center = LineLineIntersection(halfAB, perpAB, halfAC, perpAC);
// the radius is the distance between center and any point
// distance(A, B) = length(A-B)
var radius = Vector3.Distance(center, A);


// create bisecting lines in a and b
var AB = Vector3.Normalize(B - A);
var AC = Vector3.Normalize(C - A);
var bisectADir = AB + AC;

var BA = Vector3.Normalize(A - B);
var BC = Vector3.Normalize(C - B);
var bisectBDir =BA + BC;

// find intersection => center point of incircle
var center = LineLineIntersection(A, bisectADir, B, bisectBDir);
// find distance to any side => radius
var radius = PointLineDistance(center, A, B - A);

And the two helper methods LineLineIntersection and PointLineDistance:

/// <summary>
/// Calculates the intersection point between two lines, assuming that there is such a point.
/// </summary>
/// <param name="originD">The origin of the first line</param>
/// <param name="directionD">The direction of the first line.</param>
/// <param name="originE">The origin of the second line.</param>
/// <param name="directionE">The direction of the second line.</param>
/// <returns>The point at which the two lines intersect.</returns>
Vector3 LineLineIntersection(Vector3 originD, Vector3 directionD, Vector3 originE, Vector3 directionE) {
var N = Vector3.Cross(directionD, directionE);
var SR = originD - originE;
var absX = Math.Abs(N.X);
var absY = Math.Abs(N.Y);
var absZ = Math.Abs(N.Z);
float t;
if (absZ > absX && absZ > absY) {
t = (SR.X*directionE.Y - SR.Y*directionE.X)/N.Z;
} else if (absX > absY) {
t = (SR.Y*directionE.Z - SR.Z*directionE.Y)/N.X;
} else {
t = (SR.Z*directionE.X - SR.X*directionE.Z)/N.Y;
return originD - t*directionD;

/// <summary>
/// Calculates the distance between a point and a line.
/// </summary>
/// <param name="P">The point.</param>
/// <param name="S">The origin of the line.</param>
/// <param name="D">The direction of the line.</param>
/// <returns>
/// The distance of the point to the line.
/// </returns>
float PointLineDistance(Vector3 P, Vector3 S, Vector3 D) {
var SP = P - S;
return Vector3.Distance(SP, Vector3.Dot(SP, D)*D);

Vector3 is some 3D float vector implementation providing default vector operations such as addition, scaling, dot product and cross product.

Here's a screenshot of an app using the code above:

Free Image Hosting at www.ImageShack.us
thank u very much sir.....

its gr8.....


can u tell me about this....following routine doesn't use intersection but its for 2D...


// converts trilinear coordinates to Cartesian coordinates relative
// to the incenter; thus, the incenter has coordinates (0.0, 0.0)
public Coordinate toCartesian(double alpha, double beta, double gamma)
double area = getArea();
double as = getSideA(), bs = getSideB(), cs = getSideC();
double r = 2 * area / (as + bs + cs);
double k = 2 * area / (as*alpha + bs*beta + cs*gamma);
double cosC = Math.cos(getAngleC()), sinC = Math.sin(getAngleC());

//Look At here..
//this routine is very very simple...but here how can we find Z coordinate...here we only need a one formula for determine the Z coordinate...can we fine Z??????


double x = (k*beta - r + (k*alpha - r)*cosC) / sinC;
double y = k*alpha - r;

double z = ???????????????????????????????????????????


return new Coordinate(x, y);

// calculates the circumradius
public Circle getCircumcircle()
double cosA = Math.cos(getAngleA());
double cosB = Math.cos(getAngleB());
double cosC = Math.cos(getAngleC());
Coordinate center = toCartesian(cosA, cosB, cosC);
double as = getSideA(), bs = getSideB(), cs = getSideC();
double s = 0.5 * (as + bs + cs);
double radius = (as * bs * cs) / (4 * Math.sqrt(
s * (as + bs - s) * (as + cs - s) * (bs + cs - s)));
return new Circle(center, radius);

// calculates the inradius
public Circle getIncircle()
Coordinate center = toCartesian(1.0, 1.0, 1.0);
double as = getSideA(), bs = getSideB(), cs = getSideC();
double semiperimeter = 0.5 * (as + bs + cs);
double radius = getArea() / semiperimeter;
return new Circle(center, radius);



Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!