This function converts from 3-dimensional user coordinates to 3-dimensional window coordinates.

rgl.user2window(x, y = NULL, z = NULL, projection = rgl.projection())
rgl.window2user(x, y = NULL, z = 0, projection = rgl.projection())
rgl.projection(dev = cur3d(), subscene = currentSubscene3d(dev))

## Arguments

x, y, z Input coordinates. Any reasonable way of defining the coordinates is acceptable. See the function xyz.coords for details. The RGL projection to use The RGL device and subscene to work with

## Details

These functions convert between user coordinates and window coordinates.

Window coordinates run from 0 to 1 in X, Y, and Z. X runs from 0 on the left to 1 on the right; Y runs from 0 at the bottom to 1 at the top; Z runs from 0 foremost to 1 in the background. RGL does not currently display vertices plotted outside of this range, but in normal circumstances will automatically resize the display to show them. In the example below this has been suppressed.

## Value

The coordinate conversion functions produce a matrix with columns corresponding to the X, Y, and Z coordinates.

rgl.projection() returns a list containing the following components:

model

the modelview matrix

projection

the projection matrix

viewport

the viewport vector

See par3d for more details.

## Author

Ming Chen / Duncan Murdoch

## See also

select3d

## Examples

open3d()
points3d(rnorm(100), rnorm(100), rnorm(100))

{"x":{"material":{"color":"#000000","alpha":1,"lit":true,"ambient":"#000000","specular":"#FFFFFF","emission":"#000000","shininess":50,"smooth":true,"front":"filled","back":"filled","size":3,"lwd":1,"fog":true,"point_antialias":false,"line_antialias":false,"texture":null,"textype":"rgb","texmipmap":false,"texminfilter":"linear","texmagfilter":"linear","texenvmap":false,"depth_mask":true,"depth_test":"less","isTransparent":false,"polygon_offset":[0,0],"margin":"","floating":false},"rootSubscene":1444,"objects":{"1450":{"id":1450,"type":"points","material":{"lit":false},"vertices":[[-1.14845955371857,-0.574818193912506,-0.40946489572525],[1.07810950279236,1.10610842704773,-0.261390954256058],[0.0480128042399883,1.40470588207245,0.00267780432477593],[0.939406394958496,-0.0256817433983088,-1.37203705310822],[0.476963043212891,1.16989839076996,0.243978634476662],[-0.438928633928299,-0.0735140964388847,0.08036258071661],[1.56770730018616,0.413521260023117,-0.789747774600983],[0.165626272559166,-0.978567242622375,-0.0586722940206528],[-2.03259468078613,-0.401955425739288,0.30242931842804],[0.625439167022705,-0.21259905397892,-0.343976944684982],[1.0821487903595,-0.323164850473404,-1.6276193857193],[-1.19223213195801,1.34905326366425,1.52897119522095],[-1.07601702213287,-0.500983119010925,-0.778463125228882],[-1.16677951812744,0.787760555744171,1.04684007167816],[0.342589020729065,0.739052951335907,1.8105263710022],[-0.237016841769218,-0.950123012065887,-0.829546988010406],[-1.39198243618011,-0.434176981449127,0.382681518793106],[-0.951049864292145,-0.538266777992249,1.19694447517395],[-1.80852377414703,0.813056826591492,1.36451852321625],[1.57046473026276,-0.416037499904633,-0.449863284826279],[-0.325502008199692,-0.727457642555237,0.874775648117065],[-0.591384887695312,-0.347478806972504,-1.04379427433014],[0.181915476918221,1.59747040271759,-1.94616544246674],[0.0346886441111565,-0.432556211948395,-0.460609704256058],[0.176703736186028,0.903757631778717,-1.19473147392273],[-1.20270037651062,-0.513977646827698,-0.781144261360168],[-0.00774381915107369,-0.181857034564018,-0.160446599125862],[1.22791254520416,-1.29882526397705,-0.00134717777837068],[-0.608838319778442,1.58664655685425,1.58534300327301],[-0.227496445178986,-1.24173390865326,-1.83564388751984],[-0.863142371177673,1.2556825876236,-0.354070216417313],[0.0201448947191238,-0.0588362067937851,-0.238880053162575],[0.0352725088596344,-0.260354697704315,1.68263030052185],[-0.349790334701538,-0.10898768901825,-0.01140580419451],[-0.552731156349182,0.139877989888191,1.17509019374847],[1.19494390487671,-0.475424498319626,1.2042932510376],[-0.0789096727967262,0.00552108604460955,1.15833866596222],[0.534982919692993,0.847152054309845,1.5913782119751],[1.51066267490387,-0.664298832416534,-0.89135205745697],[-0.709565281867981,0.874232232570648,-0.833197832107544],[0.571943461894989,2.11811089515686,-0.144258975982666],[-0.513265609741211,-0.969527781009674,-1.39150512218475],[-0.888005256652832,0.563101649284363,0.103562548756599],[-0.549767196178436,-1.24878859519958,0.0940403044223785],[0.139321133494377,-0.0724726319313049,1.56665372848511],[0.254166305065155,0.478341460227966,-1.56802546977997],[2.36111259460449,-0.892570734024048,1.5838395357132],[0.60650372505188,-1.83770596981049,0.34175118803978],[0.0325226448476315,-0.464716792106628,1.07834577560425],[-0.592521727085114,-1.7854984998703,1.54721236228943],[-0.345925837755203,-1.68333923816681,0.775472462177277],[-1.70222210884094,-0.202328249812126,0.133027657866478],[0.28550723195076,-1.04869401454926,0.225133880972862],[0.675623774528503,-0.573635637760162,-0.513978958129883],[0.896490097045898,0.355710446834564,-0.0297206714749336],[-0.518660008907318,0.727806925773621,0.977886915206909],[-0.172901496291161,0.71920382976532,0.260729670524597],[-0.923082888126373,-0.761017560958862,0.0251538027077913],[0.801185548305511,1.5763486623764,-0.931991636753082],[-1.29571998119354,0.762841999530792,0.177333727478981],[0.105209283530712,-0.347063362598419,-1.76189303398132],[-0.864516139030457,0.199035286903381,-1.17911267280579],[-0.477634102106094,0.415416836738586,-0.4399334192276],[0.656216859817505,0.752322375774384,-0.509721994400024],[-0.634684324264526,0.882167160511017,-1.17193961143494],[-0.664959907531738,0.106365017592907,1.70757925510406],[-0.498177170753479,-0.192267239093781,1.23734831809998],[-0.0765142515301704,0.138710290193558,-0.956420421600342],[0.579342722892761,-0.406441152095795,0.384125709533691],[0.691646099090576,-2.04802274703979,1.90720176696777],[1.03858840465546,0.110762983560562,0.181010514497757],[0.241835087537766,-0.947368204593658,0.572866976261139],[0.732968628406525,1.54111063480377,0.939433097839355],[0.866747319698334,1.52844226360321,1.55614900588989],[-1.26865291595459,0.88877147436142,-0.0924492031335831],[-0.666836678981781,-0.281862318515778,0.905202925205231],[-1.1610141992569,-0.696408569812775,-0.530259847640991],[-0.153708666563034,-0.0522901602089405,0.816808998584747],[-0.111779592931271,-0.566840589046478,-0.918172478675842],[-0.501122891902924,-0.398010015487671,-0.556933879852295],[-1.09242033958435,0.423862427473068,1.73986959457397],[-1.56327140331268,1.67689764499664,0.816190600395203],[-1.16939198970795,-0.371226012706757,-1.54395830631256],[0.00337247923016548,-1.60011804103851,-0.593609094619751],[1.46110951900482,-0.272063821554184,-0.183742359280586],[0.810955762863159,-0.193180277943611,-0.710700869560242],[1.15310704708099,-0.720360398292542,-0.544514834880829],[-1.6519877910614,1.23026168346405,-0.797797024250031],[-0.195459604263306,0.530743479728699,-0.488787591457367],[0.432829767465591,-1.57837474346161,-0.322996735572815],[0.313061416149139,1.19987833499908,0.74112868309021],[-0.726855576038361,-1.05141913890839,-0.612934768199921],[-1.23189723491669,-0.59289562702179,-2.01951003074646],[0.846161186695099,1.49640333652496,0.336020886898041],[1.00244140625,-0.0847744345664978,-0.498317211866379],[-2.09733152389526,-0.787423133850098,0.662958085536957],[0.0850024297833443,-1.91538739204407,-1.17619824409485],[-1.13326013088226,-0.037897065281868,-0.378150254487991],[1.25639867782593,-1.01290285587311,0.92069137096405],[0.656066060066223,0.371072500944138,-0.0539292469620705]],"colors":[[0,0,0,1]],"centers":[[-1.14845955371857,-0.574818193912506,-0.40946489572525],[1.07810950279236,1.10610842704773,-0.261390954256058],[0.0480128042399883,1.40470588207245,0.00267780432477593],[0.939406394958496,-0.0256817433983088,-1.37203705310822],[0.476963043212891,1.16989839076996,0.243978634476662],[-0.438928633928299,-0.0735140964388847,0.08036258071661],[1.56770730018616,0.413521260023117,-0.789747774600983],[0.165626272559166,-0.978567242622375,-0.0586722940206528],[-2.03259468078613,-0.401955425739288,0.30242931842804],[0.625439167022705,-0.21259905397892,-0.343976944684982],[1.0821487903595,-0.323164850473404,-1.6276193857193],[-1.19223213195801,1.34905326366425,1.52897119522095],[-1.07601702213287,-0.500983119010925,-0.778463125228882],[-1.16677951812744,0.787760555744171,1.04684007167816],[0.342589020729065,0.739052951335907,1.8105263710022],[-0.237016841769218,-0.950123012065887,-0.829546988010406],[-1.39198243618011,-0.434176981449127,0.382681518793106],[-0.951049864292145,-0.538266777992249,1.19694447517395],[-1.80852377414703,0.813056826591492,1.36451852321625],[1.57046473026276,-0.416037499904633,-0.449863284826279],[-0.325502008199692,-0.727457642555237,0.874775648117065],[-0.591384887695312,-0.347478806972504,-1.04379427433014],[0.181915476918221,1.59747040271759,-1.94616544246674],[0.0346886441111565,-0.432556211948395,-0.460609704256058],[0.176703736186028,0.903757631778717,-1.19473147392273],[-1.20270037651062,-0.513977646827698,-0.781144261360168],[-0.00774381915107369,-0.181857034564018,-0.160446599125862],[1.22791254520416,-1.29882526397705,-0.00134717777837068],[-0.608838319778442,1.58664655685425,1.58534300327301],[-0.227496445178986,-1.24173390865326,-1.83564388751984],[-0.863142371177673,1.2556825876236,-0.354070216417313],[0.0201448947191238,-0.0588362067937851,-0.238880053162575],[0.0352725088596344,-0.260354697704315,1.68263030052185],[-0.349790334701538,-0.10898768901825,-0.01140580419451],[-0.552731156349182,0.139877989888191,1.17509019374847],[1.19494390487671,-0.475424498319626,1.2042932510376],[-0.0789096727967262,0.00552108604460955,1.15833866596222],[0.534982919692993,0.847152054309845,1.5913782119751],[1.51066267490387,-0.664298832416534,-0.89135205745697],[-0.709565281867981,0.874232232570648,-0.833197832107544],[0.571943461894989,2.11811089515686,-0.144258975982666],[-0.513265609741211,-0.969527781009674,-1.39150512218475],[-0.888005256652832,0.563101649284363,0.103562548756599],[-0.549767196178436,-1.24878859519958,0.0940403044223785],[0.139321133494377,-0.0724726319313049,1.56665372848511],[0.254166305065155,0.478341460227966,-1.56802546977997],[2.36111259460449,-0.892570734024048,1.5838395357132],[0.60650372505188,-1.83770596981049,0.34175118803978],[0.0325226448476315,-0.464716792106628,1.07834577560425],[-0.592521727085114,-1.7854984998703,1.54721236228943],[-0.345925837755203,-1.68333923816681,0.775472462177277],[-1.70222210884094,-0.202328249812126,0.133027657866478],[0.28550723195076,-1.04869401454926,0.225133880972862],[0.675623774528503,-0.573635637760162,-0.513978958129883],[0.896490097045898,0.355710446834564,-0.0297206714749336],[-0.518660008907318,0.727806925773621,0.977886915206909],[-0.172901496291161,0.71920382976532,0.260729670524597],[-0.923082888126373,-0.761017560958862,0.0251538027077913],[0.801185548305511,1.5763486623764,-0.931991636753082],[-1.29571998119354,0.762841999530792,0.177333727478981],[0.105209283530712,-0.347063362598419,-1.76189303398132],[-0.864516139030457,0.199035286903381,-1.17911267280579],[-0.477634102106094,0.415416836738586,-0.4399334192276],[0.656216859817505,0.752322375774384,-0.509721994400024],[-0.634684324264526,0.882167160511017,-1.17193961143494],[-0.664959907531738,0.106365017592907,1.70757925510406],[-0.498177170753479,-0.192267239093781,1.23734831809998],[-0.0765142515301704,0.138710290193558,-0.956420421600342],[0.579342722892761,-0.406441152095795,0.384125709533691],[0.691646099090576,-2.04802274703979,1.90720176696777],[1.03858840465546,0.110762983560562,0.181010514497757],[0.241835087537766,-0.947368204593658,0.572866976261139],[0.732968628406525,1.54111063480377,0.939433097839355],[0.866747319698334,1.52844226360321,1.55614900588989],[-1.26865291595459,0.88877147436142,-0.0924492031335831],[-0.666836678981781,-0.281862318515778,0.905202925205231],[-1.1610141992569,-0.696408569812775,-0.530259847640991],[-0.153708666563034,-0.0522901602089405,0.816808998584747],[-0.111779592931271,-0.566840589046478,-0.918172478675842],[-0.501122891902924,-0.398010015487671,-0.556933879852295],[-1.09242033958435,0.423862427473068,1.73986959457397],[-1.56327140331268,1.67689764499664,0.816190600395203],[-1.16939198970795,-0.371226012706757,-1.54395830631256],[0.00337247923016548,-1.60011804103851,-0.593609094619751],[1.46110951900482,-0.272063821554184,-0.183742359280586],[0.810955762863159,-0.193180277943611,-0.710700869560242],[1.15310704708099,-0.720360398292542,-0.544514834880829],[-1.6519877910614,1.23026168346405,-0.797797024250031],[-0.195459604263306,0.530743479728699,-0.488787591457367],[0.432829767465591,-1.57837474346161,-0.322996735572815],[0.313061416149139,1.19987833499908,0.74112868309021],[-0.726855576038361,-1.05141913890839,-0.612934768199921],[-1.23189723491669,-0.59289562702179,-2.01951003074646],[0.846161186695099,1.49640333652496,0.336020886898041],[1.00244140625,-0.0847744345664978,-0.498317211866379],[-2.09733152389526,-0.787423133850098,0.662958085536957],[0.0850024297833443,-1.91538739204407,-1.17619824409485],[-1.13326013088226,-0.037897065281868,-0.378150254487991],[1.25639867782593,-1.01290285587311,0.92069137096405],[0.656066060066223,0.371072500944138,-0.0539292469620705]],"ignoreExtent":false,"flags":34816},"1448":{"id":1448,"type":"light","vertices":[[0,0,1]],"colors":[[1,1,1,1],[1,1,1,1],[1,1,1,1]],"viewpoint":true,"finite":false},"1447":{"id":1447,"type":"background","material":{},"colors":[[0.298039227724075,0.298039227724075,0.298039227724075,1]],"centers":[[0,0,0]],"sphere":false,"fogtype":"none","fogscale":1,"flags":32768},"1449":{"id":1449,"type":"background","material":{"lit":false,"back":"lines"},"colors":[[1,1,1,1]],"centers":[[0,0,0]],"sphere":false,"fogtype":"none","fogscale":1,"flags":32768},"1444":{"id":1444,"type":"subscene","par3d":{"antialias":8,"FOV":30,"ignoreExtent":false,"listeners":1444,"mouseMode":{"none":"none","left":"trackball","right":"zoom","middle":"fov","wheel":"pull"},"observer":[0,0,14.0180387496948],"modelMatrix":[[1,0,0,-0.131890535354614],[0,0.342020153999329,0.939692616462708,0.04078184440732],[0,-0.939692616462708,0.342020153999329,-13.9659023284912],[0,0,0,1]],"projMatrix":[[3.73205089569092,0,0,0],[0,3.73205089569092,0,0],[0,0,-3.86370325088501,-50.5334053039551],[0,0,-1,0]],"skipRedraw":false,"userMatrix":[[1,0,0,0],[0,0.342020143325668,0.939692620785909,0],[0,-0.939692620785909,0.342020143325668,0],[0,0,0,1]],"userProjection":[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],"scale":[1,1,1],"viewport":{"x":0,"y":0,"width":1,"height":1},"zoom":1,"bbox":[-2.09733152389526,2.36111259460449,-2.04802274703979,2.11811089515686,-2.01951003074646,1.90720176696777],"windowRect":[428,584,684,840],"family":"sans","font":1,"cex":1,"useFreeType":true,"fontname":"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/fonts/FreeSans.ttf","maxClipPlanes":6,"glVersion":2.1,"activeSubscene":0},"embeddings":{"viewport":"replace","projection":"replace","model":"replace","mouse":"replace"},"objects":[1449,1450,1448],"subscenes":[],"flags":35072}},"crosstalk":{"key":[],"group":[],"id":[],"options":[]},"width":480,"height":480,"context":{"shiny":false,"rmarkdown":null},"players":[],"webGLoptions":{"preserveDrawingBuffer":true}},"evals":[],"jsHooks":[]}if (interactive() || !.Platform\$OS == "unix") {
# Calculate a square in the middle of the display and plot it
square <- rgl.window2user(c(0.25, 0.25, 0.75, 0.75, 0.25),
c(0.25, 0.75, 0.75, 0.25, 0.25), 0.5)
par3d(ignoreExtent = TRUE)
lines3d(square)
par3d(ignoreExtent = FALSE)
}