• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by reyalpsirc · Oct 12, 2013 at 03:45 PM · rotationinstantiateplanecreate

Create plane from 2 Vectors of a symmetry line segment

I have a text file that defines pairs of points (Vector3) that are related to one of the symmetry line segements that exists on a plane. The width and height of these planes are fixed and so, I want to create a plane given these points. This way, given a point A and a point B, I should be able to create the plane and rotate it in order that in the end, the points A and B form a symmetry line segment of the plane. How can i do that?

EDIT

This is what I have:

What I have

This is what I want:

What I want

But I just want the plane, not the line. The line is only to illustrate what the points mean to the plane, nothing more.

what_i_have.png (408 B)
what_i_want.png (2.4 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Oct 12, 2013 at 03:56 PM 0
Share

I fuzzy on your question. I think what you are saying is that you want to use a new plane as a way to draw a line between two points on an existing plane. Is the existing plane axes aligned or does it have arbitrary rotation? What kind of plane is it...a built-in plane, a built-in Quad, or something else? Are the points in world space or are they relative to the plane (or are they just defined in terms of the symmetry lines)? Also a drawing might be helpful to understanding this question.

avatar image reyalpsirc · Oct 12, 2013 at 05:51 PM 0
Share

No no, I don't have a plane. I just have 2 coordinates that belongs to one of the segments of the plane that I want to create. I will put some images to illsutrate it.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · Oct 12, 2013 at 06:12 PM

In solving this question there are three things that must be done, positioning the plane, scaling the plane, and rotating the plane. Each issue depends on the underlying plane and the your setup. I'm going to assume you are using the built-in Quad which is 1x1 units when scaled to (1,1,1). I'm going to assume that the camera is looking towards positive 'z'. And I'm arbitrarily going to assume that you will align the top and the bottom of the of the plane with the points. Because you are aligning the top and the bottom, you scale the width (x) to anything you want.

You want to position the plane at the mid-point. Assuming your points are Vector3s name P1 and P2:

 transform.position = P1 + (P2 - P1) / 2.0;

Scaling:

 transform.localScale.y = (P2 - P1).magnitude;

Rotation:

 transform.up = (P2 - P1);

or:

 transform.rotation = Quaternion.FromToRotation(transform.up, (P2 - P1));

Putting it all together might look like:

 var P21 = P2 - P1;
 transform.position = P1 + P21 / 2.0;
 transform.localScale = P21.magnitude;
 transform.up = P21;

Note if you are working in C#, you will have to save localScale to a temporary variable, change the 'y' parameter of the temporary variable, and assign it back.

This all assumes the setup is as I've described. Other setups may require a bit more code. For example, if the camera is point at the points from an arbitrary direction, you will likely need to some sort of billboarding.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

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

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Firing a rocket - flight problem 2 Answers

Rotation troubles 2 Answers

How to rotate an Instantiated object? 1 Answer

How to spawn an object continually while floating vertically like a bubble 1 Answer

Why is my projectile firing "off" after rotation 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges