|
|
- with POV-Ray macros.
The macro Cross(x1,y1,x2,y2,x3,y3,x4,y4), in this thread:
news://news.povray.org/jbk11ugit4l7hie7346ckncgdf76sog405%404ax.com
http://news.povray.org/povray.advanced-users/20568/
Subject: shortcut for inner circle
Date: Fri, 07 Dec 2001 15:40:26 +0100
Newsgroups: povray.advanced-users
- made me think of some vector macros I made earlier.
I have tried to write some comments on how to use them.
(And I have also provided some simple examples.)
Note that this is a rather odd way to solve such a
system of equations, but it works.
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;
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Macros for solving system of 3 equations with 3 unknowns
#macro S3Prod(vA, vB, vC)
vdot(vA, vcross(vB, vC))
#end // macro S3Prod
#macro S3E3U(vA, vB, vC, vD)
(<S3Prod(vD, vB, vC),
S3Prod(vA, vD, vC),
S3Prod(vA, vB, vD)>/
S3Prod(vA, vB, vC))
#end // macro S3E3U
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Macros for solving system of 2 equations with 2 unknowns
#macro vCross2D(v0)
<v0.v, -v0.u>
#end // macro vCross2D
#macro S2Prod(vA, vB)
vdot(vA, vCross2D(vB))
#end // macro S2Prod
#macro S2E2U(vA, vB, vC)
(<S2Prod(vC, vB),
S2Prod(vA, vC)>/
S2Prod(vA, vB))
#end // macro S2E2U
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// A little test of the S3E3U() macro:
// 4*x +2*y -7*z = -6
// -1*x -8*y -3*z = -70
// 5*x +5*y -9*z = 30
#declare v1 = <4, -1, 5>;
#declare v2 = <2, -8, 5>;
#declare v3 = <-7, -3, -9>;
#declare v4 = <-6, -70, 9>;
#declare vS = S3E3U(v1, v2, v3, v4);
#debug "\n\n"
#debug concat ("x = ", str(vS.x, 0, -1))
#debug "\n"
#debug concat ("y = ", str(vS.y, 0, -1))
#debug "\n"
#debug concat ("z = ", str(vS.z, 0, -1))
#debug "\n\n"
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// A little test of the S2E2U() macro:
// 2*u -3*v = -20
// 1*u +7*v = 58
#declare v1 = <2, 1>;
#declare v2 = <-3, 7>;
#declare v3 = <-20, 58>;
#declare vT = S2E2U(v1, v2, v3);
#debug "\n\n"
#debug concat ("u = ", str(vT.u, 0, -1))
#debug "\n"
#debug concat ("v = ", str(vT.v, 0, -1))
#debug "\n\n"
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
/*
About the macro S3Prod()
Scalar Triple Product
If vA, vB and vC are 3D row vectors in a 3x3 matrix, then the result
of S3Prod(vA, vB, vC) is the determinand of that matrix.
vA = <a1, a2, a3>
vB = <b1, b2, b3>
vC = <c1, c2, c3>
| a1 a2 a3 |
| b1 b2 b3 | = S3Prod(vA, vB, vC)
| c1 c2 c3 |
S3Prod(vA, vB, vC)
= a1*(b2*c3 - b3*c2) + a2*(b3*c1 - b1*c3) + a3*(b1*c2 - b2*c1)
Note that this is also true if vA, vB and vC are column vectors in
a 3x3 matrix:
| a1 b1 c1 |
| a2 b2 c2 | = S3Prod(vA, vB, vC)
| a3 b3 c3 |
*/
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
/*
About the macro S3E3U()
"Solve 3 Equations with 3 Unknowns"
The unknowns are; x, y and z
a1, a2, a3, b1, b2, b3, c1, c2 and c3 are known constants
a1*x + b1*y + c1*z = d1
a2*x + b2*y + c2*z = d2
a3*x + b3*y + c3*z = d3
a1 b1 c1 d1
a2 * x + b2 * y + c2 * z = d2
a3 b3 c3 d3
If one considers vA, vB, vC and vD as 3D column vectors, where:
vA = <a1, a2, a3>
vB = <b1, b2, b3>
vC = <c1, c2, c3>
vD = <d1, d2, d3>
Then the problem can be rewritten like this:
vA*x + vB*y + vC*z = vD
Now if one calls the macro like this:
S3E3U(vA, vB, vC, vD)
-it will return a 3D column vector; <x, y, z>, where the x, y and z
components are the solutions to our system of equations above.
a1 b1 c1 x d1
a2 b2 c2 * y = d2
a3 b3 c3 z d3
*/
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
/*
About the macro S2E2U()
"Solve 2 Equations with 2 Unknowns"
The unknowns are; u and v
a1, a2, b1, b2, c1 and c2 are known constants
a1*u + b1*v = c1
a2*u + b2*v = c2
a1 b1 c1
* u + * v =
a2 b2 c2
If one considers vA, vB and vC as 2D column vectors, where:
vA = <a1, a2>
vB = <b1, b2>
vC = <c1, c2>
Then the problem can be rewritten like this:
vA*u + vB*v = vC
Now if one calls the macro like this:
S2E2U(vA, vB, vC)
- it will return a 2D column vector; <u, v>, where the u and v
components are the solutions to our system of equations above.
a1 b1 u c1
* =
a2 b2 v c2
*/
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
/*
To see how to make the Dot4D(), vCross4D(), Dot5D() and
vCross5D() macros below, check these links:
http://news.povray.org/povray.advanced-users/17643/113743/#113743
news://news.povray.org/3B7DC4F1.C18AF6E3%40hotmail.com
Subject: About determinands and n-dimensional cross products
Date: Sat, 18 Aug 2001 03:29:21 +0200
From: Tor Olav Kristensen <tor### [at] hotmailcom>
Newsgroups: povray.advanced-users
*/
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Macros for solving system of 4 equations with 4 unknowns
/*
#macro S4Prod(vA, vB, vC, vD)
Dot4D(vA, vCross4D(vB, vC, vD))
#end // macro S4Prod
#macro S4E4U(vA, vB, vC, vD, vE)
(<S4Prod(vE, vB, vC, vD),
S4Prod(vA, vE, vC, vD),
S4Prod(vA, vB, vE, vD),
S4Prod(vA, vB, vC, vE),
>/
S4Prod(vA, vB, vC, vD))
#end // macro S4E4U
*/
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Macros for solving system of 5 equations with 5 unknowns
/*
#macro S5Prod(vA, vB, vC, vD, vE)
Dot5D(vA, vCross5D(vB, vC, vD, vE))
#end // macro S5Prod
#macro S5E5U(vA, vB, vC, vD, vE, vF)
(<S5Prod(vF, vB, vC, vD, vE),
S5Prod(vA, vF, vC, vD, vE),
S5Prod(vA, vB, vF, vD, vE),
S5Prod(vA, vB, vC, vF, vE),
S5Prod(vA, vB, vC, vD, vF),
>/
S5Prod(vA, vB, vC, vD, vE))
#end // macro S5E5U
*/
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// And so on... (If POV-Ray had supported higher dimensional vectors.)
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
Post a reply to this message
|
|