Skip to content

This is a Unity project for Plotting graphs of a given equation in the 3d space. It can plot animated graphs of sin waves etc. as well.

License

Notifications You must be signed in to change notification settings

amanyadev/Unity-Graph-Builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity-Graph-Builder

This is a Unity project for Plotting graphs of a given equation in the 3d space. It can plot animated graphs of sin waves etc. as well. Colors are provided using shaders

code for graph

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Graph : MonoBehaviour
{   
    Transform[] points; 
    [Range(10,100)] public int resolution = 10;
    
    public Transform pointPrefab;

    void Start(){
        float step = 2f / resolution;
       	Vector3 scale = Vector3.one *step;
		Vector3 position;
        position.x = 0;
        position.y = 0;
        position.z = 0;
        points = new Transform[resolution];
		for (int i = 0; i < resolution; i++) {
			Transform point = Instantiate(pointPrefab);
            points[i] = point;
			position.x = (i + 0.5f) * step - 1f;//adjusting cubes
         //   position.y = (position.x)*position.x*position.x;
			point.localPosition = position;
			point.localScale = scale;
            point.SetParent(transform);
            
		}
    }

    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < points.Length; i++) {
			Transform point = points[i];
			Vector3 position = point.localPosition;

            /*Equation Goes Here */
			position.y = Mathf.Cos(Mathf.PI*(position.x + Time.time));

			point.localPosition = position;
            	
		}

    }
}

About

This is a Unity project for Plotting graphs of a given equation in the 3d space. It can plot animated graphs of sin waves etc. as well.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published