charltonian-ga
I trust that Dr. Jerry is right - but (I hope that is a consolation)
I cannot follow his reasoning either.
So we will derive it the pedestrian way:
Take one of your data points in space - lets say X Y and Z
We want to find coordinates x,y,z of point p
such that
1) p lies in that plane
(so that z=A*x + B*y +C)
2) distance of the points, d(P,p) is minimal
(so the line pP is perependicular)
We can get 2 equations for two unknown y and z by 'moving x, and y'
and always adjusting z so that p stays in the plane:
Conditions for minimum of d (which is same as for D=d^2) are
1) d/dx (D) =0
2) d/dy (D) =0
where D is d*d = (X -x)^2 + (Y-y)^2 +(Z- A*x -B*y -C) ^2
Equations are linear, rest is easy. That assumes you can do calculus:
eq 1) 2*(X-x) + 2*(Z-A*z -B* y -C) *A =0
eq 2) 2*(Y-y) + 2*(Z-A*z -B* y -C) *B =0
rest is really easy.
Of course, you will write a program which will process your data, right?
Happy Krieging.
Hedgie |
Clarification of Answer by
hedgie-ga
on
22 May 2005 00:28 PDT
Correcting a typo
eq 1) 2*(X-x) + 2*(Z-A*z -B* y -C) *A =0
eq 2) 2*(Y-y) + 2*(Z-A*z -B* y -C) *B =0
should be
eq 1) 2*(X-x) + 2*(Z-A*x -B* y -C) *A =0
eq 2) 2*(Y-y) + 2*(Z-A*x -B* y -C) *B =0
(I hope you noticed that?) so - as pennance, next step is
(please check the signs):
eq 1) x *(A^2 +1) + y *AB = X - C*A - A*Z
eq 2) x * A*B + y * (B^2 +1) = Y - C*B - B*Z
se matrix is | 1+ A^2, AB|
| AB, 1+ B^2 |
You plug that into a program or invert by formula
The inverse of a 2x2 matrix, given e.g. here
http://www.maths.surrey.ac.uk/interactivemaths/emmaspages/option1.html
|
Request for Answer Clarification by
charltonian-ga
on
22 May 2005 01:01 PDT
Ok, it seems that I can't quite understand your answer, and I know
that part of the problem here is my unfamiliarity with mathematical
language.
I need a few points of clarification (some directly relevant, some general.)
1) I have seen planes expressed in a few ways
like yours, z=A*x + B*y +C , or 0=A*x + B*y +C*z or D=A*x + B*y +C*z
I definitely don't understand the difference (if there is one) and I'm
not entirely clear how I use this function. Please could you explain
this a little further (I don't need a full run down, just how to use
it.)
2) saying pP is perpendicular - is this like the normal ? or is it
perpendicular across the plane?
Can I do calculus? Maybe, I finished up studying Maths over 15 years
ago, so whilst I can follow things, I can't do all the clever tricks.
Your equations look like the kind of thing I was after, but I'm not
sure how to use them. If it's a case of manipulating them to get them
in terms of the XY coords I want, I can probably do that, but if it's
not then I'm lost.
In the interests of fairness you have probably answered the question
as clearly as you should, further clarifications will be tipped.
|
Clarification of Answer by
hedgie-ga
on
22 May 2005 03:01 PDT
OK
1) I have seen planes expressed in a few ways
I took same form as used in Jerry dialog:
z=A*x + B*y +C (you got A B C by fitting the plane to your 3D points)
equivalent form is A'*x + B'*y +C'*z=1 (NOT 0 !) but we
are not using that one.
2) 2) saying pP is perpendicular - is this like the normal?
Yes. Given P, you seek point p (confined to the plane) so
that line from p to P
is normal to the plane. (Imagine a rubber band from P to p, p gliding
on the plane)
It is intuitive, but prrof is available:
http://members.tripod.com/~Paul_Kirby/vector/Vclose.html
Just consider the riangle A,B, and p (= closest point).
3) Let's get to the final eqs. You did not say if matrix calculus is OK
so I assume so. It can be done without them - just solving 2 eqs.
Determinant of the matrix we found is Det= 1+ A^2 + B^2 , which is always >0
as it should.
so 'THE FINAL SOLUTION' has form:
r = I * R , where r =[x,y] I is inverse of matrix we derived above and
R is 'right side' = [ X-CA - AZ, Y- CB - BZ ]
we can write it without matrices , to get:
x = F + Fx *X + Fy *Y + Fz *Z
y= G + Gx *X + Gy *Y + Gz *Z
where
F= CA
G= CB
Fx= (1 + A^2) /det
Gy= (1 + B^2( /det
Fy = Gx= -AB/ det
Fz = A
Gz = B
It needs to be tested (it is easy to drop a term);
One test would be to pick P=X,Y,Z which is on the plane and see
x,y to be reduced to X,Y
but if you write a program, you will see if it works OK.
Hedgie
|
Clarification of Answer by
hedgie-ga
on
22 May 2005 03:39 PDT
Perhaps I was too telegraphic with this:
" not entirely clear how I use this function ...z=A *x + B* y +C "
It is an eq. for a surface Z= f(X,Y)
look at the picture here:
http://www.euclideanspace.com/maths/geometry/elements/plane/
You pick a point x,y in the 'horizontal' base plane x,y
calculate z from f(x,y) and go up that much = z
you get a point on the surface f
- you do it for all x,y points, and get whole surface.
That's what that eq. means.
PS I found this link looking for a pic, to eqplain eq. of the surface
but it looks like he is solving the same task, even the same way.
But he has 1-A^2 on diagonal and I got 1+A^2,
but he is using the other form
a*x + b*y + c*z + d = 0
You can divide by d and get
a/d X + b/d *Y + c/d *Z = -1 which still other form
or solve for z (dividing by -c) to get our form;
they are all equivalent . OK?
SEARCH TERM: Distance from a Point to a Plane
is rich, but (as I am looking at them) the lingo is quite heavy there, too.
It may be best to stick with what we have,
just verify I did not switch a sign somewhere.
Please feel free to post another RFC, if needed.
|
Request for Answer Clarification by
charltonian-ga
on
22 May 2005 05:04 PDT
Hello again, thanks for all your time so far, I feel close to a
solution but whilst I know what information I have, and I think I
understand all the stuff you have given me, putting them together is
still eluding me.
There are 2 problems, one I'm not sure how I'll fit my plane. 2) With
your equations: x = F + Fx *X + Fy *Y + Fz *Z and y= G + Gx *X + Gy
*Y + Gz *Z I'm thinking that x and y are coordinates on the plane,
and X,Y and Z are my 3d coordinates - but I'm not sure where F and G
came from.
If I explain what I have we may be able to work this thru to a solution.
I am rotating a cube about the origin, and my vertex (which is from an
arbitrary point to the origin) is a light source. The point I am
looking for on each plane/face is where the specular highlight will be
placed. I calculate the intersection between a plane and the vertex,
but mask it off if it is outside of the face area (i am working on the
basis that the plane spreads off to infinity in both directions, but I
only show the part of the plane I am interested in, which is it's
face.) I have XYZ coords for all the corners of the face, plus its
central point. I also have the XYZ coord of the point of intersection.
In addition I have the plane's normal (this was needed to calculate
the point of intersection.)
What I can't do at 'run time' is solve equations for the plane, so
effectively with the data I have I need a function which literally
converts the 3d coords into 2d coords (don't worry about the specific
scaling, I know what I'm doing with that part.)
If you can tell me how to fit what you've told me with what I have
(and I'm really sorry if I'm missing the obvious,) I would be very
grateful.
|
Clarification of Answer by
hedgie-ga
on
22 May 2005 06:25 PDT
Oh! And I thought we got it all squared out. Except perhaps the sign.
The sentence
"..and my vertex (which is from an
arbitrary point to the origin) is a light source. The point I am
looking for on each plane/face is where the specular highlight will be
placed..".
I find unclear.
My be need to backtrack -take smaller steps and agree on some symbols,
perhaps use pseudocode.
So (step 1) I assumed you already have your plane (A B C ) fitted. Do You?
(step 2) you can choose (any) CS on your plane and convert to that
I have (to make it simpler) worked with single a frame
(frame = CS = coordinate system) so x,y we got are in the same frame as X Y Z
In either case, solution will be matrix equation of form
p = Projection * P (agree?)
Please do answer: are you comfortable with matrices, as used ee.g. here:
--------------
The inverse of a 2x2 matrix, given e.g. here
http://www.maths.surrey.ac.uk/interactivemaths/emmaspages/option1.html
---------- ?? F and G are coeficients of that matrix
step 3) You will run your data through some Krieging program
(are you using some standard geostatistical library, like Glib ?)
What is the input required for step 3)
What do input data look like: X Y Z V1 V2 .. ?
where V.1 V.2 are some concentration of ore ?
Do you program (or have someone who does that for you) ?
Hedgie
|
Clarification of Answer by
hedgie-ga
on
22 May 2005 08:13 PDT
Let's strat from the begining:
I am re-reading all from the begining and
I see conflict between 'vertex' and 'perpendicular'
IN
http://mathforum.org/library/drmath/view/51727.html
1) and 2) makes sense
You say:
" Fitting the plane z = Ax+By+C to these points I can do..."
OK. The you say:
"I want :
x'=f(x,y,z),
y'=g(x,y,z)
z'=0 "
(actually no. If x', y' are in some plane frame, there is no z'
if they are in original 3D frame, then Z= A*X + B*Y +C )
You can define a second 3D frame , which has your plane as a base - but
we have not done that. In that z'=0 would be true.
I understand:
" Each point should be projected onto the plane
along a line passing through the point and perpendicular to the fitted
plane."
Here 'perpendicular' is essential (and conflicts with)
use of the word vertex in the last 'explanation' about faces of the cube.
Vertex is a point,so
"I calculate the intersection between a plane and the vertex .."
which you say in last installment, just does not compute.
see vortex:
http://www.gamedev.net/reference/articles/article1300.asp
What you can get is eq of type:
x'=f(X,Y,Z)
y'=g(X,Y,Z)
in form
x' = F + Fx *X + Fy *Y + Fz *Z
y'= G + Gx *X + Gy *Y + Gz *Z
which can by put succintly as
p = Projection-matrix * P
where p=x' y' are some 2D frame corodnates on the plane and
P= X Y Z are cordinates in some 3D frame.
You can specify any 2D frame by giving 3D coordinates
of two points P0, P1 in the plane and say
these are (origin 0,0 and point 1,0) of my 2D frame.
I assumed plane frame created by projecting your 3D frame on the plane
so that P0=(0,0,0) and P1=1,0,0 - was the special case.
The values of F,G coeficients will depend on the choice you make.
So, workfow is
for all i [ where (i=1, 2 ...I) numbers your data points.
you get p.i=(x,y) from each P.i =(X Y Z)
run 2D krieging program on p.i, geo-values.i
Then back-track back to original P.i
(no equation here, you just remember the which i it was)
Is that what you want?
Hedgie
|
Request for Answer Clarification by
charltonian-ga
on
22 May 2005 08:23 PDT
ok - clarifications
this has nothing to do with geology - the dr. math post was nothing to
do with me - it was something I found whilst looking for a solution to
my problem.
I am a programmer, and what I am doing is making a rotating cube, this
excercise is adding lighting effects to it.
I do understand matrix calculus, but this is very much in the sense of
I can pull it apart and put it back together into the direct functions
that I need,
if you go to
http://mathforum.org/library/drmath/view/55094.html
it shows the method I followed for finding my vertex plane interection.
If you look at the above example, and could find a way of expressing
where X is in terms of the point A (which I use as the top left
registration of my cube's face) but on the plane...
In my attempts to solve this problem I calculated the vector AX and
then tried to transform it in such a way that the Z component was 0
and from there I could use the XY values within the plane (I couldn't
make it work btw.)
I have a plane fitted (well 6 in fact as I am making a cube, but let's
work on just one), it moves in the 3d environment (well rotates about
the origin at any rate.) Without getting into the specifics of how it
works, essentially it is an orthographic projection, based on the top
left, top right, and bottom left points. I also have a central point
on the face (this actually serves as my axis of rotation, as the cube
rotates about its internal axes rather than the global axes.)
I do have a CS for the plane (it is 100 pixels x 100 pixels) The
starting points for the global XYZ positions of the 8 corners are
defined as S (so I can change its value, but we may as well describe
it as that) I therefore would calculate the local/plane position as
x' = (myXvalue+S/2*S)*100 the myXvalue being what was spat out of the
transforming function.
I have tried to put some of your stuff into my project but it doesn't
work (yet) so I'll start with a couple simple questions:
The plane equation z=A*x + B*y +C
am I right in thinking that ABC are the values from my normal (Nx,Ny,Nz)?
|
Request for Answer Clarification by
charltonian-ga
on
22 May 2005 09:01 PDT
Ha, it seems we are crossing messages and I'm not really helping you out much.
I will also apologise for using the wrong terminology - this, I think,
has been one of the main difficulties I have had; finding the language
to describe the problem (but despite a few inconsistencies/errors I'm
nearly there.)
It would seem that
x' = F + Fx *X + Fy *Y + Fz *Z
y'= G + Gx *X + Gy *Y + Gz *Z
is the answer and that
F= CA
G= CB
Fx= (1 + A^2) /det
Gy= (1 + B^2) /det
Fy = Gx= -AB / det
det= 1+ A^2 + B^2
Fz = A
Gz = B
gives me most of the things i need to plug in...
BUT - this relies on ABC being the values of my normal calculations
(and if not those values then values I can get from somewhere.) I know
it's not very elegant to break it down in this way, but really this is
pushing at the limits of my mathematical ability.
|
Request for Answer Clarification by
charltonian-ga
on
22 May 2005 09:09 PDT
I probably then should say from the x' and y' values I would then need
to transform them to
xOnPlane = (x'+S/2*S)*100
yOnPlane = (y'+S/2*S)*100
|
Clarification of Answer by
hedgie-ga
on
22 May 2005 09:45 PDT
AHA.
This:
"I am a programmer, and what I am doing is making a rotating cube, this
exercise is adding lighting effects to it"
is very helpful (and should have been said in first communication)!
But, better late then never - so: Thanks for this clarification.
RE: rotating cube:
I recall doing that exact exercise in a SGI course on use of the
first SGI workstations. I forgot how - it was a long time ago,
but it was fun and that course may be somewhere )
This I understand:
"One particular problem I ran across is determining whether a line and
plane intersect and where they will intersect, given a line
perpendicular to the plane (one point is on the plane, another is out
in space), and 2 points P and Q out in space that determine a line"
This
"my vertex plane interection"
still does not make sense. Vertex is a point ( a source of the light?)
It is outside of the cube, shining at the cube. Right?
You have 8 points, forming a cube, faces and normals to all faces
and center of each face. All that looks easy.
This
"without getting into the specifics of how it
works, essentially it is an orthographic projection"
again does not make sense. Please be careful with the terminology.
You need (for any rotation of the cube)to know which
'shading' to pot on each visible face
and also which face is visible from given POV. True?
Anyway - your last RFC:
if plane is a*x +b*y +c*z +d =0
then [a b c ] is normal vector.
You normalize it to 1 to get Nz Ny Nz (a unit vector normal to the plane)
My hunch (or recollection?) is:
The angles of LS - Center and of
POV-Center
lines to this vector unit vector at center may be all you need.
Hedgie
|
Request for Answer Clarification by
charltonian-ga
on
22 May 2005 11:23 PDT
ok, once again apologies for omissions and oversights. Unfortunately
I'm not using SGI and this is part of the problem. I am doing 3d in a
2d environment so the maths is 3d and the package is forced into
approximating the 3d effect by skewing the faces to the corner points.
But working on the basis of the maths being right I thought that this
aspect (intesection if the vector(!) and the plane being commuted into
a different form would not be too difficult - how wrong I was...)
I have tried putting in
x' = F + Fx *X + Fy *Y + Fz *Z
y'= G + Gx *X + Gy *Y + Gz *Z
(initially, before one of the later clarifications) using the
normalized normal (which didn't really work) and then with the normal
vector (which seemed to work even less well.)
Now I'm very conscious of taking a lot of time to make little
progress, mainly which is unfair on your good self. But, obviously I
would like this worked through.
I think the fairest resolution that I can offer (because this now
seems like my only way of getting this resolved - and you seem to
really know what you're talking about) is
1) If you've had enough, then tomorrow at some stage I'll rate the
answer and we'll leave it as it is.
2) You provide a worked through example for which I tip $10-20 of a
point on a plane being converted into local coords.
i.e.
A ______________B
/ /
/ .X /
/ /
/_____________/
C
corner A = (Ax,Ay,Az)
corner B = (Bx,By,Bz)
corner C = (Cx,Cy,Cz)
point X = (Xx,Xy,Xz) -- this is the point of intersection
and this is converted to
A_____B
| .X|
| |
C|_____|
point X can either be a coord, or be represented in terms of A,B and C
the only thing that needs to also be considered is that sometimes a
face will be rotated so that the point of intersection will be exactly
the same in 3d space but will have moved on the 2d plane (by n degrees
around the face's centre.)
Thanks for eveything so far.
c
|
Clarification of Answer by
hedgie-ga
on
22 May 2005 12:24 PDT
charltonian
You say:
" I have tried putting in
x' = F + Fx *X + Fy *Y + Fz *Z
y'= G + Gx *X + Gy *Y + Gz *Z
(initially, before one of the later clarifications) using the
normalized normal (which didn't really work)"
I believe you. That was an orthogonal projection and you are really after
vertex projection aka perspective. I gave you links describing
both - they are different.
I was actually supposed to work on something else - and so I am not sure I
can extend this dialog into another day.
So - here is my counter-offer:
You rate this dialog of partial answers -
and tomorrow evening (after some other work is done)
I will look to see if you posted another question.
That's if you need either an example - or other clarification.
But, chances are you will not need that:
To give you something to do, whole day, here is the ROTATING CUBE page,
with sources of some such programs. If you look through that and may
be all your problems will be solved:
ROATING CUBE PAGE
http://www.selectorweb.com/java_applet_cube3d.html
Some such solutions are on the net with the sources
doing this in open GL
http://brigthepig.com/images/3Dcube.jpg
specular reflection
http://www.brigthepig.com/
http://games.swizel-studios.com/tutorials/images/alpha_tutorial_0.1.png
source
http://games.swizel-studios.com/tutorials.html
http://turmanj.tripod.com/webpg/opengl2.html
SEARCH TERM: shading, ROATING CUBE
Hedgie
|
Request for Answer Clarification by
charltonian-ga
on
22 May 2005 15:10 PDT
ok, your offer is fair.
I won't (probably) post another question until next weekend, I have a
full week of working, and it is only fair that I fully review all the
things we have gone through here.
I thank you for all the effort you have put in.
|
Clarification of Answer by
hedgie-ga
on
22 May 2005 21:32 PDT
charltonian-ga
We are supposed to respond to all RFCs, so I need to add something.
Hmmm, OK: I was answering this question about the orthogonal projection:
"I have found a solution, but some of the working appears to be
incomplete, or I am missing something."
Answer was the formula I derived and explained. It turned out later,
that orthogonal projection is not what you need for your program.
I am surprised that answers to other questions you may have, was not
found in the sources of similar programs, which I listed in the last
RFC. Anyway.
Thanks for the rating; feedback is helps us to understand clients.
Good luck with you project and all the projections.
Hedgie
|