POV-Ray : Newsgroups : povray.advanced-users : shortcut for inner circle : Re: shortcut for inner circle Server Time
29 Jul 2024 14:26:58 EDT (-0400)
  Re: shortcut for inner circle  
From: Tor Olav Kristensen
Date: 10 Dec 2001 20:23:58
Message: <3C155EF8.F46FDF6D@hotmail.com>
Tor Olav Kristensen wrote:
> 
> Tor Olav Kristensen wrote:
> >
> > "Wlodzimierz ABX Skiba" wrote:
> > >
> > > I found macro to calculate radius and center of inner circle of 2d triangle. Any
> > > idea for shorter version of it ? This works fine but I'm asking just for my
> > > knowledge extending :-) Some vector optimizations ?
> >
> > Yes Wlodzimierz, vector math would be my answer...    ;)
> >
> > Maybe what I wrote in this post will interest you:
> > news://news.povray.org/3B82F267.36412849%40hotmail.com
> > (My reply 1. Aug. 2001 to Mark M. Wilson's thread;
> > "general geometry question" )
> >
> > Here's some of my further comments:
> > news://news.povray.org/3B82FDB9.45E83FA%40hotmail.com
> >
> > And here's a link to the start of that thread:
> > http://news.povray.org/povray.general/17701
> 
> It seems like I misunderstood your problem.
> 
> But now I have made a new vector math macro that
> solves the correct problem.
> 
> I think I'll post it when I have had some sleep.

Sorry,  have not had time before now to post my code.

The CircleInscribedInTriangle() macro below seems
to do the trick.


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2001 by Tor Olav Kristensen
// Email: tor### [at] hotmailcom
// http://www.crosswinds.net/~tok
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.1;

#include "colors.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Main macro

#macro CircleInscribedInTriangle(pA, pB, pC, pCenter, Radius, vPlane)

  #local vAB = pB - pA;
  #local vBC = pC - pB;
  #local vCA = pA - pC;
  #local ab = vlength(vAB);
  #local bc = vlength(vBC);
  #local ca = vlength(vCA);
  #local vUp = vcross(vAB, vCA);
  #local S = vlength(vUp);
  #local abc = ab + bc + ca;

  #declare Radius = S/abc;
  #declare pCenter = pA + (ca*vAB - ab*vCA)/abc;
  #declare vPlane = vUp/S;

#end // macro CircleInscribedInTriangle

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Macros for visualizations

#macro vProject(v1, v2)

  (v2*vdot(v1, v2)/vdot(v2, v2))

#end // macro vProject


#macro pt2ln(pP, pL, vL) 

  (pL + vProject(pP - pL, vL))

#end // macro pt2ln


#macro OrientedTorus(Rmaj, Rmin, vAxis)

  #local vY = vnormalize(vAxis);

  torus {
    Rmaj, Rmin
    #if (abs(vY.y) != 1)
      #local vX = vcross(y, vY);
      #local vZ = vcross(vX, vY);
      matrix <
        vX.x, vX.y, vX.z,
        vY.x, vY.y, vY.z,
        vZ.x, vZ.y, vZ.z,
           0,    0,    0
      >
    #end // if
  }

#end // macro OrientedTorus

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Corners of triangle

#declare pA = <1, 8, 2>;
#declare pB = <-2, -3, 1>;
#declare pC = <-4, 5, -2>;

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Draw triangle

#declare sr = 0.02;

union {
  sphere { pA, sr*4 }
  sphere { pB, sr*4 }
  sphere { pC, sr*4 }
  pigment { color Red }
}

union {
  cylinder { pA, pB, sr }
  cylinder { pB, pC, sr }
  cylinder { pC, pA, sr }
  pigment { color White }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Calculate data for inscribed circle

#declare pCtr = <0, 0, 0>;
#declare Rad = 0;
#declare vPl = <0, 0, 0>; 
 
CircleInscribedInTriangle(pA, pB, pC, pCtr, Rad, vPl)

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Show circle and the points where it touches the triangle sides

union {
  OrientedTorus(Rad, sr, vPl)
  sphere { <0, 0, 0>, sr*3 }
  translate pCtr
  pigment { color White*2 }
}

union {
  sphere { pt2ln(pCtr, pA, pB - pA), sr*3 }
  sphere { pt2ln(pCtr, pB, pC - pB), sr*3 }
  sphere { pt2ln(pCtr, pC, pA - pC), sr*3 }
  pigment { color Cyan*2 }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// The photo gear

background { color Blue/2 }

light_source { 100*<-6, -1, 7> color White }

camera {
  location 15*vPl
  look_at <0, 0, 0>
  translate pCtr
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.