Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
669 views
in Technique[技术] by (71.8m points)

algorithm - Mapping coordinates from plane given by normal vector to XY plane

So, I have this algorithm to calculate cross-section of 3D shape with plane given with normal vector.

However, my current problem is, that the cross-section is set of 3D points (all lying on that given plane) and to display it I need to map this coordinates to XY plane.

This works perfect if the plane normal is something like (0,0,c) - I just copy x and y coordinates discarding z.

And here is my question: Since I have no idea how to convert any other plain could anybody give me any hint as to what should I do now?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your pane is defined by a normal vector

n=(xn,yn,zn)

For coordination transformation we need 2 base vectors and a zero point for the pane

Base vectors

We chose those "naturally" fitting to the x/y pane (see later for edge case):

b1=(1,0,zb1)
b2=(0,1,zb2)

And we want

b1 x b2 = n*c (c const scalar)

to make sure these two are really bases

Now solve this:

b1 x b2= (0*zb2-zb1*1,zb1*0-1*zb2,1*1-0*0) = (zb1,zb2,1)
zb1*c=xn
zb2*c=yn
1*c=zn

c=zn,
zb2=yn/c=yn/zn
zb1=xn/c=xn/zn

b1=(1,0,yn/zn)
b2=(0,1,xn/zn)

and normalize it

bv1=(1,0,yn/zn)*sqrt(1+(yn/zn*yn/zn))
bv2=(0,1,yn/zn)*sqrt(1+(xn/zn*xn/zn))

An edge case is, when zn=0: In this case the normal vector is parallel to the x/y pane and no natural base vectors exist, ind this case you have to chose base b1 and b2 vectors by an esthetic POV and go through the same solution process or just chose bv1 and bv2.

Zero point

you spoke of no anchor point for your pane in the OQ, but it is necessary to differentiate your pane from the infinite family of parallel panes.

If your anchor point is (0,0,0) this is a perfect anchor point for the coordinate transformation and your pane has

x*xn+y*yn+z*zn=0,
(y0,y0,z0)=(0,0,0)

If not, I assume you have an anchor point of (xa,ya,za) and your pane has

x*xn+y*yn+z*zn=d

with d const scalar. A natural fit would be the point of the pane, that is defined by normal projection of the original zero point onto the pane:

P0=(x0,y0,z0)

with

(x0, y0, z0) = c * (xn,yn,zn)

Solving this against

x*xn+y*yn+z*zn=d

gives

c*xn*xn+c*yn*yn+c*zn*zn=d

and

c=d/(xn*xn+yn*yn+zn*zn)

thus

P0=(x0,y0,z0)=c*(xn,yn,zn)

is found.

Final transformation

is achieved by representing every point of your pane (i.e. those points you want to show) as

P0+x'*bv1+y'*bv2

with x' and y' being the new coordinates. Since we know P0, bv1 and bv2 this is quite trivial. If we are not on the edge case, we have zeroes in bv1.y and bv2.x further reducing the problem.

x' and y' are the new coordinates you want.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...