Open CASCADE学习|绘制链轮

链轮是一种带嵌齿式扣链齿的轮子,主要用于与节链环或缆索上节距准确的块体相啮合。链轮可以是实心或带辐条的齿轮,并与滚子链啮合以传递运动。

链轮的应用非常广泛,包括化工、纺织机械、食品加工、仪表仪器、石油等行业的机械传动等领域。链轮型号包括非标链轮(根据客户图纸定制)和标准链轮(美标和公制)。常用的链轮材料是C45,常用的加工方法是淬火处理和表面发黑处理。

在选择链轮齿数时,需要考虑链传动速比。链轮齿数的选择将影响链节的转动量、链条的拉伸负荷和轴承的负荷。对于链轮齿面磨损的情况,可以通过及时翻面使用来延长使用时间。如果新链轮过长或经使用后伸长,可以拆去链节进行调整,但拆去的链节数必须为偶数。

下面基于OCCT绘制链轮​:

#include <BRepPrimAPI_MakeCylinder.hxx>
#include <gp_Ax3.hxx>
#include <BRepPrimAPI_MakeCone.hxx>
#include <GCE2d_MakeLine.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <gp_Pln.hxx>
#include <TopExp_Explorer.hxx>
#include <BRepFilletAPI_MakeFillet2d.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <GC_MakeCircle.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <gp_GTrsf.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepPrimAPI_MakeRevol.hxx>
#include <GccAna_Circ2d2TanRad.hxx>
#include <GeomAPI.hxx>
#include <TopoDS.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <Geom2dAPI_InterCurveCurve.hxx>
#include <GCE2d_MakeCircle.hxx>
#include <GCE2d_MakeArcOfCircle.hxx>
#include"Viewer.h"

Standard_Real roller_diameter = 10.2;
Standard_Real pitch = 15.875;
Standard_Integer num_teeth = 40;
Standard_Real chain_width = 6.35;
//Dimensions derived from the provided inputs
Standard_Real roller_radius = roller_diameter / 2.;
Standard_Real tooth_angle = (2 * M_PI) / num_teeth;
Standard_Real pitch_circle_diameter = pitch / sin(tooth_angle / 2.);
Standard_Real pitch_circle_radius = pitch_circle_diameter / 2.;
Standard_Real roller_contact_angle_min = (M_PI * 120 / 180) - ((M_PI / 2.) / num_teeth);
Standard_Real roller_contact_angle_max = (M_PI * 140 / 180) - ((M_PI / 2.) / num_teeth);
Standard_Real roller_contact_angle = (roller_contact_angle_min + roller_contact_angle_max) / 2.;
Standard_Real tooth_radius_min = 0.505 * roller_diameter;
Standard_Real tooth_radius_max = tooth_radius_min + (0.069 * pow(roller_diameter, 1.0 / 3.0));
Standard_Real tooth_radius = (tooth_radius_min + tooth_radius_max) / 2.;
Standard_Real profile_radius = 0.12 * roller_diameter * (num_teeth + 2);
Standard_Real top_diameter = pitch_circle_diameter + ((1 - (1.6 / num_teeth)) * pitch) - roller_diameter;
Standard_Real top_radius = top_diameter / 2.;
Standard_Real thickness = chain_width * 0.95;
//Center hole data
Standard_Real center_radius = 125.0 / 2.;
//Mounting hole data
Standard_Real mounting_hole_count = 6;
Standard_Real mounting_radius = 153.0 / 2.;
Standard_Real hole_radius = 8.5 / 2.;
TopoDS_Shape build_tooth()
{
    gp_Pnt2d base_center = gp_Pnt2d(pitch_circle_radius + (tooth_radius - roller_radius), 0);
    gp_Circ2d base_circle = gp_Circ2d(gp_Ax2d(base_center, gp_Dir2d()), tooth_radius);
    Handle(Geom2d_TrimmedCurve) trimmed_base = GCE2d_MakeArcOfCircle(base_circle, M_PI - (roller_contact_angle / 2.), M_PI).Value();
    trimmed_base->Reverse();  //just a trick
    gp_Pnt2d p0 = trimmed_base->StartPoint();
    gp_Pnt2d p1 = trimmed_base->EndPoint();
    //Determine the center of the profile circle
    Standard_Real x_distance = cos(roller_contact_angle / 2.) * (profile_radius + tooth_radius);
    Standard_Real y_distance = sin(roller_contact_angle / 2.) * (profile_radius + tooth_radius);
    gp_Pnt2d profile_center = gp_Pnt2d(pitch_circle_radius - x_distance, y_distance);
    //Construct the profile circle gp_Circ2d
    gp_Circ2d profile_circle = gp_Circ2d(gp_Ax2d(profile_center, gp_Dir2d()), profile_center.Distance(p1));
    Handle(Geom2d_Circle) geom_profile_circle = GCE2d_MakeCircle(profile_circle).Value();
    //Construct the outer circle gp_Circ2d
    gp_Circ2d outer_circle = gp_Circ2d(gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d()), top_radius);
    Handle(Geom2d_Circle) geom_outer_circle = GCE2d_MakeCircle(outer_circle).Value();
    Geom2dAPI_InterCurveCurve inter = Geom2dAPI_InterCurveCurve(geom_profile_circle, geom_outer_circle);
    Standard_Integer num_points = inter.NbPoints();
    gp_Pnt2d p2;
    if (num_points == 2)
    {
        if (p1.Distance(inter.Point(1)) < p1.Distance(inter.Point(2)))
        {
            p2 = inter.Point(1);
        }
        else
        {
            p2 = inter.Point(2);
        }
    }
    else if (num_points == 1)
    {
        p2 = inter.Point(1);
    }
    else
    {
        ;
    }
    //Trim the profile circle and mirror
    Handle(Geom2d_TrimmedCurve) trimmed_profile = GCE2d_MakeArcOfCircle(profile_circle, p1, p2).Value();
    //Calculate the outermost point
    gp_Pnt2d p3 = gp_Pnt2d(cos(tooth_angle / 2.) * top_radius, sin(tooth_angle / 2.) * top_radius);
    //and use it to create the third arc
    Handle(Geom2d_TrimmedCurve) trimmed_outer = GCE2d_MakeArcOfCircle(outer_circle, p2, p3).Value();
    //Mirror and reverse the three arcs
    gp_Ax2d mirror_axis = gp_Ax2d(gp::Origin2d(), gp::DX2d().Rotated(tooth_angle / 2.));
    Handle(Geom2d_TrimmedCurve) mirror_base = Handle(Geom2d_TrimmedCurve)::DownCast(trimmed_base->Copy());
    Handle(Geom2d_TrimmedCurve) mirror_profile = Handle(Geom2d_TrimmedCurve)::DownCast(trimmed_profile->Copy());
    Handle(Geom2d_TrimmedCurve) mirror_outer = Handle(Geom2d_TrimmedCurve)::DownCast(trimmed_outer->Copy());
    mirror_base->Mirror(mirror_axis);
    mirror_profile->Mirror(mirror_axis);
    mirror_outer->Mirror(mirror_axis);
    mirror_base->Reverse();
    mirror_profile->Reverse();
    mirror_outer->Reverse();
    //Replace the two outer arcs with a single one
    gp_Pnt2d outer_start = trimmed_outer->StartPoint();
    gp_Pnt2d outer_mid = trimmed_outer->EndPoint();
    gp_Pnt2d outer_end = mirror_outer->EndPoint();
    Handle(Geom2d_TrimmedCurve) outer_arc = GCE2d_MakeArcOfCircle(outer_start, outer_mid, outer_end).Value();
    //Create an arc for the inside of the wedge
    gp_Circ2d inner_circle = gp_Circ2d(gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d()), top_radius - roller_diameter);
    gp_Pnt2d inner_start = gp_Pnt2d(top_radius - roller_diameter, 0);
    Handle(Geom2d_TrimmedCurve) inner_arc = GCE2d_MakeArcOfCircle(inner_circle, inner_start, tooth_angle).Value();
    inner_arc->Reverse();
    //Convert the 2D arcs and two extra lines to 3D edges
    gp_Pln plane = gp_Pln(gp::Origin(), gp::DZ());
    TopoDS_Edge arc1 = BRepBuilderAPI_MakeEdge(GeomAPI::To3d(trimmed_base, plane)).Edge();
    TopoDS_Edge arc2 = BRepBuilderAPI_MakeEdge(GeomAPI::To3d(trimmed_profile, plane)).Edge();
    TopoDS_Edge arc3 = BRepBuilderAPI_MakeEdge(GeomAPI::To3d(outer_arc, plane)).Edge();
    TopoDS_Edge arc4 = BRepBuilderAPI_MakeEdge(GeomAPI::To3d(mirror_profile, plane)).Edge();
    TopoDS_Edge arc5 = BRepBuilderAPI_MakeEdge(GeomAPI::To3d(mirror_base, plane)).Edge();
    gp_Pnt2d p4 = mirror_base->EndPoint();
    gp_Pnt2d p5 = inner_arc->StartPoint();
    TopoDS_Edge lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0), gp_Pnt(p5.X(), p5.Y(), 0)).Edge();
    TopoDS_Edge arc6 = BRepBuilderAPI_MakeEdge(GeomAPI::To3d(inner_arc, plane)).Edge();
    gp_Pnt2d p6 = inner_arc->EndPoint();
    TopoDS_Edge lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p6.X(), p6.Y(), 0), gp_Pnt(p0.X(), p0.Y(), 0)).Edge();
    BRepBuilderAPI_MakeWire wire = BRepBuilderAPI_MakeWire(arc1);
    wire.Add(arc2);
    wire.Add(arc3);
    wire.Add(arc4);
    wire.Add(arc5);
    wire.Add(lin1);
    wire.Add(arc6);
    wire.Add(lin2);
    TopoDS_Face face = BRepBuilderAPI_MakeFace(wire.Wire());
    TopoDS_Shape wedge = BRepPrimAPI_MakePrism(face, gp_Vec(0.0, 0.0, thickness));
    return wedge;
}
TopoDS_Shape round_tooth(TopoDS_Shape wedge)
{
    Standard_Real round_x = 2.6;
    Standard_Real round_z = 0.06 * pitch;
    Standard_Real round_radius = pitch;
    //Determine where the circle used for rounding has to start and stop
    gp_Pnt2d p2d_1 = gp_Pnt2d(top_radius - round_x, 0);
    gp_Pnt2d p2d_2 = gp_Pnt2d(top_radius, round_z);
    //Construct the rounding circle
    GccAna_Circ2d2TanRad round_circle = GccAna_Circ2d2TanRad(p2d_1, p2d_2, round_radius, 0.01);
    if (round_circle.NbSolutions() != 2)
    {
       ;
    }
    gp_Circ2d round_circle_2d_1 = round_circle.ThisSolution(1);
    gp_Circ2d round_circle_2d_2 = round_circle.ThisSolution(2);
    gp_Circ2d round_circle_2d;
    if (round_circle_2d_1.Position().Location().Coord(1) >= 0)
    {
        round_circle_2d = round_circle_2d_1;
    }
    else
    {
        round_circle_2d = round_circle_2d_2;
    }
    //Remove the arc used for rounding
    Handle(Geom2d_TrimmedCurve) trimmed_circle = GCE2d_MakeArcOfCircle(round_circle_2d, p2d_1, p2d_2).Value();
    //Calculate extra points used to construct lines
    gp_Pnt p1 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y());
    gp_Pnt p2 = gp_Pnt(p2d_2.X(), 0, p2d_2.Y());
    gp_Pnt p3 = gp_Pnt(p2d_2.X() + 1, 0, p2d_2.Y());
    gp_Pnt p4 = gp_Pnt(p2d_2.X() + 1, 0, p2d_1.Y() - 1);
    gp_Pnt p5 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y() - 1);
    //Convert the arc and four extra lines into 3D edges
    gp_Pln plane = gp_Pln(gp_Ax3(gp::Origin(), gp::DY().Reversed(), gp::DX()));
    TopoDS_Edge arc1 = BRepBuilderAPI_MakeEdge(GeomAPI::To3d(trimmed_circle, plane)).Edge();
    TopoDS_Edge lin1 = BRepBuilderAPI_MakeEdge(p2, p3).Edge();
    TopoDS_Edge lin2 = BRepBuilderAPI_MakeEdge(p3, p4).Edge();
    TopoDS_Edge lin3 = BRepBuilderAPI_MakeEdge(p4, p5).Edge();
    TopoDS_Edge lin4 = BRepBuilderAPI_MakeEdge(p5, p1).Edge();
    //Make a wire composed of the edges
    BRepBuilderAPI_MakeWire round_wire = BRepBuilderAPI_MakeWire(arc1);
    round_wire.Add(lin1);
    round_wire.Add(lin2);
    round_wire.Add(lin3);
    round_wire.Add(lin4);
    //Turn the wire into a face
    TopoDS_Face round_face = BRepBuilderAPI_MakeFace(round_wire.Wire());
    //Revolve the face around the Z axis over the tooth angle
    TopoDS_Shape rounding_cut_1 = BRepPrimAPI_MakeRevol(round_face, gp::OZ(), tooth_angle).Shape();
    //Construct a mirrored copy of the first cutting shape
    gp_Trsf mirror = gp_Trsf();
    mirror.SetMirror(gp::XOY());
    TopoDS_Shape mirrored_cut_1 = BRepBuilderAPI_Transform(rounding_cut_1, mirror, 1).Shape();
    //and translate it so that it ends up on the other side of the wedge
    gp_Trsf translate = gp_Trsf();
    translate.SetTranslation(gp_Vec(0, 0, thickness));
    TopoDS_Shape rounding_cut_2 = BRepBuilderAPI_Transform(mirrored_cut_1, translate, 0).Shape();
    //Cut the wedge using the first and second cutting shape
    TopoDS_Shape cut_1 = BRepAlgoAPI_Cut(wedge, rounding_cut_1).Shape();
    TopoDS_Shape cut_2 = BRepAlgoAPI_Cut(cut_1, rounding_cut_2).Shape();
    return cut_2;
}
TopoDS_Shape clone_tooth(TopoDS_Shape base_shape)
{
    gp_Trsf clone = gp_Trsf();
    TopoDS_Shape grouped_shape = base_shape;
    //Find a divisor, between 1 and 8, for the number_of teeth
    int multiplier = 1;
    int max_multiplier = 1;
    for (int i = 0; i < 8; i++)
    {
        if (num_teeth % multiplier == 0)
        {
            max_multiplier = i + 1;
        }
    }
    multiplier = max_multiplier;
    for (int i = 0; i < multiplier; i++)
    {
        clone.SetRotation(gp::OZ(), -i * tooth_angle);
        TopoDS_Shape rotated_shape = BRepBuilderAPI_Transform(base_shape, clone, 1).Shape();
        TopoDS_Shape grouped_shape = BRepAlgoAPI_Fuse(grouped_shape, rotated_shape).Shape();
    }
    //Rotate the basic tooth and fuse together
    TopoDS_Shape aggregated_shape = grouped_shape;
    for (int i = 1; i < int(num_teeth / multiplier); i++)
    {
        clone.SetRotation(gp::OZ(), -i * multiplier * tooth_angle);
        TopoDS_Shape rotated_shape = BRepBuilderAPI_Transform(grouped_shape, clone, 1).Shape();
        aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape, rotated_shape).Shape();
    }
    BRepPrimAPI_MakeCylinder cylinder = BRepPrimAPI_MakeCylinder(gp::XOY(), top_radius - roller_diameter, thickness);
    aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape, cylinder.Shape()).Shape();
    return aggregated_shape;
}
TopoDS_Shape center_hole(TopoDS_Shape base)
{
    BRepPrimAPI_MakeCylinder cylinder = BRepPrimAPI_MakeCylinder(center_radius, thickness);
    TopoDS_Shape cut = BRepAlgoAPI_Cut(base, cylinder);
    return cut;
}
TopoDS_Shape mounting_holes(TopoDS_Shape base)
{
    TopoDS_Shape result = base;
    for (int i = 0; i < mounting_hole_count; i++)
    {
        gp_Pnt center = gp_Pnt(cos(i * M_PI / 3) * mounting_radius, sin(i * M_PI / 3) * mounting_radius, 0.0);
        gp_Ax2 center_axis = gp_Ax2(center, gp::DZ());
        BRepPrimAPI_MakeCylinder cylinder = BRepPrimAPI_MakeCylinder(center_axis, hole_radius, thickness);
        result = BRepAlgoAPI_Cut(result, cylinder).Shape();
        BRepPrimAPI_MakeCone cone = BRepPrimAPI_MakeCone(center_axis, hole_radius + thickness / 2., hole_radius, thickness / 2.);
        result = BRepAlgoAPI_Cut(result, cone.Shape()).Shape();
    }
    return result;
}
TopoDS_Shape cut_out(TopoDS_Shape base)
{
    gp_Circ2d outer = gp_Circ2d(gp::OX2d(), top_radius - 1.75 * roller_diameter);
    gp_Circ2d inner = gp_Circ2d(gp::OX2d(), center_radius + 0.75 * roller_diameter);
    Handle(Geom2d_Circle) geom_outer = GCE2d_MakeCircle(outer).Value();
    Handle(Geom2d_Circle) geom_inner = GCE2d_MakeCircle(inner).Value();
    geom_inner->Reverse();
    Standard_Real base_angle = (2. * M_PI) / mounting_hole_count;
    Standard_Real hole_angle = atan(hole_radius / mounting_radius);
    Standard_Real correction_angle = 3 * hole_angle;
    gp_Lin2d left = gp_Lin2d(gp::Origin2d(), gp::DX2d());
    gp_Lin2d right = gp_Lin2d(gp::Origin2d(), gp::DX2d());
    left.Rotate(gp::Origin2d(), correction_angle);
    right.Rotate(gp::Origin2d(), base_angle - correction_angle);
    Handle(Geom2d_Line) geom_left = GCE2d_MakeLine(left).Value();
    Handle(Geom2d_Line) geom_right = GCE2d_MakeLine(right).Value();
    Geom2dAPI_InterCurveCurve inter_1 = Geom2dAPI_InterCurveCurve(geom_outer, geom_left);
    Geom2dAPI_InterCurveCurve inter_2 = Geom2dAPI_InterCurveCurve(geom_outer, geom_right);
    Geom2dAPI_InterCurveCurve inter_3 = Geom2dAPI_InterCurveCurve(geom_inner, geom_right);
    Geom2dAPI_InterCurveCurve inter_4 = Geom2dAPI_InterCurveCurve(geom_inner, geom_left);
    gp_Pnt2d p1;
    if (inter_1.Point(1).X() > 0) p1 = inter_1.Point(1);
    else p1 = inter_1.Point(2);
    gp_Pnt2d p2;
    if (inter_2.Point(1).X() > 0) p2 = inter_2.Point(1);
    else p2 = inter_2.Point(2);
    gp_Pnt2d p3;
    if (inter_3.Point(1).X() > 0) p3 = inter_3.Point(1);
    else p3 = inter_3.Point(2);
    gp_Pnt2d p4;
    if (inter_4.Point(1).X() > 0) p4 = inter_4.Point(1);
    else p4 = inter_4.Point(2);
    Handle(Geom2d_TrimmedCurve) trimmed_outer = GCE2d_MakeArcOfCircle(outer, p1, p2).Value();
    Handle(Geom2d_TrimmedCurve) trimmed_inner = GCE2d_MakeArcOfCircle(inner, p4, p3).Value();
    gp_Pln plane = gp_Pln(gp::Origin(), gp::DZ());
    TopoDS_Edge arc1 = BRepBuilderAPI_MakeEdge(GeomAPI::To3d(trimmed_outer, plane)).Edge();
    TopoDS_Edge lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p2.X(), p2.Y(), 0), gp_Pnt(p3.X(), p3.Y(), 0)).Edge();
    TopoDS_Edge arc2 = BRepBuilderAPI_MakeEdge(GeomAPI::To3d(trimmed_inner, plane)).Edge();
    TopoDS_Edge lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0), gp_Pnt(p1.X(), p1.Y(), 0)).Edge();
    BRepBuilderAPI_MakeWire cutout_wire = BRepBuilderAPI_MakeWire(arc1);
    cutout_wire.Add(lin1);
    cutout_wire.Add(arc2);
    cutout_wire.Add(lin2);

    //Turn the wire into a face
    TopoDS_Face cutout_face = BRepBuilderAPI_MakeFace(cutout_wire.Wire());
    BRepFilletAPI_MakeFillet2d filleted_face = BRepFilletAPI_MakeFillet2d(cutout_face);
    TopTools_IndexedMapOfShape mapVertex;
    TopExp::MapShapes(cutout_wire.Wire(), TopAbs_VERTEX, mapVertex);
    for (int i = 1; i <= mapVertex.Extent(); ++i)
    {
        filleted_face.AddFillet(TopoDS::Vertex(mapVertex(i)), roller_radius);
    }
    TopoDS_Shape cutout = BRepPrimAPI_MakePrism(filleted_face.Shape(), gp_Vec(0.0, 0.0, thickness));
    TopoDS_Shape result = base;
    gp_Trsf rotate = gp_Trsf();
    for (int i = 0; i < mounting_hole_count; i++)
    {
        rotate.SetRotation(gp::OZ(), i * 2. * M_PI / mounting_hole_count);
        BRepBuilderAPI_Transform rotated_cutout = BRepBuilderAPI_Transform(cutout, rotate, 1);
        result = BRepAlgoAPI_Cut(result, rotated_cutout.Shape()).Shape();
    }
    return result;
}
int main(int argc, char* argv[])
{
    TopoDS_Shape wedge = build_tooth();
    TopoDS_Shape rounded_wedge = round_tooth(wedge);
    TopoDS_Shape basic_disk = clone_tooth(rounded_wedge);
    TopoDS_Shape cut_disc = center_hole(basic_disk);
    TopoDS_Shape mountable_disc = mounting_holes(cut_disc);
    TopoDS_Shape sprocket = cut_out(mountable_disc);
    Viewer vout(50, 50, 500, 500);
    vout << sprocket;
    vout.StartMessageLoop();
    return 0;
}

参考文献:

1、https://blog.csdn.net/weixin_42755384/article/details/96770073

2、https://dev.opencascade.org/doc/occt-7.0.0/refman/html/index.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值