0

Considering the following JavaScript code that runs in Node.js is there any way to change the input data according to below statements ?

Since I am a newbie in JS I do not understand if it passes the header meaning pointer or a value .

  • u_new = u cos(v)
  • v_new = u sin(v)
    setData (data) {
    if (data.length > 1) {
      this.u.data = data[0].data
      this.v.data = data[1].data
      this._baseLayer.setData([this.u , this.v])
      Layer.prototype.setData.call(this, data)
    }
  },
  setModel (model) {
    let modelHeader = {
      ...
    }
    Object.assign(this.u.header, modelHeader)
    Object.assign(this.v.header, modelHeader)
    Layer.prototype.setModel.call(this, model)
  }

Original inputs u and v are arrays in this format :

This is u data array

["NaN","NaN","NaN","NaN","NaN",0.77,0.76,0.75,0.84,0.94,1.03,1.11,"NaN"]

This is v data array

Note that v values are in degrees while JavaScript's Math read radians.

["NaN","NaN","NaN","NaN","NaN",187.21,189.48,190.58,192.54,194.48,"NaN",197.21,198.09]

I have already tried the following without any success, I can't see any animation running (I animate u-v vectors) :

// radians = degrees * PI / 180
this.u.data = data[0].data * Math.cos(data[1].data * Math.PI / 180) 
this.v.data = data[0].data * Math.sin(data[1].data * Math.PI / 180)

If such a data processing is not possible should I modify the arrays before I pass them as input to JS ?

2
  • 2
    "without any success" - what does that mean? console errors? Calculation errors? Commented Sep 14, 2020 at 11:27
  • @ mplungjan You are right sir, sorry for not noting what I mean. I just updated the question. I animate u & v vector data. Commented Sep 14, 2020 at 11:30

1 Answer 1

1

Do you mean this?

const uRads = ["NaN", "NaN", "NaN", "NaN", "NaN", 0.77, 0.76, 0.75, 0.84, 0.94, 1.03, 1.11, "NaN"]
  .map(deg => deg === "NaN" ? 0 : Math.cos(deg * Math.PI / 180))

const vRads = ["NaN", "NaN", "NaN", "NaN", "NaN", 187.21, 189.48, 190.58, 192.54, 194.48, "NaN", 197.21, 198.09]
  .map(deg => deg === "NaN" ? 0 : Math.cos(deg * Math.PI / 180))


const res = uRads.map((urad, i) => console.log(urad, vRads[i]))

Sign up to request clarification or add additional context in comments.

9 Comments

u and v json are not only 2 specific files, so they can't be const, there are multiple with 1 - 1 ratio which are loaded by a server folder.
I have no idea what you mean. You can do this.u.data = ["NaN","NaN","NaN","NaN","NaN",187.21,189.48,190.58,192.54,194.48,"NaN",197.21,198.09].map(deg => deg === "NaN" ? 0 : Math.cos(deg * Math.PI / 180)) if that is what you need
OR you can do this.u.data = uArray.map(deg => deg === "NaN" ? 0 : Math.cos(deg * Math.PI / 180)) if you have the array in a var
@ mplungjan That works fine, thank you very much. How can I multiply u_new = u cos v ? That's my cos v = data[1].map(deg => deg === "NaN" ? 0 : Math.cos(deg * Math.PI / 180))
Sorry that is just math - that is up to you. I have zero idea what you are trying to do so I just made it possible for you to do whatever it is you need to do
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.