|
![](/i/fill.gif) |
Ben Chambers wrote:
...
> I also have three points on a plane (lets call them
> p1,p2,p3). I'd like to have this flattened sphere
> oriented on the plane... Maybe I'm just braindead
> tonight, but the reorient macro didn't do it for
> me...
...
Hello Ben
See my suggestion code below.
I hope it does what you want.
Best regards
from Tor Olav
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2001 by Tor Olav Kristensen
// mailto:tor### [at] hotmail com
// 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 =
// Define a macro that does the same as
// John VanSickle's Reorient macro.
// (But with a slightly different method.)
#macro ReorientMatrix(vAxis1, vAxis2)
#local v1 = vnormalize(vAxis1);
#local v2 = vnormalize(vAxis2);
#local vU = vcross(v1, v2);
#local Dot = vdot(v1, v2);
#local v0 = vnormalize(vU);
#local vW = (1 - Dot)*v0;
matrix <
v0.x*vW.x + Dot, v0.x*vW.y + vU.z, v0.x*vW.z - vU.y,
v0.y*vW.x - vU.z, v0.y*vW.y + Dot, v0.y*vW.z + vU.x,
v0.z*vW.x + vU.y, v0.z*vW.y - vU.x, v0.z*vW.z + Dot,
0, 0, 0
>
#end // macro ReorientMatrix
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
// Define 3 points that lies on the plane
#declare p1 = <1, 2, 3>;
#declare p2 = <2, -1, -1>;
#declare p3 = <-1, 0, 1>;
// Show the 3 points
sphere { p1, 0.2 pigment { color Red } }
sphere { p2, 0.2 pigment { color Green } }
sphere { p3, 0.2 pigment { color Blue } }
// Calculate a normal vector for the plane
#declare vNormal = vnormalize(vcross(p2 - p1, p3 - p1));
// Calculate the common transformations
#declare TiltAndTranslate =
transform {
ReorientMatrix(y, vNormal)
translate (p1 + p2 + p3)/3
// See note 1 below for other translate statements
// that can replace the line above.
}
// Then define your other stuff
#declare YourPlane =
plane {
y, 0
pigment { color Grey }
// See note 2 below
}
#declare YourSphere =
sphere {
<0, 0, 0>, 1
scale <5, 1, 5>
// scale 1/4 // Uncomment if you want to see all the 3 points
pigment { color Yellow }
}
// And transform it into place
object {
YourPlane
transform TiltAndTranslate
}
object {
YourSphere
transform TiltAndTranslate
}
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
light_source { <-2, 20, -1>*5 color White }
camera {
location <1, 3, 2>*3
look_at <0, -1, 0>
}
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
/*
Note 1:
Here are some alternate translate
statements that also will work:
translate vdot(p1, vNormal)*vNormal
translate vdot(p2, vNormal)*vNormal
translate vdot(p3, vNormal)*vNormal
translate p1
translate p2
translate p3
translate (p1 + p2)/2
translate (p1 + p3)/2
translate (p2 + p3)/2
translate (p1 + p2 + p3)/3
...and so on...
Note 2:
It's sometimes easier to work with
a disk instead of a plane. E.g.:
disc {
<0, 0, 0>, y, 10
transform TiltAndTranslate
pigment { color Grey }
}
*/
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
Post a reply to this message
|
![](/i/fill.gif) |