# Align a plane with 3 normal

I have a region with 3 normals and now I want to align a plane in this region. The two shown in the picture and one perpendicular facing up (created with pca, but that doesent matter)

```
GameObject Gplane = GameObject.CreatePrimitive(PrimitiveType.Plane);
Transform t = Gplane.transform;
t.position = segment.middle;
t.localScale = new Vector3((2*segment.dist_pc1)/10, 0, (2*segment.dist_pc2)/10);
t.rotation = Quaternion.FromToRotation(Vector3.right, segment.middle - segment.pc1);
t.rotation *= Quaternion.FromToRotation(Vector3.forward, segment.middle - segment.pc2);
t.rotation *= Quaternion.FromToRotation(Vector3.up, segment.normal)
```

I create a newgameobject from primitivetype plane. get transform and set its position and scale (segment is a object which contains all information about this region). Then I want to align the plane with the three normal, each rotation works fine and aligns the plane with the axis, but multiplied its messed up. As you can see the plane is kind of between the two normals (blue and red, which you can hardly see but i am sure you can image) Any advice in what i am doing wrong is appreciated since i am not too familiar with quaternions and rotations. Thanks in advance.

**Answer** by Dvergar
·
Mar 19, 2018 at 02:44 PM

After digging some more I found a working solution.

Instead of calclating the angle one can set the right, forward und up vector of any transform. This will do rotation automatically

```
t.right = segment.pc1
```

But since the vector is rotated by itself (Vector3, two defining position in space, the third may let the vector rotate around itself) the plane may be rotated around the this axis (and t.forward is not alinged with segment.pc2) To fix this i calculated the angle between t.forward and segment.pc2

```
float angle = Vector3.Angle(t.forward, segment.pc2);
t.RotateAround(segment.middle, t.right, - angle);
```

RotateAround allowed me to keep the axis that was already set and correct.

I tried to align a plane with two vector3 that is facing in the corresponding directions of the two vectors. Maybe this can help anybyody.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Rotate around local Y axis using Joystick Vector3 0 Answers

Smooth card rotation with Quaternion not doing anything 1 Answer

align object with collision normal then look at an object on one axis 0 Answers

How to limit only one axis rotation? c# 1 Answer

How can I fix rotation of Z axis to 0? 0 Answers