For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

How do i can Partial Derivatives ?

Anonymous's picture
Forums: 

I would like to do partial derivatives.

How do i?

Igor Feoktistov's picture

Hi

there are no in CASCADE special method for calculations of function derivatives. For well known analitical functions like Sin(x), Cos(x), ... you can look in any math reference book. For non-analitycal function you should to write appropriate method for numerical calculations of ordinary or partial derivatives.

Igor

Ejun Jin. Kim's picture

Thanks your response.

But I don't understand what to do source code "Expr_cosine.cpp"

In source code , cosine derivative fuction exist. what is it ?

Igor Feoktistov's picture

Hi,

Package Expr is used for realisation of interpreter of math expressions and for you it will be rather difficult and not effective to use it in direct calculations, but what is your problem? Derivative for Cos(x) is -Sin(x) (Expr_Cosine does the same) and I don't think that it is necessary to have special method to calculate -Sin(x) as well as derivatives for other simple functions.

Best regards

Igor

Ejun Jin. Kim's picture

Thanks..

I understand your comment..

What i want, When vecotor[alph,beta,gamma,x,y,z] and, equation f1 = sin(beta) f2 = cos(beta)sir(gamma) f3= cos(beta)cos(gamma) -1 f4 = x-3 f5 = y-2 f6 = y-2 f7 = alpha . . In solve root , i can't method how do i in opencascade, that in fuctionsetRoot argument, i have to set deriative fuction. but i don't know how do i ? One variable(alpha) have to partial deriative between f1 and f9 and then beta have to partial deriative between f1 and f9 finally i have to gain matrix (6*9)...

but i cannot programming..

please help...

In Book , I find not source code partial deriatives of n dimension.

Igor Feoktistov's picture

f1'/beta = Cos(beta)

f1'/other variables = 0.

f2'/alph = 0

f2'/beta = -Sin(beta)*Sin(gamma)

f2'/gamma = Cos(beta)*Cos(gamma)

f2'/other variables = 0

.......

In method Derivative(...) for math_FunctionSetRoot you must calculate all partial derivatives for each equation (as I did for f1 and f2 above) for given vector of variables and put these values in output matrix. That is all. If you don't know how to calculate partial derivative for simple function it is so pity. Ask somebody who know how to do this. By the way, in Russia children study such kind of things in school. What school have you finished?

Best regards,

Igor

Ejun Jin. Kim's picture

Thanks your response..

Your solution is not match me. I know that partial deriative theory..

But I have to set equation realtime..

that is : equation f1,f2,f3 is not already set but equation calcurated real-time.

so.. i think that partial deriative fuction method make. ..

Igor Feoktistov's picture

Sorry for my misuderstanding.

Do you mean that during calculations the number of equations or the equation functions can be changed?

What means " equation f1,f2,f3 is not already set..."?

Igor

Ejun Jin. Kim's picture

Dear Sir!

Varial Vector numbers are not changed ... always 6 have variable..

equation number have always 9.

but equation content can changed according to condition ..

that is : according to condition equation(normal vector1 == -normal vector2) Set one is normal vector 0,0, -1, the other is normal vector( -sin(beta) cos(beta)sin(gamma), - cos(beta)cos(gamma)).

then if -sin(beta) = 0 then sin(beta) = 0.. Because normal vector values is changed by object shape.. I think that partial fuction is not right to do setting alreadly.

Do you understand?

Igor Feoktistov's picture

As far as I understood 3 first equations must look like:

sin(beta) = n1

cos(beta)*sin(gamma) = n2

cos(beta)*cos(gamma) = n3

Do n1, n2, n3 depend on any variable (alpha, beta, gamma, x, y, z) ?

Ejun Jin. Kim's picture

Dear Sir!

For example,

normal vector1 is already exist values..

But Normal vector2 is already not exist values.

Nomal vector2 have to find values..

Therefore, normal vector have vector(0,0,-1)

values.

But unknown normal vector2 gain vector values by some rule(perpendicual,parallel...).

So by we normal vector = -normal vecotor2

condition. The equation can derive as following.

sin(beta) = 0

cos(beta)*sin(gamma) = 0

cos(beta)*cos(gamma) = -1

.. ..

Therefore we can set f1 = sin(beta) f2 = cos(beta)*sin(gamma) f3 = cos(beta)*cos(gamma) -1 ..

As above, x,y,z variable not display. but the other equation have x,y,z eqation of value.

so values vector have [alpha,beta,gamma,x,y,z] and equation have f1,f2....f9..

nomal vector1 and normal vector2 can changed by objected shape..

Help...

Igor Feoktistov's picture

So, as far as I could understand for given objected shapes all equations are defined and you can solve them. Do you want to create method that solve problem for any objected shape? As far as I could understand now you have equations for normal vector for sphere, but for example for cylinder f1, f2 and f3 must have another form. It is true?

Ejun Jin. Kim's picture

Dear..

I am sorry that i don't explain detail.

The 2 box exist in some distance..

I would like to mate one box bottom surface and the other top surface..

Then one box bottom surface normal vector invert the other box top surface normal.

and I would likt to adjust one box bottom surface center point and the other box top surface.

Then I fix one box(box1) location and I would like to mate by the other box(box2) move.

So. I select box top plane and i gain top plane normal vector. and i select the other box bottom plane and i gain bottom plane normal vector. but I cannot find location which box 2 move.

therefore, location which move have to find. so. moved normal vector [-sin(beta),cos(beta)sin(gamma),-cos(beta)cos(gamma) 0] moved position [x-3sin(beta),y+3cos(beta)singamma),z-3cos(beta)cos(gamma) 1]

so. by using rule invered normal vector1 and nomal vector2 and position adjust rule..

set f1,f2,f3,f4,f5,f6,f7,f8,f9...and [alpha,beta,gamma,x,y,z]

Finally I have to find location matrix which moved object.

Are you understand?

Igor Feoktistov's picture

Yes, at last.

I think it is better to use gp_Trsf class and define needed transformation with help method SetDisplacement(Ax3_1, Ax3_2), Ax3_1 and Ax3_2 - axes which must coincide with antinormal of box1 and normal of box2 correspondently (or otherwise). Ax3_1 and Ax3_2 must have origin points on box faces which you want to be equal after transformation. Then transform box1 by this transformation with help of class BRepBuilderAPI_Transform.

Any case, you not need to solve those equations, because you always can construct transformation directly as composition translation and elementary rotations. (Of course, your equations are wrong, this task is fully defined and number of equations must be equal number of variables.)

When you calculate normal to face of box remember that normal to face is comosition of normal to underlying surface and orientation flag of face: if face is REVERSED you must invert surface normal to get face normal

Best regards

Igor

Ejun Jin. Kim's picture

Dear Sir!

Thanks your response..

I don't understand How do i gain orientation flag of your comment.

Is it fuction to orientation exist?

In fact, i experienced normal vector wrong.

So i don't know why this occurred..

How do i?

Igor Feoktistov's picture

Hi

orientation flag can be got by method TopoDS_Shape::Orientation().

Normal to surface can be got by method BRepLProp_SLProps::Normal().

Usually top and bottom (in general two opposit) surfaces of box have the same normal, but one face is FORWARD but another is REVERSED, so to get true normal to face you must reverse normal for REVERSED face.

Best regards,

Igor

Ejun Jin. Kim's picture

Dear Sir!

Thanks for your response.

I am glad to solve my some problem your comment.

I am deveoping to assembly system works on open cascade.

In opencascade,In fact Because Assembly fuction is not exist, I have to make this system.

So. I have found to related paper and books. and I studied..

My reference book is cad/cam theory and practice by ibramim zied..

Most of all paper as well as this book, using Mating condition, assembly modeling constructed.

Therefore, currently I have tried to implement sample example in Book.

Mating conditions ( fits condition,against condition, distance condition, ...etc..) are too much to apply all. Therefore, I consider only fits condition and against condition.

so..I think that I dont implement only what i want to your comment.

I have to implement assembly system using constraint equation.

Therefore, in many cases, Because constraint equation vary, I have to set equation in real-time not virtual fuction set.

Please Help..

Best regards..

Igor Feoktistov's picture

In general you can define and keep constraints with help of OCAF level of CASCADE, but CASCADE does not have methods to solve constraints, so you must write solver yourself.

Igor

Ejun Jin. Kim's picture

Dear Igor.

normal vector values are strange.

I selected bottom surfaceof box solid. TopoDS_Face Face = TopoDS::Face(myAISContext->SelectedShape()); and because i know that already top surface is plane, i gain Handle (Geom_Plane) aPlane.

and using gp_Pln, i gain normal vector " aPln.Axis().Direction().XYZ()"

then i tried to gain top surface of box solid(positive direction)and bottom surface of box solid(negative z direction).

currently because i don't know display shape local coodinate axis, i display using world coodinate axis.

the result are strangeous. Both top and bottom normal vector result in (0,0,-1)-top (0,0,-1)-bottom.

so.. like to your metioned, I use TopAbs_Orientation using Face.Orientation(). but, top surface is forward and the others are all reward.

i don't know why this occcured.

Please tell me know how to solve this problem.

Best regards..

Igor Feoktistov's picture

How did you create the box? When I use BRepPrimAPI_MakeBox normals to top and bottom surfaces are (0,0,1) and (0,0,1).

Igor

Ejun Jin. Kim's picture

Dear Sir.

i make box in solid works 2000. And in origin toward positive x direction x length 200, toward positive y direction y length 100, and toward postive z direction z legnth 200 are created box. then i saved step data In opencascade ,i imported box step data.

According to coordinate system , i think that normal vector values is same, sign is not same. if z positive direction.

so i think normal vector values are right top (0,0,1), bottom (0,0,-1).

is it wrong?

Igor Feoktistov's picture

It is true, normal vectors of top and bottom faces (taking in account orientation of bottom face) must be (0, 0, 1) and (0, 0, -1) because CASCADE has agreement that normals of faces of solid body always point out of body.

Really I don't know why your box has normals that point inside body. Are you sure that top face is FORWARD and bottom face is REVERSED? May be otherwise?

Try to create the same box directly in your program (using BRepPrimAPI...) and check normals.

Igor

Ejun Jin. Kim's picture

Dear Sir

By your comment, I try to create the same box directly in my program using BRepPrimAPI and check normals.

The result top surface is forward and normal vector is 0,0,1. and bottom surface is reversed and normal vector is 0,0,1.

is it right?

i don't know why the result value are (0,0,1),(0,0,1)..

Igor Feoktistov's picture

It is true result because you calculate normals to surfaces. The top face is FORWARD, so its normal is the same that normal to surface : (0, 0, 1). The bottom face is REVERSED, so to get its normal you should invert normal to bottom surface and get (0, 0, -1).

Is it clear for you the difference between surface and face?

Ejun Jin. Kim's picture

Dear sir!

The surface is gemetric element. The face is topological element.

But why box loaded in step data is one forward and others reversed ?

is it step data representation bug?

and when box face selected, normal vector(0,0,-1) and bottom face selected, normal vector(0,0,-1)???

i don't understand why this occurred.//

i would like to solve this problem..

please help...

Ejun Jin. Kim's picture

Dear sir..

Due to Your help, i have gain to many information in opencascade.

Sincerely thanks for your help.

Final question :

I would like to display local coordiate system wich imported step data model.

i can display world coordinate axis.

but i cannot display local coordinate axis.

such fuction supported cannot find..

how do i..

Best regards..