Passing 3d points and scalars into "special" for pst-3dplot

50 views
Skip to first unread message

Don

unread,
Jan 14, 2011, 9:39:16 PM1/14/11
to Sketch Users
Hi all,

It would be very useful to be able to pass a 3D point into a "special"
command. This would be useful in allowing use of pst-3dplot commands,
e.g. pstPlanePut.

Right now I have to do
special | \pstPlanePut [ plane=xz, planecorr=xyrot ](-0.2,-0.4,0)
{ { Text } } |
but I'd like to do
special | \pstPlanePut [ plane=xz, planecorr=xyrot ] #1 { { Text } } |
(Coord)

Unfortunately sketch always projects 3d points into 2d, so this syntax
fails. It would also be useful to be able to pass scalars. To get
pst-3dplot to line up correctly with sketch's output, you can use

def CamPos (CamX,CamY,CamZ)
def AlphaAngle 90+atan2(CamZ, CamX)

def BetaAngle atan2(CamY, sqrt(CamZ^2+CamX^2))

special | \psset{Alpha={116.5651}, Beta={16.6015} } | [lay=under]
special | \psset{RotY=0, RotX=90, RotZ=0} | [lay=under]


def MyDrawing {
...
}
put { view((CamPos),(0,0,0),[0,1,0]) } {MyDrawing}

where the Alpha= and Beta= are replaced with the results of the def.
This would be a great place to be able to pass a scalar in!

Alternatively, can someone suggest a way of putting 3D text in a
plane, as in pstPlanePut?

Cheers,
Don

Gene

unread,
Jan 14, 2011, 10:36:17 PM1/14/11
to sketch...@googlegroups.com
Thanks.  This ought to be pretty easy. I'll look at it.

Gene

unread,
Jan 29, 2011, 10:14:47 PM1/29/11
to sketch...@googlegroups.com
Hello friends.  I'm uploading now v0.3 build 1, which has extended the language for argument substitution in specials as Don suggested. 

Arguments can now be scalars, points, and vectors.  Substitution can be controlled with the "tick" operator, so 'x 'y 'z substitute the x, y, z- component of point and vector args and '3 produces the full 3d point rather than 2d projection.  Documentation has been updated, though the examples don't show these new features in use.  Thanks do Don for the suggestion. 

The grammar needed some substantial changes to make all this work.  There should be _no_ effect on processing of existing code.  If you find any, please let me know.

Don

unread,
Feb 8, 2011, 3:04:17 AM2/8/11
to Sketch Users

Thanks, this is very cool! Thanks to this new syntax you can line up
pst-3dplot drawing elements with sketch-generated output. The example
below aligns pst-3dplot axes with sketch based on a tweakable camera
position CamPos.

Unfortunately, the projections don't line up perfectly. If CamY is 0,
things line up for varying CamX,Z, but for significant values of CamY,
the sketch output becomes smaller while pst-3dplot output does not.
I'm not sure why this is happening, though I'm still pretty new to
sketch. I do note that perspective transformations are not supported
by pst-3dplot... any insight here, Gene?

I think I'll probably try to do my figures with rputs (with rotation,
as in the example below) instead of the somewhat nicer-looking
pstPlanePut, just so I can have perspective without trying to hack
pst-3dplot into complying with it. It's a tough call between nice-
looking in-plane text, and perspective. Anyone out there have hints
on making the \rput text look nicer... i.e. more "in-plane") (def
CamPos (15, 15, 10) in the example below to see what I mean)

Cheers,
Don

--------------aligning pst-3dplot with sketch-------------------
%%%%% TWEAKABLES %%%%%

%% cam & axis

def O (0,0,0)

def CamPos (5, 2, 10)

def dx 3

def dy 3

def dz 3



%%%%% DERIVED %%%%%

%% cam & axis

def AlphaAngle 90+atan2((CamPos)'z, (CamPos)'x)

def BetaAngle atan2((CamPos)'y, sqrt((CamPos)'z^2+(CamPos)'x^2))



%%%%% pst-3dtricks setup %%%%%

def Config {

% set up pst-3dplot -- this should always be drawn first

special | \psset{Alpha={#1}, Beta={#2} } | AlphaAngle BetaAngle

special | \psset{RotY=0, RotX=90, RotZ=0} |

}



%%%%% Axes, Ref planes %%%%%

def AxesAndPlane {

% draw the axes

line[arrows=->,linewidth=1pt](O)(dx,0,0)

line[arrows=->,linewidth=1pt](O)(0,dy,0)

line[arrows=->,linewidth=1pt](O)(0,0,dz)



% draw again using pst-3dplot

special | \pstThreeDLine[]{->}(0,0,0)(#1,0,0) | dx

special | \pstThreeDLine[]{->}(0,0,0)(0,#1,0) | dy

special | \pstThreeDLine[]{->}(0,0,0)(0,0,#1) | dz



% draw the plane

polygon[cull=false,fillstyle=solid,opacity=0.6,fillcolor=gray!
20,linewidth=0.7pt](0,0,0)(dx,0,0)(dx,dy,0)(0,dy,0)

special | \rput[bl]#1-2#3{\sf rput} | (-dx,0,0)(dx,0,0)(0,0,0)



% and again using pst-3dplot

special | \pstThreeDSquare(0,0,0)(#1,0,0)(0,#2,0) | dx dy

special | \pstPlanePut [plane=xz, planecorr=xyrot](0,1,0) { { \sf
pstPlanePut } } |

}



def L2PP {

{Config}

{AxesAndPlane}

}



%%%%% Draw with desired cam setup %%%%%

put { view((CamPos)) } {L2PP}



global {

language pstricks

}

---------------------------using the template
file---------------------------

\documentclass{article}
\usepackage[x11names,rgb]{xcolor}
\usepackage{tikz}
\usepackage{pst-3dplot}
\usetikzlibrary{snakes,arrows,shapes,backgrounds}
\usepackage[cmex10]{amsmath}
\usepackage{amsfonts}

% Use preview.sty to crop the page
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{pspicture} % set to tikzpicture for tikz output
\setlength\PreviewBorder{10pt}%

\begin{document}
%%SKETCH_OUTPUT%%
\end{document}
---------------------------------------------

Don

unread,
Feb 8, 2011, 6:01:27 AM2/8/11
to Sketch Users

Just as a followup to this, when I pass a 3d point in using #1'3, it's
getting modified by the view((CameraPos)) modifier. How can I pass a
3D point in directly without having it modified/reprojected? This
would be useful, for this kind of command:

special | \pstPlanePut [ plane=yz, planecorr=xyrot ](#1'3) { { $Z$ }}
| [lay=in] (MyZAxisEnd)

pstPlanePut needs to have knowledge of the world/camera alignment to
get text to look correct "in the plane", so it makes sense to align
the pst-3dplot world with the sketch world, then directly pass in 3D
coordinates.

Reading the documentation, I thought that maybe using (#1'x,#1'y,#1'z)
would do it, but that seems to also use the transformed 3D point.

Cheers,
Don

Gene

unread,
Feb 8, 2011, 11:11:17 PM2/8/11
to sketch...@googlegroups.com
This is why there were no 3d points to begin with.  The 3dplot routines apply their own view transform.  The points being passed in have already had a view (camera) transform applied.  Interaction between the two is arbitrary.

Don

unread,
Feb 9, 2011, 7:20:15 PM2/9/11
to Sketch Users
Hi Gene,

I see what you mean, both systems are doing their own 3d->2d
conversions. It still seems to me that it should be possible to line
the two worlds up and pass 3d coordinates directly between them... as
long as there's no perspective, the relationship isn't arbitrary.
I've gotten very close with the Alpha and Beta values as computed in
the example I posted... there's just that niggling little difference
under vertical camera motion. Anyway, I'm currently only using 3dplot
for text in the plane, and for that the match is close enough, with a
bit of manual bumping around.

Thanks for the great work,
Don

Gene

unread,
Feb 9, 2011, 8:13:04 PM2/9/11
to sketch...@googlegroups.com
It's true that if the viewing transformations are parallel rather than perspective, it will be much simpler to make a match. Good luck with it.

The real answer of course is to make Sketch do everything that the various 3d packages do so that you don't need to combine systems.  
Reply all
Reply to author
Forward
0 new messages