Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Round down to nearest whole, odd number

Status
Not open for further replies.

crecore

Mechanical
Mar 11, 2010
64
I am driving a sketch using a perimeter constraint tied to an expression which is tied to an assocative perimeter measurement which is the result of another sketch which is also driven by expressions.

The goal is input expressions for measurements. The first sketch yields a visual model to determine the aesthetics. This then drives the second sketch but with the rounding I need to "tweak" the perimeters of some curves to follow mathematical rules.

The two sketches are working.

Now, I need to change the perimeter constraints to not just be an expression tied to the perimeter measurement, but to take that measurement, divide by a constant, round down to the nearest whole, odd integer and then multiply that back by the constant again to yield a new "adjusted" perimeter.

The closest I have done to this before now is interpart linking with rounding up and unit conversion.

please help!

NX 8.0.1.5
 
Replies continue below

Recommended for you

Have you looked at the 'functions' available while in the expression dialog? These can be found by selecting the [f(x)] icon in the lower left corner of the expression dialog (check out some of the 'math' items).

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Sorry, my sig didn't update. Using 9.0.1.3
I will investigate further in the am. Thanks

NX 9.0.1.3
 
Could you post at least some idea of the numbers that you're working with here? Perhaps show the list of expressions identifying which expression is what.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
See attched screen shot. The User Expressions in the boxes drive Sketch (3). 2 resulting curves yielded from Sketch (3). Length Measurement (5) is from one curve and I tied it to X_LENGTH_PERIMETER and Length Measurement (6) is tied to Y_WIDTH_PERIMETER. I then drive Sketch (7) with Perimeter constraints of similar curves tied to those Expressions. You see these on the right in the Expressions Editor (the first is highlighted). Right now both sketches look and adjust identically so that part is working. I am using the first sketch only to do math and provide a visual.

10.26456911 is the current result of the X_LENGTH_PERIMETER. I know I can use floor to round down similar to using ceiling to round up as I have in the past. I have also rounded with units before as well (thanks to your other posts). So in this case I will show you what I want to do mathematically.

First divide the Perimeters by my Crystal Spacing Expression (.45). In the first case 10.26456911/.45 = 22.810153577777777777777777777778

Second, I need to round to the nearest odd number. In this case I would round up to 23. If the perimeter was 21.99 or less I would want to round down to 21. So I guess now that I have written this out, I want to round to the nearest odd integer.

Third, I want to multiply the nearest odd integer, in this case 23, times the Spacing again (.45). 23*.45 = 10.35

Fourth, I need to set my Perimeter constraint equal to this to drive my second sketch.

I see no reason why we cannot do all of this with a single equation where the current perimeter constraint pulls the Perimeter Expression Tied to the Length Measurement yielded from the first sketch. I would then just repeat for the second perimeter.

Thanks in advance!


NX 9.0.1.3
 
 http://files.engineering.com/getfile.aspx?folder=8f2be1ba-e536-4900-8a1f-99e1c2c5fcf3&file=Express1.JPG
Code:
if(mod(floor(t1),2)=1)then(floor(t1))else(if(mod(ceiling(t1),2)=0)then(t1-1)else(ceiling(t1)))

The above expression code checks the value of expression "t1" and gives the closest odd integer. The only wrinkle is if the value of "t1" is an even integer; in this case it subtracts 1 from "t1", but you may want to change that to add 1.

www.nxjournaling.com
 
Here is what I came up with. It seems messy but it works.
You will need to change the "p" numbers.
p101 is the rounded down, odd, whole number that you want

p100=22.810153577777777777777777777778
p101=if (p100-(((floor(p100/2))*2))>=(1))(((floor(p100/2))*2)+1)else(((floor(p100/2))*2)-1)
 
and the p100 number is simply this number that was mentioned above
10.26456911/.45 = 22.810153577777777777777777777778
 
It is working with cowski's code. Jerry's is actually more like what I was expecting from the various rounding expressions that I have worked on. I did create an intermediate expression to yield the number needing to be rounded, just to reduce syntax error troubleshooting time.

I can create a situation with certain input expressions that drive the first sketch that create an underconstrained first sketch warning or even make the arcs flip inside out but it does not break and the driven sketch still works. This is a problem within the sketch itself due to wanting to control too many things. This could be fixed but I would need a bunch of complicated geometric formula constraints. For now, it is doing what I want (with limitations). If I need to go further I am not sure how I would do so due to Non Disclosure, etc. Thanks all.

NX 9.0.1.3
 
If the acrs flip inide out, and that is undesirable to you, then you may want to stragetically add reference lines that prevent such a thing
 
Sorry, let me rephrase. There are reference lines on the first sketch and while it can become under constrained under certain inputs it does not break and the driven sketch still works. There are some situations where the arcs on the second (driven sketch) flip inside out. This tells me to vary one of the other input parameters until the situation is remedied. I may be able to control this differently. It's all about what you want to control. With sketch constraints you cannot, that I know of, make preferred constraints for example. They all must work in all situations.

NX 9.0.1.3
 
Back in UG V15, you could insert a (floor) command in an expression which will reduce, or round down, the given value to the nearest single integer.
So you would create a new expression and make it equal to: (floor)p123 if I remember the syntax correctly.
The same would be true for the opposite direction, rounding up, would be the (ceiling) command.
 
Yes, The function that you mention is still available in NX, look at my equation above.
the trick was to make it an odd number.
 
OK, I used these same expressions in another file with a different shape, so different constraints, but the same rounding. It has a similar problem where certain numbers input to the User definable driving expressions yield the wrong answer. In a nut shell, in some cases it is not multiplying back times the crystal spacing constant of .45. I have .45 set to constant so that it doesn't misinterpret the results as area instead of length by the way.

So, you will see in the attached screen shot, when the X input is 18 it works fine.

NX 9.0.1.3
 
 http://files.engineering.com/getfile.aspx?folder=d32984ec-6719-44fc-b4dd-18d36a6b1cb7&file=eXp_rnd_ok.JPG
Put parentheses around the rounding calculation:

Code:
[highlight #FCE94F]([/highlight]if(...rounding calc...)else(...calc...)[highlight #FCE94F])[/highlight]*.45

What's currently happening is you are only performing the multiplication if the "else" portion of the IF test is run. Adding the parentheses will take whatever answer comes from the rounding calc and use that in the multiplication operation.

www.nxjournaling.com
 
Ahh, seems onvious, I tried something like that early on and received an odd error, may have been caused by something else. I will revert to that. In that case it is odd that it sometimes works! instead of sometimes fails! thanks!

NX 9.0.1.3
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor