Hello,

I do not know where to post math questions so excuse me if this is the wrong sub.

can anyone give me a quick lesson on how to calculate the point in the picture?

Much appreciated.

(The purple arrow is the transform.forward vector)

Hello,

I do not know where to post math questions so excuse me if this is the wrong sub.

can anyone give me a quick lesson on how to calculate the point in the picture?

Much appreciated.

(The purple arrow is the transform.forward vector)

Let me make sure Iâ€™m understanding this diagram correctly. Are you trying to get the point at which the forward of the transform intersects with the ground plane?

If so, then you can just raycast against a Plane:

```
var plane = new Plane( Vector3.up, Vector3.zero );
var ray = new Ray( transform.position, transform.forward );
float d;
plane.Raycast( ray, out d );
var pointOnPlane = ray.GetPoint( d );
```

I am hoping to get a view on how would it be achieved using only trigonometric functions instead of using planes and rays.

Thanks anyway

Use `TransformDirection()`

. Something like this:

```
float distance = 3.5f;
Vector3 forwardWorldPos = Camera.transform.TransformDirection(transform.forward * distance);
```

Thatâ€™ll project a local vector out by x distance then let TransformDirection() convert it to a world position.

*edit*

sorry didnâ€™t fully understand your question because the picture wasnâ€™t totally clear to me where the purple thing was pointing.

Hereâ€™s a link that explains how to solve for these types of things.

these are really good and I believe someone will find them useful but I am really interested only in the math part of the problem, I have the implementation covered.

Thanks for the link to the math site LaneFox, Iâ€™ll check it out

There is not enough information for a trigonometric interpretation. There is no way to determine any angles from the picture, as was previously mentioned. It could be pointing anywhere.

Thereâ€™s certainly enough information to determine a trigonometric solution. For this purpose I am going to use my own labeled version of the diagram for clarity:

First we need to find theta. You can do this since you know the normalized direction of AC (letâ€™s call this normal N), as well as the vector AB.

Theta is calculated as `acos( AB Â· N )`

(the dot signifies a dot product).

Now you need to find the length of AC. Now that you have theta this can be done simply using `cos( Î¸ ) * len( AB )`

.

Finally, multiply N by the length of AC, and add the resulting vector to point A to get C.

For the record, raycasting against a plane is *also* a trigonometric solution to the problem. When exploded out of methods and into pure math, it looks like this:

Where P is the planeâ€™s normal, D is the ray direction (in this case the transform forward) and O is the ray origin (in this case the transform position).

You find the distance at which the ray intersects the plane by taking `v = D Â· P`

and `n = O Â· P`

. The distance equals `-n / v`

.

How do you know the normalized direction of AC? You donâ€™t know the coordinates of C (?, 0, ?)

As stated in the original post, we have the transform.forward of the object, which gives us the direction but not the length.

Agreed, but the OP requested that we use trigonometry only, assuming based only on the diagram and the statement â€śI am really interested only in the math partâ€ť. Yes you can get the angles from Unity, but not from the diagram. Semantics at this point, sounds like we are in agreement.

1 Like