# Position\_material (Translation and Rotation)

**URL:** <https://forums.sketchup.com/t/position-material-translation-and-rotation/297961>\
**Category:** Ruby API\
**Created:** [November 7, 2024, 7:20am UTC](https://forums.sketchup.com/t/position-material-translation-and-rotation/297961 "2024-11-07T07:20:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![medeek](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/medeek/32/10675_2.png) [@medeek](https://forums.sketchup.com/u/medeek)\
**Post date:** [November 7, 2024, 7:20am UTC](https://forums.sketchup.com/t/position-material-translation-and-rotation/297961/1 "2024-11-07T07:20:01Z")

</div>

The documentation on how exactly to use this method in the API seems a bit sparse to me or at least I’m not figuring it out very well.

In this particular case I am interested in using position\_material on horizontal faces in my group hence you will see that I use the normal vector for the faces of interest in my test code below.

I have been getting the pure translation to work, that one is easy with only two points:

```auto
# Pure Translation

				pt_array = []
				pt_array[0] = Geom::Point3d.new(@Flooring_offsetx,@Flooring_offsety,0)
				pt_array[1] = Geom::Point3d.new(0,0,0)

				face_list = group1.entities.grep(Sketchup::Face)
				mainfaces = face_list.find_all {|f| f.normal.parallel?(Z_AXIS)}
				for facei in mainfaces
					facei.material = @Flooring_mat
					facei.position_material(@Flooring_mat, pt_array, true)
				end

```

The one that is giving me problems is the pure rotation (eight points), it is rotating as expected but it is also scaling the material very small. Obviously I’m missing something here.

```auto
# Pure Rotation

			phi = @Flooring_rot.degrees
			
			pt_array = []

			pt_array[0] = Geom::Point3d.new(0,0,0)
			pt_array[1] = Geom::Point3d.new(0,0,0)

			xp2 = cos(phi)
			yp2 = sin(phi)
			pt_array[2] = Geom::Point3d.new(xp2,yp2,0)
			pt_array[3] = Geom::Point3d.new(1.0,0,0)

			xp3 = cos(phi) - sin(phi)
			yp3 = sin(phi) + cos(phi)
			pt_array[4] = Geom::Point3d.new(xp3,yp3,0)
			pt_array[5] = Geom::Point3d.new(1.0,1.0,0)

			xp4 = -sin(phi)
			yp4 = cos(phi)
			pt_array[6] = Geom::Point3d.new(xp4,yp4,0)
			pt_array[7] = Geom::Point3d.new(0,1.0,0)

			face_list = group1.entities.grep(Sketchup::Face)
			mainfaces = face_list.find_all {|f| f.normal.parallel?(Z_AXIS)}
			for facei in mainfaces
				facei.material = @Flooring_mat
				facei.position_material(@Flooring_mat, pt_array, true)
			end

```

I do not want any scaling, just rotation.

---

<div class="post-metadata">

**Author:** ![medeek](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/medeek/32/10675_2.png) [@medeek](https://forums.sketchup.com/u/medeek)\
**Post date:** [November 7, 2024, 9:18am UTC](https://forums.sketchup.com/t/position-material-translation-and-rotation/297961/2 "2024-11-07T09:18:06Z")

</div>

I’m comparing what I have here with what Thomas @tt_su is doing here and my math seems to be correct:

> [@Rotating Texture/Material of a Face](https://forums.sketchup.com/t/rotating-texture-material-of-a-face/204566/8):
>
> One thing that might help is to study the Position Texture tool - observe how the texture pins are placed on the surface of the face. [position\_material] model = Sketchup.active\_model model.active\_entities.clear! texture\_path = Sketchup.find\_support\_file('/Materials/Brick, Cladding and Siding/Brick Colored Blue.skm') material = model.materials.load(texture\_path) points = [ # World space coordinates Geom::Point3d.new( 0, 0, 0), Geom::Point3d.new(1.m, 0, 0), Geom::Point3d.new(1.m, …

The scaling is shrinking my texture down by 48X, which also coincides with the size of my material, something is going on here.

---

<div class="post-metadata">

**Author:** ![medeek](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/medeek/32/10675_2.png) [@medeek](https://forums.sketchup.com/u/medeek)\
**Post date:** [November 7, 2024, 9:53am UTC](https://forums.sketchup.com/t/position-material-translation-and-rotation/297961/3 "2024-11-07T09:53:52Z")

</div>

This seems to do the trick but maybe there is a better way to accomplish the same thing:

```auto
# Pure Rotation

			twidth = @Flooring_mat.texture.width
			theight = @Flooring_mat.texture.height

			phi = @Flooring_rot.degrees
			
			pt_array = []

			pt_array[0] = Geom::Point3d.new(0,0,0)
			pt_array[1] = Geom::Point3d.new(0,0,0)

			xp2 = twidth * cos(phi)
			yp2 = twidth * sin(phi)
			pt_array[2] = Geom::Point3d.new(xp2,yp2,0)
			pt_array[3] = Geom::Point3d.new(1.0,0,0)
 
			xp3 = twidth * cos(phi) - theight * sin(phi)
			yp3 = twidth * sin(phi) + theight * cos(phi)
			pt_array[4] = Geom::Point3d.new(xp3,yp3,0)
			pt_array[5] = Geom::Point3d.new(1.0,1.0,0)

			xp4 = -theight * sin(phi)
			yp4 = theight * cos(phi)
			pt_array[6] = Geom::Point3d.new(xp4,yp4,0)
			pt_array[7] = Geom::Point3d.new(0,1.0,0)

			face_list = group1.entities.grep(Sketchup::Face)
			mainfaces = face_list.find_all {|f| f.normal.parallel?(Z_AXIS)}
			for facei in mainfaces
				facei.material = @Flooring_mat
				facei.position_material(@Flooring_mat, pt_array, true)
			end

```

---

<div class="post-metadata">

**Author:** ![medeek](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/medeek/32/10675_2.png) [@medeek](https://forums.sketchup.com/u/medeek)\
**Post date:** [November 7, 2024, 10:02am UTC](https://forums.sketchup.com/t/position-material-translation-and-rotation/297961/4 "2024-11-07T10:02:55Z")

</div>

Translation and a Rotation:

```auto
# Translation and Rotation

				x1 = @Flooring_offsetx
				y1 = @Flooring_offsety

				twidth = @Flooring_mat.texture.width
				theight = @Flooring_mat.texture.height

				phi = @Flooring_rot.degrees
			
				pt_array = []

				pt_array[0] = Geom::Point3d.new(x1,y1,0)
				pt_array[1] = Geom::Point3d.new(0,0,0)

				xp2 = twidth * cos(phi) + x1
				yp2 = twidth * sin(phi) + y1
				pt_array[2] = Geom::Point3d.new(xp2,yp2,0)
				pt_array[3] = Geom::Point3d.new(1.0,0,0)

				xp3 = twidth * cos(phi) - theight * sin(phi) + x1
				yp3 = twidth * sin(phi) + theight * cos(phi) + y1
				pt_array[4] = Geom::Point3d.new(xp3,yp3,0)
				pt_array[5] = Geom::Point3d.new(1.0,1.0,0)

				xp4 = -theight * sin(phi) + x1
				yp4 = theight * cos(phi) + y1
				pt_array[6] = Geom::Point3d.new(xp4,yp4,0)
				pt_array[7] = Geom::Point3d.new(0,1.0,0)

				face_list = group1.entities.grep(Sketchup::Face)
				mainfaces = face_list.find_all {|f| f.normal.parallel?(Z_AXIS)}
				for facei in mainfaces
					facei.material = @Flooring_mat
					facei.position_material(@Flooring_mat, pt_array, true)
				end

```

---

<div class="post-metadata">

**Author:** ![dezmo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/dezmo/32/51058_2.png) [@dezmo](https://forums.sketchup.com/u/dezmo)\
**Post date:** [November 7, 2024, 11:10am UTC](https://forums.sketchup.com/t/position-material-translation-and-rotation/297961/5 "2024-11-07T11:10:01Z")

</div>

Thanks a lot for sharing!

Just an advice how to make your code more readable (colorized) in a forum:

When you insert your code use the `ruby` keyword after the first 3 ```  
😉  
 ![colorizecode](https://global.discourse-cdn.com/sketchup/original/3X/1/a/1ae01790ce582e80b82adef4800cb963a722ee41.gif)

---

<div class="post-metadata">

**Author:** ![JackyM](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@JackyM](https://forums.sketchup.com/u/JackyM)\
**Post date:** [August 29, 2025, 3:58pm UTC](https://forums.sketchup.com/t/position-material-translation-and-rotation/297961/6 "2025-08-29T15:58:40Z")

</div>


