Jump to content

Getting a Cube's Corners


Shymus Roffo
 Share

You are about to reply to a thread that has been inactive for 3017 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello,

I've been working on creating something that requires the use of the corners of the prim instead of the center. I'm not very good with math, all my attempts have failed. The best success i had was getting the prim's diagonal. However, if i get the diagonal of the prim, i need the diagonal line's end points.

Here's what i'm trying to do. The green points inside the square are the prim's points that i need to get.



The Cube is 50 x 50. It is placed randomly in the world. The intentions are to be able to size the cube randomly and be able to get the positions of the cube or rectangle's corners or the end positions of the diagonal (Red Line).

As i have said, all attempts have failed and it has upset me. All attempts used the Pythygorean's Theroem as that is all the information i could find on the internet that was similar to what i was looking for.

Thank you!

Link to comment
Share on other sites

Imagine a cube that is 1 meter on a side. The angle at any corner is a right angle, and the diagonal of any face is the hypotenuse of a triangle with a length equal to the square root of 1x1+1x1 = sqrt(2) = 1.414 .  Now consider the triangle that has one side as the cube' s body diagonal. The other two sides must be a face diagonal and one of the cube edges. That is, it has one side that is 1 meter long and another that is 1.414 meters. The length of the body diagonal ... the hypotenuse ... is the square root of 1x1 + 1.414 x 1.414 = sqrt (3) = 1.732 . Half of that is the distance from any corner of the cube to its center. Voila, as they say, or maybe Q.E.D.

Link to comment
Share on other sites

I'm not really understanding that much. I probably forgot to elloborate a bit, i need to place a prim in the region based on the position of those corners.

My intentions is to be able to make a map via PHP's GD library. Since it takes two corners to draw a rectangle, i need a way to get those corner's positions without having to use seperate cubes.

 

Link to comment
Share on other sites

Barring the use of Pythygorean's Theroem, there is another simple way to know the exact position of a cube's corners. If you understand the layout of a region (256 meters x 256 meters) then all you have to know is the Center position of the cube and the size of the cube to know where it's corners are. You just add or subtract HALF the size of the cube, depending on which way you are going on the 0-256 grid layout. For example; if a 50 meter cube is at 128 x 128 on the region , then the corners must be at 103 x 103/103 x 153/153 x 103/ and 153x153 (minus or plus 25 from/to 128). This will only work if the cube is at 0, 90, 180, or 270 Degrees. There is also a way you can know exact corner positions even if the cube is rotated at an odd angle. First, mark the angle of the cube, turn the cube to 0, 90, 180, or 270 Degrees and then find what size it is. Use the first method i suggest to determine the location of the corners. Then use a smaller prim on top of the cube in that corner's position. Do all corners and then turn the cube back to it's original angle. When you get the position of the 4 smaller cubes you will have the position of the large cube's corners.   

   

Link to comment
Share on other sites

Well, i tried that. Without any luck. For some reason the diagonal thing doesn't seem to work. It keep to much of a distance away from the prim.

These scripts show what i used to test the placement of markers. There are two markers and a square.

My attempt is to get the to markers to stay attached to the corners of the base square or rectangle.

 

Square / Rectangle

default {    state_entry() {        llSetTimerEvent(1);    }    timer() {        vector scale = llGetScale();        float hyp = llSqrt(scale.x * scale.x + scale.y * scale.y);        float distance_from_center = llSqrt(scale.y * scale.y + hyp * hyp) / 2;        vector pos = llGetPos();        llSay(1,(string)<pos.x - distance_from_center,pos.y - distance_from_center,pos.z>); // Southwest Corner        llSay(2,(string)<pos.x + distance_from_center,pos.y + distance_from_center,pos.z>); //Northeast Corner    }}

Marker 1 & 2

default{    state_entry() {        llListen(1,"","","");        //llListen(2,"","","");    }    listen(integer c, string n, key i, string m) {        if(llGetOwnerKey(i) == llGetOwner()) {            llSetPos((vector)m);        }    }}

The size of the marker does not matter as long as the center position of it is directly on the corner.

I may just not be understanding what you are writing about the theory. I'm not the best at understanding Math.

Thank you!

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3017 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...