|
 |
On 01/05/2022 22:23, Tor Olav Kristensen wrote:
>
> Here's some code for you to experiment with:
> ...
>
Thanks Tor.
*I will look at your code*
on my side, I made (not the easiest way) :
// ---------------------------------------------------------------------
// https://en.wikipedia.org/wiki/Plane_(geometry)
// ---------------------------------------------------------------------
#macro plane_equation(p1, p2, p3)
#local a1 = p2.x - p1.x;
#local b1 = p2.y - p1.y;
#local c1 = p2.z - p1.z;
#local a2 = p3.x - p1.x;
#local b2 = p3.y - p1.y;
#local c2 = p3.z - p1.z;
#local a = b1 * c2 - b2 * c1;
#local b = a2 * c1 - a1 * c2;
#local c = a1 * b2 - b1 * a2;
#local d = (-a*p1.x -b*p1.y - c*p1.z);
#declare equation = concat(str(a,0,2),"x ");
#if(b<0)
#declare equation = concat(equation,"- ");
#else
#declare equation = concat(equation,"+ ");
#end
#declare equation = concat(equation, str(abs(b),0,2),"y ");
#if(c<0)
#declare equation = concat(equation,"- ");
#else
#declare equation = concat(equation,"+ ");
#end
#declare equation = concat(equation,str(abs(c),0,2),"z ");
#if(d<0)
#declare equation = concat(equation,"- ");
#else
#declare equation = concat(equation," +");
#end
#declare equation = concat(equation,str(abs(d),0,2)," = 0");
#debug concat("Plane equation :\n ",equation,"\n\n")
#local result = array[4]{a,b,c,d};
result
#end
// ---------------------------------------------------------------------
// --- 3 POINTS --------------------------------------------------------
// ---------------------------------------------------------------------
#declare ptA = <1,1,0>;
#declare ptB = <0,1,1>;
#declare ptC = <1,0,1>;
#declare POINTS =union {
sphere { ptA, 0.10 pigment { color Red } }
sphere { ptB, 0.10 pigment { color Green } }
sphere { ptC, 0.10 pigment { color Blue } }
union {
cylinder { ptA, ptB, 0.025 }
cylinder { ptB, ptC, 0.025 }
cylinder { ptC, ptA, 0.025 }
pigment { color White*0.80 }
finish { brilliance 2 specular 0.20 }
}
}
object { POINTS }
#declare planCoef = plane_equation(ptA, ptB, ptC);
#declare a = planCoef[0];
#declare b = planCoef[1];
#declare c = planCoef[2];
#declare d = planCoef[3];
plane {
<a, b, c>, ? <- several tests here :(
pigment { color Magenta transmit 0.80 }
}
// ---------------------------------------------------------------------
// Just to check the distance between the plane and the points...
// https://mathworld.wolfram.com/Point-PlaneDistance.html
// ---------------------------------------------------------------------
#declare D = sqrt(a*a+b*b+c*c);
#declare Dist = abs(a*ptA.x + b*ptA.y + c*ptA.z + d)/D;
#debug concat("A Point-Plane = ",str(Dist,0,4),"\n")
#declare Dist = abs(a*ptB.x + b*ptB.y + c*ptB.z + d)/D;
#debug concat("B Point-Plane = ",str(Dist,0,4),"\n")
#declare Dist = abs(a*ptC.x + b*ptC.y + c*ptC.z + d)/D;
#debug concat("C Point-Plane = ",str(Dist,0,4),"\n\n")
// all Dist values are egal to zero.
--
Kurtz le pirate
Compagnie de la Banquise
Post a reply to this message
|
 |