简介
快速用库的方式得到交点
参考链接
https://blog.csdn.net/OOFFrankDura/article/details/82430434
code
//山东大学 计算机基地Frankdura
//2018.9.4
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/intersections.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef K::Point_3 Point_3;
typedef K::Segment_3 Segment_3;
typedef K::Plane_3 Plane_3;
typedef K::Intersect_3 Intersect_3;
int main()
{
Segment_3 seg(Point_3(0,0,0), Point_3(2,2,0));
Segment_3 lin(Point_3(1,2,0), Point_3(1,0,0));
CGAL::cpp11::result_of<Intersect_3(Segment_3, Segment_3)>::type
result = intersection(seg, lin);
if (result) {
if (const Segment_3* s = boost::get<Segment_3>(&*result)) {
std::cout << *s << std::endl;
} else {
const Point_3* p = boost::get<Point_3 >(&*result);
std::cout << (*p) << std::endl;
}
}
return 0;
}
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/intersections.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef K::Point_3 Point_3;
typedef K::Segment_3 Segment_3;
typedef K::Plane_3 Plane_3;
typedef K::Intersect_3 Intersect_3;
int main()
{
Segment_3 seg(Point_3(0,0,0), Point_3(4,4,4));
Plane_3 lin (Point_3(1,0,0),Point_3(0,1,0),Point_3(0,0,1));
CGAL::cpp11::result_of<Intersect_3(Segment_3, Segment_3)>::type
result = intersection(seg, lin);
if (result) {
if (const Segment_3* s = boost::get<Segment_3>(&*result)) {
std::cout << *s << std::endl;
} else {
const Point_3* p = boost::get<Point_3 >(&*result);
std::cout << (*p) << std::endl;
}
}
return 0;
}
附赠Makefile
LOCAL_LIBRARY += -L/home/ling/lee/lib/cgal/dyna
LOCAL_LDFLAGS += -lm -lpthread -ldl -lCGAL_Core -lCGAL_ImageIO -lCGAL -lgmp -lmpfr
LOCAL_CFLAGS += -I/home/ling/lee/include
CC := g++ -g -std=c++17
TARGETS1 = genCube2
SRCS1 = main2.cc
OBJS1 = $(patsubst %.cc, %.o, $(SRCS1))
CFLAGS += $(LOCAL_CFLAGS)
LDFLAGS += $(LOCAL_LIBRARY) $(LOCAL_LDFLAGS)
$(info $(OBJS))
$(info $(TARGETS))
all: $(TARGETS1)
$(TARGETS1):$(OBJS1)
$(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS)
$(OBJS1): %.o:%.cc
$(CC) -c $< -o $@ $(CFLAGS)
clean :
@rm -rf $(TARGETS1) $(OBJS1)
#.SUFFIXES:
.PHONY : all clean
---------------------------我的天空里没有太阳,总是黑夜,但并不暗,因为有东西代替了太阳。虽然没有太阳那么明亮,但对我来说已经足够。凭借着这份光,我便能把黑夜当成白天。我从来就没有太阳,所以不怕失去。
--------《白夜行》