calculate Vector3 offset relative to surface normal

Hi !
I’m trying to calculate four relative points from a raycast hit point, according to the face normal that was hit.

Now the offsets in the code are obviously wrongly hardcoded, just to show the intended result, but of course it just works on the plane.
I guess what i need, is some trig calculation based on hit.normal to keep the red marked offsets at the same distance from center, according to the face normal that was hit.

function Update () 
{
	var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	var hit : RaycastHit;
	
		if (Physics.Raycast (ray, hit))
		{
		Debug.DrawRay(hit.point, hit.normal, Color.green);
		
		Debug.DrawRay(hit.point+Vector3(1,0,1), hit.normal*2, Color.red);
		Debug.DrawRay(hit.point+Vector3(-1,0,1), hit.normal*2, Color.red);
		Debug.DrawRay(hit.point+Vector3(-1,0,-1), hit.normal*2, Color.red);
		Debug.DrawRay(hit.point+Vector3(1,0,-1), hit.normal*2, Color.red);
		}
}

I can think of a dirty solution like:

  • creating a dummy plane, and keeping it centered to the
    raycast hit point
  • adjusting it’s size to match the
    desired distance (the red offsets)
  • aligning it with the surface normal
    it is on
  • then picking my
    surface-orientation-relative points
    from the plane i’m using

But i’m actually more interested in understanding the trig that has been passing over my head in the last few days, or even some transformation function I may have missed from the documentation.
So, i would really appreciate any hint! Thanks !

There are a lot of different ways of solving this problem. One issue is that you have a degree of freedom here you did not define. That is the four red lines may be rotate to any arbitrary angle with the green normal as the axis. If you don’t care about that rotation, then a really simple approach is to use an empty game object (with a scale of (1,1,1)). Then you can do:

empty.transform.position = hit.point;
transform.up = hit.normal;
var pos1 = empty.transform.TransformPoint(Vector3(1,0,1));
var pos2 = empty.transform.TransformPoint(Vector3(-1,0,1));
var pos3 = empty.transform.TransformPoint(Vector3(-1,0,-1));
var pos4 = empty.transform.TransformPoint(Vector3(1,0,-1));