# Return function from float\[\] array

**URL:** <https://discourse.processing.org/t/return-function-from-float-array/2519>\
**Category:** Coding Questions\
**Created:** [August 9, 2018, 10:41pm UTC](https://discourse.processing.org/t/return-function-from-float-array/2519 "2018-08-09T22:41:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olygamy](https://avatars.discourse-cdn.com/v4/letter/o/dfb087/32.png) [@Olygamy](https://discourse.processing.org/u/Olygamy)\
**Post date:** [August 9, 2018, 10:41pm UTC](https://discourse.processing.org/t/return-function-from-float-array/2519/1 "2018-08-09T22:41:09Z")

</div>

Hi there,

I am stuck on a return function. I have a triangle, each corner is defined by pair of float [] arrays: float[] xArray = new float[3]; float[] yArray = new float[3] - all in the class to contstruct the triangle.  
I need to be able to access each pair of arrays from another class or draw function - so I assume I need to return them in the class…how do I do that correctly?  
Here is a code:

```auto
Triangle triangle;

void setup() {
  size(400, 400);
  triangle = new Triangle ( width/2, height/2, 40);
}

void draw() {
  background(88);     
  triangle.triangleDisplay();
}

// ---------------------------------------------

class Triangle {

  float x, y, w, h;
  float CSize;
  float[] xArray = new float[3];
  float[] yArray = new float[3];

  Triangle( float posx, float posy, float tW) {

    x = posx;
    y = posy;
    w = tW;
  }

  void triangleDisplay() {

    float currentAngle = -HALF_PI;  
    float wr = w * 0.5; 
    for (int i = 0; i < 3; i++) {
      xArray[i] = x + wr*cos(currentAngle);
      yArray[i] = y + wr*sin(currentAngle);

      //println(xArray[0], ",", yArray[0]);
      fill(255);
      currentAngle = currentAngle + radians (360 / 3);
    }
    triangle(xArray[0], yArray[0], xArray[1], yArray[1], xArray[2], yArray[2]);
  }
}

```

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [August 9, 2018, 10:45pm UTC](https://discourse.processing.org/t/return-function-from-float-array/2519/2 "2018-08-09T22:45:39Z")

</div>

### _Please format your code_ 😊

It consist on these two steps:

1. In your code editor (PDE, VS code, Eclipse, etc) ensure you execute the beautifier function. This function automatically indents your code. Auto-indenting makes your code easier to read and helps catching bugs due to mismatch parenthesis, for instance. In the PDE, you use the key combination: `ctrl+t`
2. You copy and paste your code in the forum. Then you select the code and you hit the formatting button aka. the button with this symbol: `</>`

That’s it! Please notice you do not create a new post in case you need to format something you already posted. You can edit your post, copy the code to the PDE, indent the code properly there and then past it back here, format the code and \>\> **save** \<\< the edits.

## Extra info:

Formatting your code makes everybody’s life easier, your code looks much better plus it ensures your code integrity is not affected by the forum’s formatting (Do you know the forum processes markup code?) Please visit the sticky posts or the FAQ section/post to learn about this, other advantages and super powers you can get in this brand new forum.

Kf

---

<div class="post-metadata">

**Author:** ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)\
**Post date:** [August 10, 2018, 5:24am UTC](https://discourse.processing.org/t/return-function-from-float-array/2519/3 "2018-08-10T05:24:42Z")

</div>

It’s good that you’ve considered the privacy of your class.

If xArray and yArray were private, you would need a public method to access them publically, say, something like

```auto
float[] getXArray(){
    return xArray;

```

}

In the bigger picture, you want the member variables to be readable, but not changeable.

Did this answer your question?

---

<div class="post-metadata">

**Author:** ![Olygamy](https://avatars.discourse-cdn.com/v4/letter/o/dfb087/32.png) [@Olygamy](https://discourse.processing.org/u/Olygamy)\
**Post date:** [August 10, 2018, 11:23am UTC](https://discourse.processing.org/t/return-function-from-float-array/2519/4 "2018-08-10T11:23:19Z")

</div>

Hi Tony,

Indeed - as in I want to access each individual member (as in xArray[0]) from i.e. another class or draw function of main sketch. And indeed the variables are static…I will try with your method now :). THANK YOU!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 10, 2018, 4:27pm UTC](https://discourse.processing.org/t/return-function-from-float-array/2519/5 "2018-08-10T16:27:36Z")

</div>

- [Forum.Processing.org/two/discussion/14423/how-do-i-draw-triangles-as-easily-as-rectangles-or-ellipses#Item\_4](http://Forum.Processing.org/two/discussion/14423/how-do-i-draw-triangles-as-easily-as-rectangles-or-ellipses#Item_4)
