[SOLVED]Share with you a problem and how I fixed

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
mariwan
Posts: 306
Joined: Wed Jan 06, 2021 2:00 pm

[SOLVED]Share with you a problem and how I fixed

Post by mariwan »

I had a problem with my star 2D drawing for quite a long time.
I didn't understand why the normalAt was (0,0,-1).

Here is the function that draw the star with the bug :

Code: Select all

    def execute(self, obj):
        try:
            if obj.OuterRadius< obj.InnerRadius  :
                #you cannot have it smaller 
                obj.OuterRadius=obj.InnerRadius
            _points = []

            for i in range(0, obj.Corners):
                alpha = _math.pi *(2 * i + 2 - obj.Corners % 2)/(obj.Corners) 
                if i % 2 == 1:
                    radius = obj.InnerRadius
                else:
                    radius = obj.OuterRadius
                y = _math.cos(alpha) * radius
                x = _math.sin(alpha) * radius
                _points.append(App.Vector(x, y, 0.0))
                if i ==0 : 
                    saveFirstPoint=App.Vector(x,y,0.0)
                if alpha>obj.Angle : 
                    break
            _points.append(saveFirstPoint)
            test = _part.makePolygon(_points)
            obj.Shape = _part.Face(test)
            if hasattr(obj, "Area") and hasattr(obj.Shape, "Area"):
                obj.Area = obj.Shape.Area
I think some one mentioned that it might be the way it was drawn that causes the issue.
Actually changing the following lines fixed the normalAt to be (0,0,1) and that solve the issue of extruding the face which was going down rather than going up when you extrude the face.
I share with you this problem and the cause of the problem so maybe you face something like that also.

Code: Select all

                x = _math.cos(alpha) * radius
                y = _math.sin(alpha) * radius
Post Reply