UNI.T C# new plane (Vector3.up, Vector3.zero); I'm curious about this coding

Asked 1 years ago, Updated 1 years ago, 107 views

I'm just going to use the plane as the floor Plane groundPlane = new Plane(Vector3.up, Vector3.zero);

What's the point of doing this? I don't know the difference Why adjust the Vector value and why there are two parameters.

unity c#

2022-09-22 19:53

1 Answers

In Unity, there are three constructors that make the plane, which are overloaded. https://docs.unity3d.com/ScriptReference/Plane-ctor.html

This means that you can use it for each situation.

Usually, there are minimum conditions for determining the plane in geometry Based on the explanation from high school math,

There are four.

public Plane(Vector3 a, Vector3 b, Vector3 c);

If you look at the parameters that this constructor receives, it corresponds to plane determination condition 1. Although each type is a vector, it does not receive a normalized vector because it means a position vector from the origin. Let's use a vector that has the same coordinates as the world space.

So the rest of the generators that receive the normal need to see why it's so defined.

public Plane(Vector3 inNormal, Vector3 inPoint);

public Plane(Vector3 inNormal, float d);

Normal refers to the vertical direction of the plane. So it's a vector. Vectors have directions and sizes, but do not specify positions. So vectors alone can't represent a plane.

I mean, we need one more factor to specify the location That's one point (in point), or the distance from the origin (d). Depending on this factor, you can write different constructors that you call.

Besides this, there are many other conditions that determine the plane is determinedten thousand The reason why we use normal is because if you look at the equation of the plane that you know well, it will help you understand.

The general equation of the plane is expressed as follows.

ax + by + cz + d = 0

where the normal vector of this plane is (a, b, c) and the distance from the origin is d.

The above Unity's Plane constructors receive the elements necessary to establish this general equation as a factor. Equation can be established == The plane is determined.Because it comes down to .

Knowing a point (in point) is equivalent to knowing the distance (d) from the origin, so the constructors are divided, but they are mathematically the same.

The description states that the normal vector you factor in must use a normalized vector.

The d value is inversely proportional to the size of the normal vector If the normal vector is not normalized (i.e., if the size is not 1), This is because the d value becomes a different value. You have to keep this.

new Plane(Vector3.up, Vector3.zero);

In this code, Vector3.up is I don't know how UNI.T uses the axial direction, It's probably a unit vector of one size in the direction of the sky based on world coordinates.

Vector3.zero is the starting point.

If you want to create a floor with zero height based on world coordinates, that's the right expression.


2022-09-22 19:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.