• 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 /
  • Help Room /
avatar image
0
Question by cjsawyer · Aug 30, 2015 at 08:51 PM · 2dcurvedrawingshapes

How can I draw this 2d shape? (two straight lines and two curved segments)

I only need to draw two of them, so the method doesn't need to be particularly fast. I just don't know where to start. Are there any smallish libraries that can help me accomplish this? alt text

Comment
Add comment
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

2 Replies

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

Answer by cjsawyer · Aug 30, 2015 at 11:59 PM

layla over at facepunch.com wrote a script that fully answered my question

Quickly made a script to do this for you. Obviously you don't want to be generating the mesh every frame so just use it to generate it once then draw it however you want.

alt text

 using UnityEngine;
 using System.Collections;

 [RequireComponent(typeof(MeshRenderer), typeof(MeshFilter)), ExecuteInEditMode]
 public class CircleMesh : MonoBehaviour
 {
     public int SegmentCount;
     public float OuterRadius;
     public float InnerRadius;
     public float DeltaStart;
     public float DeltaSize;

     private Mesh _mesh;

     private void Awake()
     {
         _mesh = new Mesh();

         GetComponent<MeshFilter>().sharedMesh = _mesh;
     }

     private void Update()
     {
         UpdateMesh();
     }

     private void UpdateMesh()
     {
         _mesh.Clear();

         Vector3[] vertices = new Vector3[(SegmentCount + 1) * 2];
         int[] indices = new int[SegmentCount * 6];

         for (int i = 0; i <= SegmentCount; ++i)
         {
             float angle = (DeltaStart * Mathf.Deg2Rad) + ((DeltaSize * Mathf.Deg2Rad) / SegmentCount) * i;
             Vector2 direction = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));

             vertices[i * 2] = direction * OuterRadius;
             vertices[(i * 2) + 1] = direction * InnerRadius;
         }

         for (int i = 0; i < SegmentCount; ++i)
         {
             int baseIndex = i * 6;

             indices[baseIndex] = (i * 2);
             indices[baseIndex + 1] = ((i * 2) + 1);
             indices[baseIndex + 2] = (((i + 1) * 2) + 1);

             indices[baseIndex + 3] = (((i + 1) * 2) + 1);
             indices[baseIndex + 4] = ((i + 1) * 2);
             indices[baseIndex + 5] = (i * 2);
         }

         _mesh.vertices = vertices;
         _mesh.triangles = indices;
     }
 }



screen-shot-2015-08-30-at-55852-pm.png (9.2 kB)
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
avatar image
0

Answer by Wolfshadow · Aug 30, 2015 at 10:20 PM

Do you need to do it in unity, or can a program like, say, inkscape make it, and import it. A much easier method, if that is all you need to do.

Comment
Add comment · Show 2 · 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
avatar image Wolfshadow · Aug 30, 2015 at 10:20 PM 0
Share

sorry, if this is not the answer you need, ignore it.

avatar image cjsawyer · Aug 30, 2015 at 10:35 PM 0
Share

I need to generate the shape in unity on the fly with parameters r1, r2, and theta.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

29 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 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

User drawing game in unity (2d) 0 Answers

How to make a curve motion change direction fluidly on click 0 Answers

Draw simple 2D shapes like circles, rectangles, paths etc... 0 Answers

Drawing simple shapes on Canvas,How to draw simple shapes on Canvas 2 Answers

How do you draw 2D circles and primitives 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges