[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Orekit Users] Advice on FastMath.toRadians

Hello Bogdan,

I agree with you : functionnal programming, when used properly, can be really powerful.
Another advantage that is quite obvious in your example is that there is far less risk to mess up indexing.
In your original example, it is relatively easy to make a mistake in the loop stop condition : is it length ? lenth+1 ?
What happens if there is a single element ? Or no element at all ?

With the "lambda" version of the statement, the developper does not have to worry about all these corner
cases : they are handled nicely by the "setAll" method.


De : orekit-users-request@orekit.org <orekit-users-request@orekit.org> de la part de Bogdan Udrea <bogdan.udrea@vissidus.com>
Envoyé : jeudi 19 juillet 2018 21:18
À : orekit-users@orekit.org
Objet : RE: [Orekit Users] Advice on FastMath.toRadians


Thank you for your help. It works great.
Lambda functions are new to me and now I see quite a few places where I can use them in the code.

Best regards,


-----Original Message-----
From: orekit-users-request@orekit.org <orekit-users-request@orekit.org> On Behalf Of MAISONOBE Luc
Sent: Thursday, July 19, 2018 10:23
To: orekit-users@orekit.org
Subject: Re: [Orekit Users] Advice on FastMath.toRadians

bogdan.udrea@vissidus.com a écrit :

> Dear Colleagues,
> This might be better asked on the Hipparchus listserv but I have
> decided to ask it here as well.
> I am using an XML file to store the parameters of a simulation where I
> specify Euler angles for a multitude of sensors. The Euler angles are
> stored in the XML file in degrees so they are easy to read by humans.
> The angles are converted to radians in the code in a loop.
> // Euler angles so that the Ox axis of sensors points radially out //
> rotation order of Euler angles is ZYX double [] senEulerAng =
> senParams.getEulerAngles(); for ( int i = 0; i < senEulerAng.length;
> ++i ) { // converts to rad
>       senEulerAng[i] = FastMath.toRadians( senEulerAng[i] ); }
> The question: Is it possible to apply FastMath.toRadians as an
> iterator on an array of doubles? I haven't been able to figure it out on my own.

You may try this, if senEulerAng is declared as final so it is available in the context of the lambda generator function:

    Arrays.setAll(senEulerAng, i -> FastMath.toRadians(senEulerAng[i]));

best regards,

> A solution would be to convert the array of doubles to a RealVector,
> mapMultiuply with pi/180, and then convert back to an array of doubles
> but it seems like a workaround instead of elegant Java.
> Thank you.
> Bogdan

The information in this e-mail is confidential. The contents may not be disclosed or used by anyone other than the addressee. Access to this e-mail by anyone else is unauthorised.
If you are not the intended recipient, please notify Airbus immediately and delete this e-mail.
Airbus cannot accept any responsibility for the accuracy or completeness of this e-mail as it has been sent over public networks. If you have any concerns over the content of this message or its Accuracy or Integrity, please contact Airbus immediately.
All outgoing e-mails from Airbus are checked using regularly updated virus scanning software but you should take whatever measures you deem to be appropriate to ensure that this message and any attachments are virus free.