You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve -p option to support true perspective projections #8816
The -p option currently produces what seems to be an orthographic projection, where all objects appear with the same size regardless of their distance from the viewer. This projection maintains parallel lines and provides no sense of depth.
A true perspective projection would make distant objects appear smaller, with lines converging toward vanishing points — similar to how real cameras or rendering engines represent 3D scenes. You can see this link for some interactive examples.
Implementation:
I would be interested in working on this improvement myself. However, I have not been able to find where in the GMT source the code handling the -p option (projection and 3D transformations) is implemented. Could you please indicate which source file(s) contain this logic?
I believe some of the required functionality might already exist in GMT through the General Perspective projection, so this could potentially be adapted or reused for implementing a true perspective view.
I'm still trying to learn my way around the GMT code. It looks to me like the -p option state is a boolean stored in GMT->common.p.active variable. That then triggers the appropriate projection configuration based on parsing the -p option modifiers in the gmt_init.c:gmtinit_parse_p_option() function. Otherwise, I only see the common.p.active variable used to throw an error for an inverse projection in mapproject.c
-p was not thought to be a projection parameter. What it controls is angle of rotation and view elevation. But perhaps a view distance or camera opening could be added too.
What I do when searching where things are done is to use the all-files-search of Visual Studio Code (Shift+Ctrl+F). For that one needs to load the all src dir as as workspace. Than ... see what happens. -p for sure saves the angles of rotation & elevation (or their cos/sinus) somewhere in a struct. Than repeat the process, where do those angles are used. It will be in one of the plotting functions, but this is still to broad.
-p was not thought to be a projection parameter. What it controls is angle of rotation and view elevation. But perhaps a view distance or camera opening could be added too.
Possibly (didn't) check. But remembered while driving back home that some 2-3 years ago I made a modification to allow a negative elevations. That must have been in the interest zone. Try to find it (some PR of me).
GMT uses the PostScript (PS) language to generate figures. Native PostScript only supports affine transformations, which is why GMT’s current -p option is limited to affine 3D projections (rotation, translation, and scaling) and cannot produce true perspective projections by itself.
To obtain real 3D perspective, there are essentially two options:
Implement the perspective projection in C and pass the projected coordinates to PostScript.
Implement the perspective projection directly in PostScript.
Regarding the second option, I found the PostScript package ps3d.inc, developed by Bill Casselman and described in his book Mathematical Illustration (more info here: https://personal.math.ubc.ca/~cass/graphics/manual/). From what I have seen, it provides true 3D perspective capabilities, including real perspective projections, text rendered in perspective, and spheres and other regular polyhedra with shading. Examples can be found in Chapters 13 and 14 of the book.
While performing the 3D calculations in C would likely be faster, I believe that approach would complicate features such as rendering text in true perspective. For this reason, my current idea is to continue exploring option 2, i.e., performing the perspective calculations in PostScript. Once this is implemented and evaluated, it should then be possible to assess whether performance becomes an issue and, if so, consider ways to optimize or partially move computations elsewhere.
I contacted the author by email, and he explicitly authorized the inclusion of this package in GMT, provided proper attribution is given.
I will continue investigating this direction. In the meantime, I would welcome any general comments or suggestions on how best to proceed.
I don't follow what you are trying to achieve. Do you want to modify existing PS files? I don't think we can do perspectives this way. That I know, not even full affine transforms can be done (we cannot do the shear part). Only way, that I can think of (but may be wrong), is to create a perspective transform (no idea how) in the GMT lib.
Yes, but you are creating a new PS file. Not modifying a GMT PS to show it in a perspective view. So again, I fail to see the interest of this in a GMT context.
Activity
ES-Solar commentedon Oct 22, 2025
I'm still trying to learn my way around the GMT code. It looks to me like the -p option state is a boolean stored in GMT->common.p.active variable. That then triggers the appropriate projection configuration based on parsing the -p option modifiers in the gmt_init.c:gmtinit_parse_p_option() function. Otherwise, I only see the common.p.active variable used to throw an error for an inverse projection in mapproject.c
joa-quim commentedon Oct 22, 2025
-p was not thought to be a projection parameter. What it controls is angle of rotation and view elevation. But perhaps a view distance or camera opening could be added too.
What I do when searching where things are done is to use the all-files-search of Visual Studio Code (Shift+Ctrl+F). For that one needs to load the all src dir as as workspace. Than ... see what happens. -p for sure saves the angles of rotation & elevation (or their cos/sinus) somewhere in a struct. Than repeat the process, where do those angles are used. It will be in one of the plotting functions, but this is still to broad.
Esteban82 commentedon Oct 22, 2025
Thanks, I found -p here: (
gmt/src/gmt_common.h
Line 243 in 88b836e
Now, I would have to search for
do_z_rotation, right?I found this in gmt_init.c and in gmt_plot.c. Am I the rigth path?
gmt/src/gmt_init.c
Line 2827 in 88b836e
gmt/src/gmt_plot.c
Line 9182 in 88b836e
Esteban82 commentedon Oct 22, 2025
I have found this (https://github.com/carltheperson/blockamok) where (I think) only one parameter (FOV_ANGLE) is needed. Maybe other two parameters could be add.
joa-quim commentedon Oct 22, 2025
Possibly (didn't) check. But remembered while driving back home that some 2-3 years ago I made a modification to allow a negative elevations. That must have been in the interest zone. Try to find it (some PR of me).
joa-quim commentedon Oct 22, 2025
That thing has pretty heavy dependencies.
Esteban82 commentedon Oct 23, 2025
Thank. I found the issue #7349 which works with gmt_init.c.
Esteban82 commentedon Dec 16, 2025
Update on this topic
GMT uses the PostScript (PS) language to generate figures. Native PostScript only supports affine transformations, which is why GMT’s current -p option is limited to affine 3D projections (rotation, translation, and scaling) and cannot produce true perspective projections by itself.
To obtain real 3D perspective, there are essentially two options:
Regarding the second option, I found the PostScript package ps3d.inc, developed by Bill Casselman and described in his book Mathematical Illustration (more info here: https://personal.math.ubc.ca/~cass/graphics/manual/). From what I have seen, it provides true 3D perspective capabilities, including real perspective projections, text rendered in perspective, and spheres and other regular polyhedra with shading. Examples can be found in Chapters 13 and 14 of the book.
While performing the 3D calculations in C would likely be faster, I believe that approach would complicate features such as rendering text in true perspective. For this reason, my current idea is to continue exploring option 2, i.e., performing the perspective calculations in PostScript. Once this is implemented and evaluated, it should then be possible to assess whether performance becomes an issue and, if so, consider ways to optimize or partially move computations elsewhere.
I contacted the author by email, and he explicitly authorized the inclusion of this package in GMT, provided proper attribution is given.
I will continue investigating this direction. In the meantime, I would welcome any general comments or suggestions on how best to proceed.
joa-quim commentedon Dec 16, 2025
I don't follow what you are trying to achieve. Do you want to modify existing PS files? I don't think we can do perspectives this way. That I know, not even full affine transforms can be done (we cannot do the shear part). Only way, that I can think of (but may be wrong), is to create a perspective transform (no idea how) in the GMT lib.
Esteban82 commentedon Dec 17, 2025
Correct. The built-in funcions in PS cannot do the shear part. The ps3d.inc package has all the functions to do the perspective transformation.
joa-quim commentedon Dec 17, 2025
And how do you use it?
Esteban82 commentedon Dec 17, 2025
You have to include some commands in the header of the ps file. For example, this is the PS file that creates the image below
Link: https://personal.math.ubc.ca/~cass/graphics/manual/code/cube5.txt
`
`
joa-quim commentedon Dec 17, 2025
Yes, but you are creating a new PS file. Not modifying a GMT PS to show it in a perspective view. So again, I fail to see the interest of this in a GMT context.
Esteban82 commentedon Dec 17, 2025
Well, I still have to see how to modify a GMT PS to make a perspective view. But I know that it is possible.