Why is the transformation matrix not the identity matrix? - processing

Trying to grok the transformation matrices in Processing Python Mode.
Dirt simple program that never transforms anything
def setup():
print("original matrix ".format())
printMatrix()
size(200, 200, P3D)
print("after-size matrix ".format())
printMatrix()
line(10,30,90,50)
resetMatrix()
print("after resetMatrix()".format())
printMatrix()
I was expecting the same output throughout the script:
1.0000 0.0000 0.0000 0.0000
0.0000 1.0000 0.0000 0.0000
0.0000 0.0000 1.0000 0.0000
0.0000 0.0000 0.0000 1.0000
But instead, the initial transformation matrix isn't an identity matrix -- it has some extra small values in the fourth column. Until I resetMatrix() I don't get the identity matrix that I expected.
original matrix
001.0000 000.0000 000.0000 -100.0000
000.0000 001.0000 000.0000 -100.0000
000.0000 000.0000 001.0000 -173.2051
000.0000 000.0000 000.0000 001.0000
after-size matrix
001.0000 000.0000 000.0000 -100.0000
000.0000 001.0000 000.0000 -100.0000
000.0000 000.0000 001.0000 -173.2051
000.0000 000.0000 000.0000 001.0000
after resetMatrix()
1.0000 0.0000 0.0000 0.0000
0.0000 1.0000 0.0000 0.0000
0.0000 0.0000 1.0000 0.0000
0.0000 0.0000 0.0000 1.0000

Related

Can i use sklearn IterativeImputer to fill in missing categorical data?

I have a dataset of categorical and continuos features and a lot of them have missing elements. I was wondering if i can use the respective imputer to fill out continuos as well as categorical data.
And if it cant be done, what would be the best way to proceed? Would it be best to separate the data into continuos and discrete features and then use, for example, IterativeImputer for the first set and KNN for the second one and then merge them?
Any help would be appreciated.
The data consists of 65 features:
x_train
age sex painloc painexer relrest cp trestbps htn chol smoke ... om1 om2 rcaprox rcadist lvx1 lvx2 lvx3 lvx4 lvf cathef
288 -1.109572 1.0 0.0 0.0 0.0 1.0 -0.655059 0.0 0.818661 NaN ... NaN NaN NaN NaN 1.0 1.0 1.0 1.0 2.0 0.568676
283 -0.180525 1.0 1.0 0.0 0.0 2.0 1.447445 0.0 -0.040919 NaN ... NaN NaN NaN NaN 1.0 1.0 1.0 1.0 1.0 NaN
230 -0.077297 1.0 1.0 1.0 0.0 3.0 0.659006 1.0 2.872604 NaN ... 2.0 NaN 2.0 NaN 1.0 1.0 1.0 1.0 1.0 NaN
380 -0.799890 0.0 1.0 1.0 1.0 4.0 -0.129433 0.0 0.339106 NaN ... NaN NaN NaN NaN 1.0 1.0 1.0 1.0 1.0 NaN
147 0.129157 1.0 1.0 1.0 1.0 4.0 NaN 0.0 0.031467 0.0 ... 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 -0.822164
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
847 -0.180525 0.0 NaN NaN NaN 3.0 0.185942 1.0 -0.040919 NaN ... 1.0 NaN 1.0 1.0 1.0 1.0 1.0 1.0 1.0 NaN
301 -0.283752 1.0 1.0 1.0 1.0 4.0 -0.129433 0.0 -0.194738 NaN ... NaN NaN NaN NaN 1.0 1.0 1.0 1.0 1.0 NaN
693 0.645295 1.0 NaN NaN NaN 4.0 -0.392246 1.0 0.520070 NaN ... 1.0 NaN 2.0 1.0 1.0 1.0 1.0 1.0 1.0 NaN
115 1.058204 1.0 1.0 1.0 1.0 4.0 NaN 0.0 0.954384 0.0 ... 1.0 1.0 2.0 1.0 1.0 1.0 1.0 1.0 1.0 -0.811925
155 1.574341 1.0 1.0 1.0 1.0 4.0 NaN 1.0 NaN 0.0 ... 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 NaN
I have standarized the continuos variables.
There are many categorical features like 'painloc' a 'painexer' that have missing values, and there are also continous ones like 'age' (i decided to treat it as continuous) and 'chol' that also have missing elements.
I tried using IterativeImputer:
x_mice=x_train
mice_impute = IterativeImputer(sample_posterior=True)
x_mice=pd.DataFrame(mice_impute.fit_transform(x_mice))
x_mice.columns=labels
x_mice
age sex painloc painexer relrest cp trestbps htn chol smoke ... om1 om2 rcaprox rcadist lvx1 lvx2 lvx3 lvx4 lvf cathef
0 1.049449 1.0 1.000000 1.000000 1.000000 4.0 0.444874 0.000000 0.540723 0.000000 ... 1.000000 1.000000 2.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 -0.891887
1 0.505617 1.0 1.000000 1.000000 0.000000 2.0 -0.266785 0.000000 -1.752150 0.000000 ... 1.000000 1.000000 2.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 -0.888760
2 0.831916 1.0 1.000000 0.000000 0.000000 4.0 -1.080109 0.764037 -1.752150 1.450166 ... 1.000000 1.000000 1.000000 1.000000 1.025761 0.879404 -0.400332 3.193691 3.267492 1.118696
3 -0.582047 1.0 1.000000 0.000000 0.000000 2.0 -1.588436 0.000000 -0.249794 0.000000 ... 1.383778 1.048614 -0.147575 1.942328 1.000000 1.000000 1.000000 1.000000 1.000000 0.802084
4 -1.452178 1.0 1.000000 0.000000 0.000000 3.0 0.444874 1.000000 5.232542 1.000000 ... 1.235595 1.249215 2.269437 1.155985 1.000000 1.000000 1.000000 1.000000 1.000000 -1.935223
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
624 0.179318 1.0 1.000000 1.000000 1.000000 4.0 -0.571781 0.000000 0.628910 -0.060307 ... 0.928614 0.830982 1.080936 1.185430 1.000000 1.000000 1.000000 1.000000 1.000000 -1.032691
625 1.702047 1.0 1.000000 0.000000 1.000000 3.0 0.444874 0.000000 -1.752150 0.000000 ... 1.000000 1.000000 2.000000 1.000000 1.000000 1.000000 1.000000 1.000000 2.000000 -0.895014
626 -0.364514 1.0 0.694690 1.738101 0.396025 4.0 0.953201 1.000000 0.390804 1.287500 ... 1.000000 0.739708 2.000000 1.000000 1.000000 1.000000 1.000000 1.000000 2.000000 -0.523902
627 0.723149 1.0 0.762459 0.038032 0.315826 4.0 0.444874 1.000000 0.831741 0.750375 ... 1.000000 0.912221 2.000000 1.000000 1.000000 1.000000 1.000000 1.000000 2.000000 0.730936
628 0.940682 1.0 1.000000 1.000000 1.000000 4.0 -0.000217 0.000000 -0.252964 0.000000 ... 1.000000 1.000000 2.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 -0.888134
It works fine for continuos features but not for categorical as it can fill in a decimal number and thats obviously not right.

How to apply a texture on a mesh exported from blender as wrl and imported into threejs using VRMLLoader

I have exported a simple box mesh from blender as wrl. I have "smart uv unwrap"ed the mesh also. I am using this mesh only for it's geometry and am applying material through threejs. I am then binding a texture with the imported mesh, and i am also setting the needsUpdate property of material (MeshPhongMaterial) to true.
The result is as follows :
The applied texture :
The code excerpts are as follows :
function generateCustomTHREEMeshFromWRL(name) {
return vrmlLoader.parse(getResource(name).content).children[0]
//the getResource(name).content returns the entire wrl file content
}
mesh = generateCustomTHREEMeshFromWRL('unwrapped.wrl')
mesh.material.map = textureLoader.load('lavatile.jpg')
mesh.material.needsUpdate = true;
scene.add(mesh)
The WRL file is as follows :
#VRML V2.0 utf8
#modeled using blender3d http://blender.org
# 'Cube'
Shape {
appearance Appearance {
material Material {
}
}
geometry IndexedFaceSet {
coord Coordinate {
point [ -1.000000 -1.000000 1.000000 -1.000000 -1.000000 -1.000000 1.000000 -1.000000 -1.000000 1.000000 -1.000000 1.000000 -1.000000 1.000000 0.999999 -0.999999 1.000000 -1.000001 1.000000 1.000000 -1.000000 1.000000 1.000000 1.000000 ]
}
colorPerVertex FALSE
color Color {
color [ 0.80 0.80 0.80 ]
}
colorIndex [ 0 0 0 0 0 0 0 0 0 0 0 0 ]
coordIndex [ 1 3 0 -1 7 5 4 -1 4 1 0 -1 5 2 1 -1 2 7 3 -1 0 7 4 -1 1 2 3 -1 7 6 5 -1 4 5 1 -1 5 6 2 -1 2 6 7 -1 0 3 7 -1 ]
}
}
This is a glimpse of the actions I am performing in blender

OBJMTLLoader() not transparent .png in model

I have read a lot of questions and articles about this issue, but anyway png images for models are not transparent. Instead it has white background. Like:
three.js: how to apply alpha-map when using OBJMTL loader?
Assigning Alpha channels to OBJ/MTL model meshes
Three.js png texture - alpha renders as white instead as transparent
Maybe someone has ideas how to fix it and what code to add?
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
var loader = new THREE.OBJMTLLoader();
loader.crossOrigin = 'anonymous';
loader.load( 'model.obj', 'model.mtl', function ( object ) {
object.position.set(0, 0, 0);
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.castShadow = true;
child.receiveShadow = true;
}
if ( child.material instanceof THREE.MeshPhongMaterial ) {
child.material.opacity = 1;
// child.material.alphaTest = 0.5;
// child.material.depthWrite = false;
// child.material.depthTest = false;
// child.material.side = THREE.BackSide;
child.material.transparent = true;
}
});
scene.add(object);
});
model.mtl:
newmtl Cap
Ns 37.6553
Ni 1.5000
d 0.9990
Tr 0.0010
Tf 0.9990 0.9990 0.9990
illum 2
Ka 0.7333 0.7333 0.7333
Kd 1.0000 1.0000 1.0000
Ks 0.0980 0.0980 0.0980
Ke 0.0000 0.0000 0.0000
map_Kd Cap_01.png
map_bump Cap_01_Normal.png
bump Cap_01_Normal.png
newmtl Bark
Ns 37.6553
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 0.7333 0.7333 0.7333
Kd 1.0000 1.0000 1.0000
Ks 0.0980 0.0980 0.0980
Ke 0.0000 0.0000 0.0000
map_Kd BroadleafBark.png
map_bump BroadleafBark_Normal.png
bump BroadleafBark_Normal.png
newmtl Leaves
Ns 37.6553
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 0.7647 0.7647 0.7647
Kd 1.0000 1.0000 1.0000
Ks 0.4118 0.4118 0.4118
Ke 0.0000 0.0000 0.0000
map_Kd BroadleafLeaves.png
map_Ks BroadleafLeaves_Spec.png
map_d BroadleafLeaves_Alpha.png
map_bump BroadleafLeaves_Normal.png
bump BroadleafLeaves_Normal.png
Finally! I found solution. I have converted .obj to .js loader with authors of threejs python script (How to convert object to json file for three.js model loader) and then use JSONLoader():
var loader = new THREE.JSONLoader();
loader.load('model.js', function(geometry, materials) {
var material = new THREE.MeshFaceMaterial(materials);
var object = new THREE.Mesh(geometry, material);
...

three.js: how to apply alpha-map when using OBJMTL loader?

Actually I am trying to upload these .obj and .mtl file by OBJMTLloader. all is working fine but the image in mtl file is loaded by map_d is not uploaded.
newmtl Eyelashes
Ns 10.0000
Ni 1.5000
d 0.5000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 0.5880 0.5880 0.5880
Kd 0.5880 0.5880 0.5880
Ks 0.0000 0.0000 0.0000
Ke 0.0000 0.0000 0.0000
map_Ka EyelashesDiffuseTexture.jpg
map_Kd EyelashesDiffuseTexture.jpg
map_d EyeLashes_Opacity_Texture.jpg
My code is
var loader = new THREE.OBJMTLLoader();
loader.load( 'upload/model.obj', 'upload/model.mtl', function ( object ) {
object.position.y = -35;
scene.add( object );
} );
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
What i need to change in my code.
I try so may example and checked so many answers but not get helpful answer.
Now three.js supports alpha maps. But you need change MTLLoaded.js. Add to createMaterial_
case 'map_d':
// Alpha texture map
params[ 'alphaMap' ] = this.loadTexture( this.baseUrl + value );
params[ 'transparent' ] = true;
break;
three.js r.74
three.js does not support alpha-maps in any of its materials.
The work-around is to bake the alpha-map into the alpha-channel of the diffuse map.
three.js r.66

Animating With Gloss in Haskell

Here's my code for a little pattern that looks something like this. (Not the most efficient code I know). Now, I want to make stars rotate using animate. but I'm not sure how to use display and animate together in one program. Any help would be appreciated. Thanks.
import Graphics.Gloss
main = display (InWindow "Gloss" (700,700) (0,0))
black (picture 100)
picture :: Float -> Picture
picture 0 = text "Value cannot be 0"
picture number = scale 6.5 6.5 (color rose $ drawpicture number)
orangered, orangered2, orangered3 :: Color
orangered = makeColor 1.0 0.251 0.0 0.7
orangered2 = makeColor 1.0 0.251 0.0 0.5
orangered3 = makeColor 1.0 0.251 0.0 0.3
intervalsmall = [0,11.25,22.5,33.75,45,56.25,67.5,78.75]
intervalbig = [0,22.5,45,67.5,90,112.5,135,157.5,180,202.5,225,247.5,270,292.5,315,337.5]
xlist = [2,4..50]
ylist = [0,2..48]
squares = pictures[rotate x (line [(-50,0),(0,50),(50,0),(0,-50),(-50,0)]) | x <- intervalsmall]
stars = pictures[rotate x ((pictures [line [(-8.5,0),(0,50),(8.5,0)],line[(0,50),(0,0)]])) | x <- intervalbig]
grid = pictures[line [(0,y),(x,50)] | x <- xlist, y <- ylist, x-y==2]
insidegrid = pictures[
translate 0 (-50) grid,
rotate 90 (translate 0 (-50) grid),
rotate 180 (translate 0 (-50) grid),
rotate 270 (translate 0 (-50) grid)]
drawpicture :: Float -> Picture
drawpicture number = pictures [
color red (pictures [circle 50,circle 8.5]),
line [(-50,-50),(-50,50),(50,50),(50,-50),(-50,-50)],
squares,
scale 0.7 0.7 squares,
scale 0.49 0.49 squares,
scale 0.347 0.347 squares,
scale 0.242 0.242 squares,
color orange stars,
color orange (scale 0.178 0.178 stars),
rotate 11.25 (scale 0.178 0.178 stars),
translate (-50) 0 grid,
rotate 90 (Translate (-50) 0 grid),
rotate 180 (Translate (-50) 0 grid),
rotate 270 (Translate (-50) 0 grid),
color orangered insidegrid,
color orangered2 (rotate 45 insidegrid),
color orangered3 (rotate 22.5 insidegrid),
color orangered3 (rotate 67.5 insidegrid)
]
It's easier if you have separate draw functions for each visual element, but the basic answer is: to animate it just use the animate function and rotate the image components you desire to "move":
import Graphics.Gloss
main = animate (InWindow "Gloss" (700,700) (0,0))
black picture
picture :: Float -> Picture
picture 0 = text "Value cannot be 0"
picture number = scale 6.5 6.5 (color rose $ drawpicture number)
orangered, orangered2, orangered3 :: Color
orangered = makeColor 1.0 0.251 0.0 0.7
orangered2 = makeColor 1.0 0.251 0.0 0.5
orangered3 = makeColor 1.0 0.251 0.0 0.3
intervalsmall = [0,11.25,22.5,33.75,45,56.25,67.5,78.75]
intervalbig = [0,22.5,45,67.5,90,112.5,135,157.5,180,202.5,225,247.5,270,292.5,315,337.5]
xlist = [2,4..50]
ylist = [0,2..48]
squares = pictures[rotate x (line [(-50,0),(0,50),(50,0),(0,-50),(-50,0)]) | x <- intervalsmall]
stars = pictures[rotate x ((pictures [line [(-8.5,0),(0,50),(8.5,0)],line[(0,50),(0,0)]])) | x <- intervalbig]
grid = pictures[line [(0,y),(x,50)] | x <- xlist, y <- ylist, x-y==2]
insidegrid = pictures[
translate 0 (-50) grid,
rotate 90 (translate 0 (-50) grid),
rotate 180 (translate 0 (-50) grid),
rotate 270 (translate 0 (-50) grid)]
rotVal :: Float -> Float
rotVal x = x - (x / (2*pi))
drawpicture :: Float -> Picture
drawpicture number = pictures [
rot $ color red (pictures [circle 50,circle 8.5]),
line [(-50,-50),(-50,50),(50,50),(50,-50),(-50,-50)],
rot $ squares,
rot $ scale 0.7 0.7 squares,
rot $ scale 0.49 0.49 squares,
rot $ scale 0.347 0.347 squares,
rot $ scale 0.242 0.242 squares,
rot $ color orange stars,
rot (color orange (scale 0.178 0.178 stars)),
rot (rotate 11.25 (scale 0.178 0.178 stars)),
translate (-50) 0 grid,
rotate 90 (Translate (-50) 0 grid),
rotate 180 (Translate (-50) 0 grid),
rotate 270 (Translate (-50) 0 grid),
rot $ color orangered insidegrid,
rot $ color orangered2 (rotate 45 insidegrid),
rot $ color orangered3 (rotate 22.5 insidegrid),
rot $ color orangered3 (rotate 67.5 insidegrid)
]
where rot = rotate (rotVal number)
It is too much to write out all for you but you just have to add another argument to your picture function that is a Float and represents time. So display would be replaced by animate. So.
main = animate (InWindow "Gloss" (700,700) (0,0))
black (picture 100)
picture :: Float -> Float -> Picture
picture number time = -- whatever you have to do
You'll have to change your helping drawing functions to take this time param. Let's say you want to rotate the whole think once ever 5 seconds you can just multiply this time coming in and get an angle angle = time*(pi*2/5) then you can use this angle for trig functions to calculate new x and y positions from the center.

Resources