Jump to content

# Finding center of surface of a cube

## Recommended Posts

Hey there, was wondering whether anyone has some ideas to share about the best way to find the region coordinates of the center of the surface of a prim (cube, cuboid, pyramid, other regular shaped prims)

Thanks

#### Share this post

##### Share on other sites

I don't know if there's a single easy way that would work for every shape, but for cubes and a few others I think it wouldn't be hard. You can get the position of the object center, and add half the size to find the center of each side (rotated if neccesary).

#### Share this post

##### Share on other sites

Well, a cube is simple enough.  I can't pop in world to field test this, but it looks right (unless I got the face numbering wrong)...

`vector Face_Ctr(integer face){	vector Size = llGetScale();	float x = 0.5*Size.x;	float y = 0.5*Size.y;	float z = 0.5*Size.z;	list Axis = [<0.0,0.0,z>,<0.0,y,0.0>,<x,0.0,0.0>,<0.0,-y,0.0>,<-x,0.0,0.0>,<0.0,0.0,-z>];	vector Ctr = llGetPos() + llList2Vector(Axis,face)*llGetRot();	return Ctr;}default{	touch_start(integer num)	{		integer Face = llDetectedTouchFace(0);		llSay(0,"The center of face " + (string) Face + " is at "+ (string) Face_Ctr(Face));	}}`

If that works, you ought to be able to do some simple geometry and work out ways to generate the list Axis for any regular solids.  Once you start twisting, skewing, slicing or otherwise torturing them, of course, all bets are off.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

×
×
• Create New...